Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a authorities/responsabilities models #225

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tmp
dist
doc/output/
doc/pelican-plugins/
doc/pelican-themes/
doc/api/telemeta

# Installer logs
Expand Down
12 changes: 11 additions & 1 deletion telemeta/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ class MediaItemIdentifierInline(admin.StackedInline):
model = MediaItemIdentifier
factory_kwargs = {'max_num': 1}

class ResponsabilityInline(admin.StackedInline):
model = Responsability

class MediaItemAdmin(admin.ModelAdmin):
search_fields = ['title', 'code']
ordering = ['code']
exclude = ('copied_from_item', )
inlines = [MediaItemIdentifierInline,
MediaItemRelatedInline,
MediaItemTranscodedInline,
MediaItemMarkerInline]
MediaItemMarkerInline,
ResponsabilityInline
]

class MediaPartAdmin(admin.ModelAdmin):
search_fields = ['title', 'item__code']
Expand Down Expand Up @@ -106,6 +111,8 @@ class PlaylistAdmin(admin.ModelAdmin):
class EnumerationPropertyAdmin(admin.ModelAdmin):
list_display = ['enumeration_name', 'is_admin', 'is_hidden']

#class AuthorityAdmin(admin.ModelAdmin):
# model = Authority

admin.site.register(MediaFonds, MediaFondsAdmin)
admin.site.register(MediaCorpus, MediaCorpusAdmin)
Expand Down Expand Up @@ -135,3 +142,6 @@ class EnumerationPropertyAdmin(admin.ModelAdmin):
admin.site.register(Playlist, PlaylistAdmin)

admin.site.register(EnumerationProperty, EnumerationPropertyAdmin)

admin.site.register(Responsability)
admin.site.register(Authority)
33 changes: 33 additions & 0 deletions telemeta/migrations/0008_auto_20200531_0733.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import telemeta.models.fields


class Migration(migrations.Migration):

dependencies = [
('telemeta', '0007_auto_20190505_1749'),
]

operations = [
migrations.CreateModel(
name='Authority',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('first_name', models.CharField(max_length=50, verbose_name='firstname')),
('last_name', models.CharField(max_length=50, verbose_name='lastname')),
],
options={
'db_table': 'media_authority',
'verbose_name': 'authority',
},
),
migrations.AddField(
model_name='mediaitem',
name='authority',
field=telemeta.models.fields.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, default=None, blank=True, to='telemeta.Authority', null=True),
),
]
19 changes: 19 additions & 0 deletions telemeta/migrations/0009_auto_20200531_0805.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('telemeta', '0008_auto_20200531_0733'),
]

operations = [
migrations.RenameField(
model_name='mediaitem',
old_name='authority',
new_name='collector2',
),
]
29 changes: 29 additions & 0 deletions telemeta/migrations/0010_auto_20200531_0811.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('telemeta', '0009_auto_20200531_0805'),
]

operations = [
migrations.AddField(
model_name='authority',
name='biography',
field=models.TextField(null=True, verbose_name='biography', blank=True),
),
migrations.AddField(
model_name='authority',
name='birth',
field=models.DateField(help_text='YYYY-MM-DD', null=True, verbose_name='birth', blank=True),
),
migrations.AddField(
model_name='authority',
name='death',
field=models.DateField(help_text='YYYY-MM-DD', null=True, verbose_name='death', blank=True),
),
]
19 changes: 19 additions & 0 deletions telemeta/migrations/0011_authority_isni.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('telemeta', '0010_auto_20200531_0811'),
]

operations = [
migrations.AddField(
model_name='authority',
name='isni',
field=models.PositiveIntegerField(help_text='International Standard Name Identifier', null=True, verbose_name='isni', blank=True),
),
]
44 changes: 44 additions & 0 deletions telemeta/migrations/0012_auto_20200531_0822.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('telemeta', '0011_authority_isni'),
]

operations = [
migrations.AddField(
model_name='authority',
name='first_name_lat',
field=models.CharField(help_text='First name in latin characters, usage form', max_length=50, null=True, verbose_name='firstname_lat', blank=True),
),
migrations.AddField(
model_name='authority',
name='first_name_translit',
field=models.CharField(help_text='First name transliterated', max_length=50, null=True, verbose_name='firstname_translit', blank=True),
),
migrations.AddField(
model_name='authority',
name='last_name_lat',
field=models.CharField(help_text='Last name in latin character, usage form', max_length=50, null=True, verbose_name='lastname_lat', blank=True),
),
migrations.AddField(
model_name='authority',
name='last_name_translit',
field=models.CharField(help_text='Last name transliterated', max_length=50, null=True, verbose_name='lastname_translit', blank=True),
),
migrations.AlterField(
model_name='authority',
name='first_name',
field=models.CharField(help_text='First name in original language', max_length=50, verbose_name='firstname'),
),
migrations.AlterField(
model_name='authority',
name='last_name',
field=models.CharField(help_text='Last name in original language', max_length=50, verbose_name='lastname'),
),
]
21 changes: 21 additions & 0 deletions telemeta/migrations/0013_auto_20200531_0849.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('telemeta', '0012_auto_20200531_0822'),
]

operations = [
migrations.RemoveField(
model_name='mediaitem',
name='collector2',
),
migrations.DeleteModel(
name='Authority',
),
]
66 changes: 66 additions & 0 deletions telemeta/migrations/0014_auto_20200531_0901.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('telemeta', '0013_auto_20200531_0849'),
]

