Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'c/collections/5-refactor-edtf-fields' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurty committed Jun 8, 2017
2 parents a01e30e + d6244d9 commit b949703
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 175 deletions.
68 changes: 34 additions & 34 deletions glamkit_collections/contrib/work_creator/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ class CreatorChildAdmin(
ICEkitContentsAdmin.inlines

readonly_fields = (
'birth_date_earliest',
'birth_date_latest',
'birth_date_sort_ascending',
'birth_date_sort_descending',
'birth_date_edtf',
'death_date_earliest',
'death_date_latest',
'death_date_sort_ascending',
'death_date_sort_descending',
'death_date_edtf',
'start_date_earliest',
'start_date_latest',
'start_date_sort_ascending',
'start_date_sort_descending',
'start_date_edtf',
'end_date_earliest',
'end_date_latest',
'end_date_sort_ascending',
'end_date_sort_descending',
'end_date_edtf',
)

NAME_FIELDSET = ('Name', {
Expand All @@ -136,24 +136,24 @@ class CreatorChildAdmin(
DATE_FIELDSETS = (
("Dates", {
'fields': (
('birth_date_display',
'death_date_display',),
('start_date_display',
'end_date_display',),
),
}),
("Advanced date controls", {
'classes': ('collapse',),
'fields': (
('birth_date_earliest',
'birth_date_latest',),
('birth_date_sort_ascending',
'birth_date_sort_descending',),
'birth_date_edtf',

('death_date_earliest',
'death_date_latest',),
('death_date_sort_ascending',
'death_date_sort_descending',),
'death_date_edtf',
('start_date_earliest',
'start_date_latest',),
('start_date_sort_ascending',
'start_date_sort_descending',),
'start_date_edtf',

('end_date_earliest',
'end_date_latest',),
('end_date_sort_ascending',
'end_date_sort_descending',),
'end_date_edtf',
),
}),
)
Expand Down Expand Up @@ -192,11 +192,11 @@ class WorkChildAdmin(
exclude = ('layout', 'alt_slug',)
prepopulated_fields = {"slug": ("accession_number", "title",)}
readonly_fields = (
"date_edtf",
'date_earliest',
'date_latest',
'date_sort_ascending',
'date_sort_descending',
"creation_date_edtf",
'creation_date_earliest',
'creation_date_latest',
'creation_date_sort_ascending',
'creation_date_sort_descending',
)

inlines = [WorkOriginsInline, WorkCreatorsInlineForWorks, WorkImageInline] + \
Expand All @@ -205,17 +205,17 @@ class WorkChildAdmin(
DATE_FIELDSETS = (
("Date", {
'fields': (
'date_display',
'creation_date_display',
),
}),
("Advanced date controls", {
'classes': ('collapse',),
'fields': (
('date_earliest',
'date_latest',),
('date_sort_ascending',
'date_sort_descending',),
'date_edtf',
('creation_date_earliest',
'creation_date_latest',),
('creation_date_sort_ascending',
'creation_date_sort_descending',),
'creation_date_edtf',
),
}),

Expand Down
35 changes: 10 additions & 25 deletions glamkit_collections/contrib/work_creator/api_serializers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from django.apps import apps

from rest_framework import serializers
from rest_framework.settings import api_settings
from rest_framework.validators import UniqueTogetherValidator
from drf_queryfields import QueryFieldsMixin

from icekit.api.base_serializers import ModelSubSerializer, \
PolymorphicHyperlinkedModelSerializer, WritableSerializerHelperMixin, \
WritableRelatedFieldSettings
from icekit.api.base_serializers import WritableSerializerHelperMixin, \
PolymorphicHyperlinkedModelSerializer, WritableRelatedFieldSettings
from icekit.api.images.serializers import RelatedImageSerializer

from .models import WorkBase, CreatorBase, WorkCreator as WorkCreatorModel, \
Expand Down Expand Up @@ -84,23 +81,9 @@ class Meta:
}


class WorkDate(ModelSubSerializer):
class Meta:
model = WorkBase
source_prefix = 'date_'
fields = (
'date_display',
'date_edtf',
)


class WorkSummary(WritableSerializerHelperMixin,
PolymorphicHyperlinkedModelSerializer):
""" Minimal information about a work """
date = WorkDate(
required=False,
read_only=True,
)

def get_child_view_name_data(self):
from .plugins.game import api as game_api
Expand All @@ -118,7 +101,8 @@ class Meta:
api_settings.URL_FIELD_NAME,
'id',
'title',
'date',
'creation_date_display',
'creation_date_edtf',
)
extra_kwargs = {
'id': {
Expand Down Expand Up @@ -239,6 +223,10 @@ class Meta:
'name_sort',
'website',
'wikipedia_link',
'start_date_display',
'start_date_edtf',
'end_date_display',
'end_date_edtf',
# Metadata fields
'id',
'external_ref',
Expand Down Expand Up @@ -325,9 +313,6 @@ class Work(BaseCollectionModelSerializerMixin,
many=True,
read_only=True,
)
date = WorkDate(
required=False,
)
origin = WorkOrigin(
source="workorigin_set",
many=True,
Expand All @@ -341,8 +326,6 @@ class Meta:
'creators',
'images',
'origin',
# Sub-resources
'date',
# Fields
api_settings.URL_FIELD_NAME,
'publishing_is_draft',
Expand All @@ -353,6 +336,8 @@ class Meta:
'department',
'credit_line',
'accession_number',
'creation_date_display',
'creation_date_edtf',
# Metadata fields
'id',
'external_ref',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import edtf.fields


class Migration(migrations.Migration):

dependencies = [
('gk_collections_work_creator', '0030_auto_20170523_1243'),
]

operations = [
migrations.RenameField(
model_name='workbase',
old_name='date_display',
new_name='creation_date_display',
),
migrations.RenameField(
model_name='workbase',
old_name='date_earliest',
new_name='creation_date_earliest',
),
migrations.RenameField(
model_name='workbase',
old_name='date_latest',
new_name='creation_date_latest',
),
migrations.RenameField(
model_name='workbase',
old_name='date_sort_ascending',
new_name='creation_date_sort_ascending',
),
migrations.RenameField(
model_name='workbase',
old_name='date_sort_descending',
new_name='creation_date_sort_descending',
),
migrations.RemoveField(
model_name='creatorbase',
name='birth_date_display',
),
migrations.RemoveField(
model_name='creatorbase',
name='birth_date_earliest',
),
migrations.RemoveField(
model_name='creatorbase',
name='birth_date_edtf',
),
migrations.RemoveField(
model_name='creatorbase',
name='birth_date_latest',
),
migrations.RemoveField(
model_name='creatorbase',
name='birth_date_sort_ascending',
),
migrations.RemoveField(
model_name='creatorbase',
name='birth_date_sort_descending',
),
migrations.RemoveField(
model_name='creatorbase',
name='death_date_display',
),
migrations.RemoveField(
model_name='creatorbase',
name='death_date_earliest',
),
migrations.RemoveField(
model_name='creatorbase',
name='death_date_edtf',
),
migrations.RemoveField(
model_name='creatorbase',
name='death_date_latest',
),
migrations.RemoveField(
model_name='creatorbase',
name='death_date_sort_ascending',
),
migrations.RemoveField(
model_name='creatorbase',
name='death_date_sort_descending',
),
migrations.RemoveField(
model_name='workbase',
name='date_edtf',
),
migrations.AddField(
model_name='creatorbase',
name='end_date_display',
field=models.CharField(max_length=255, verbose_name=b'Date of death/closure (display)', blank=True, help_text=b'Displays date as formatted for display, rather than sorting.'),
),
migrations.AddField(
model_name='creatorbase',
name='end_date_earliest',
field=models.DateField(blank=True, verbose_name=b'Earliest end date', null=True),
),
migrations.AddField(
model_name='creatorbase',
name='end_date_edtf',
field=edtf.fields.EDTFField(lower_fuzzy_field=b'end_date_sort_ascending', upper_strict_field=b'end_date_latest', null=True, verbose_name=b'Date of death/closure (EDTF)', upper_fuzzy_field=b'end_date_sort_descending', natural_text_field=b'end_date_display', blank=True, lower_strict_field=b'end_date_earliest', help_text=b"an <a href='http://www.loc.gov/standards/datetime/implementations.html'>EDTF</a>-formatted date, parsed from the display date, e.g. '1855/1860-06-04'"),
),
migrations.AddField(
model_name='creatorbase',
name='end_date_latest',
field=models.DateField(blank=True, verbose_name=b'Latest end date', null=True),
),
migrations.AddField(
model_name='creatorbase',
name='end_date_sort_ascending',
field=models.DateField(blank=True, verbose_name=b'Ascending sort by end', null=True),
),
migrations.AddField(
model_name='creatorbase',
name='end_date_sort_descending',
field=models.DateField(blank=True, verbose_name=b'Descending sort by end', null=True),
),
migrations.AddField(
model_name='creatorbase',
name='start_date_display',
field=models.CharField(max_length=255, verbose_name=b'Date of birth/creation (display)', blank=True, help_text=b'Displays date as formatted for display, rather than sorting.'),
),
migrations.AddField(
model_name='creatorbase',
name='start_date_earliest',
field=models.DateField(blank=True, verbose_name=b'Earliest start date', null=True),
),
migrations.AddField(
model_name='creatorbase',
name='start_date_edtf',
field=edtf.fields.EDTFField(lower_fuzzy_field=b'start_date_sort_ascending', upper_strict_field=b'start_date_latest', null=True, verbose_name=b'Date of birth/creation (EDTF)', upper_fuzzy_field=b'start_date_sort_descending', natural_text_field=b'start_date_display', blank=True, lower_strict_field=b'start_date_earliest', help_text=b"an <a href='http://www.loc.gov/standards/datetime/implementations.html'>EDTF</a>-formatted date, parsed from the display date, e.g. '1855/1860-06-04'"),
),
migrations.AddField(
model_name='creatorbase',
name='start_date_latest',
field=models.DateField(blank=True, verbose_name=b'Latest start date', null=True),
),
migrations.AddField(
model_name='creatorbase',
name='start_date_sort_ascending',
field=models.DateField(blank=True, verbose_name=b'Ascending sort by start', null=True),
),
migrations.AddField(
model_name='creatorbase',
name='start_date_sort_descending',
field=models.DateField(blank=True, verbose_name=b'Descending sort by start', null=True),
),
migrations.AddField(
model_name='workbase',
name='creation_date_edtf',
field=edtf.fields.EDTFField(lower_fuzzy_field=b'creation_date_sort_ascending', upper_strict_field=b'creation_date_latest', null=True, verbose_name=b'Date of creation (EDTF)', upper_fuzzy_field=b'creation_date_sort_descending', natural_text_field=b'creation_date_display', blank=True, lower_strict_field=b'creation_date_earliest', help_text=b"an <a href='http://www.loc.gov/standards/datetime/implementations.html'>EDTF</a>-formatted date, parsed from the display date, e.g. '1855/1860-06-04'"),
),
]
Loading

0 comments on commit b949703

Please sign in to comment.