operations = [
migrations.CreateModel(
name='Authority',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('first_name', models.CharField(help_text='First name in original language', max_length=50, verbose_name='firstname')),
('last_name', models.CharField(help_text='Last name in original language', max_length=50, verbose_name='lastname')),
('first_name_lat', models.CharField(help_text='First name in latin characters, usage form', max_length=50, null=True, verbose_name='firstname_lat', blank=True)),
('last_name_lat', models.CharField(help_text='Last name in latin character, usage form', max_length=50, null=True, verbose_name='lastname_lat', blank=True)),
('first_name_translit', models.CharField(help_text='First name transliterated', max_length=50, null=True, verbose_name='firstname_translit', blank=True)),
('last_name_translit', models.CharField(help_text='Last name transliterated', max_length=50, null=True, verbose_name='lastname_translit', blank=True)),
('birth', models.DateField(help_text='YYYY-MM-DD', null=True, verbose_name='birth', blank=True)),
('death', models.DateField(help_text='YYYY-MM-DD', null=True, verbose_name='death', blank=True)),
('biography', models.TextField(null=True, verbose_name='biography', blank=True)),
('isni', models.PositiveIntegerField(help_text='International Standard Name Identifier', null=True, verbose_name='isni', blank=True)),
],
options={
'db_table': 'media_authority',
'verbose_name': 'authority',
'verbose_name_plural': 'authorities',
},
),
migrations.CreateModel(
name='Responsability',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('authority', models.ForeignKey(to='telemeta.Authority')),
('collection', models.ForeignKey(to='telemeta.MediaCollection')),
('item', models.ForeignKey(to='telemeta.MediaItem')),
],
options={
'db_table': 'media_responsability',
'verbose_name': 'responsability',
'verbose_name_plural': 'responsabilites',
},
),
migrations.CreateModel(
name='Role',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('intitule', models.CharField(help_text='List of roles', max_length=50, verbose_name='role')),
],
options={
'db_table': 'media_role',
'verbose_name': 'role',
'verbose_name_plural': 'roles',
},
),
migrations.AddField(
model_name='responsability',
name='role',
field=models.ForeignKey(to='telemeta.Role'),
),
]
2 changes: 1 addition & 1 deletion telemeta/models/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from telemeta.models.identifier import *
from telemeta.models.resource import *
from telemeta.models.enum import *

from telemeta.models.responsability import *

item_published_code_regex = getattr(settings, 'ITEM_PUBLISHED_CODE_REGEX', '[A-Za-z0-9._-]*')
item_unpublished_code_regex = getattr(settings, 'ITEM_UNPUBLISHED_CODE_REGEX', '[A-Za-z0-9._-]*')
Expand Down
76 changes: 76 additions & 0 deletions telemeta/models/responsability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-

# This file is part of Telemeta.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Authors: Anas Ghrab <anas.ghrab@gmail.com>

from __future__ import division
from django.db import models
from django.utils.translation import ugettext_lazy as _
from telemeta.models.item import *
from telemeta.models.collection import *

class Authority(models.Model):
"Describe an autority"

first_name = models.CharField(_('firstname'), max_length=50, help_text=_('First name in original language'))
last_name = models.CharField(_('lastname'), max_length=50, help_text=_('Last name in original language'))
first_name_lat = models.CharField(_('firstname_lat'), max_length=50, null=True, blank=True, help_text=_('First name in latin characters, usage form'))
last_name_lat = models.CharField(_('lastname_lat'), max_length=50, null=True, blank=True, help_text=_('Last name in latin character, usage form'))
first_name_translit = models.CharField(_('firstname_translit'), max_length=50, null=True, blank=True, help_text=_('First name transliterated'))
last_name_translit = models.CharField(_('lastname_translit'), max_length=50, null=True, blank=True, help_text=_('Last name transliterated'))
birth = models.DateField(_('birth'), null=True, blank=True, help_text=_('YYYY-MM-DD'))
death = models.DateField(_('death'), null=True, blank=True, help_text=_('YYYY-MM-DD'))
biography = models.TextField(_('biography'), null=True, blank=True)
isni = models.PositiveIntegerField(_('isni'), null=True, blank=True, help_text=_('International Standard Name Identifier'))
#photo =

class Meta:
db_table = 'media_authority'
verbose_name = _('authority')
verbose_name_plural = _('authorities')

def __str__(self):
return '%s %s' % (self.prenom, self.nom)

class Role(models.Model):
"Describe a role related to items"

intitule = models.CharField(_('role'), max_length=50, help_text=_('List of roles'))

class Meta:
db_table = 'media_role'
verbose_name = _('role')
verbose_name_plural = _('roles')

def __str__(self):
return '%s %s' % (self.intitule)

class Responsability(models.Model):
"Describe a responsability in making an item"

authority = models.ForeignKey('Authority', on_delete = models.CASCADE)
role = models.ForeignKey('Role', on_delete = models.CASCADE)
item = models.ForeignKey('MediaItem', on_delete = models.CASCADE)
collection = models.ForeignKey('MediaCollection', on_delete = models.CASCADE)
Copy link
Member

@yomguy yomguy Jul 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those 4 fields, to avoid cascade deleting, I strongly advise to set on_delete=models.SET_NULL.
If not, in this case and for example, a Responsability could be deleted when the related Role or Item is deleted.


class Meta:
db_table = 'media_responsability'
verbose_name = _('responsability')
verbose_name_plural = _('responsabilites')

def __str__(self):
return '%s %s' % (self.authority, self.role)