diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-05-16 12:27:34 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-05-16 12:27:34 +0200 |
commit | 8d9998014f3d7591f073dea645e3eee40b4917e6 (patch) | |
tree | 6bb5b6aa22d1720b8eb2dc26766dcad9dda1544d /archaeological_finds | |
parent | dfd6fd2551a9cc54e6b69d4f5d4d4aa328b9cc7a (diff) | |
parent | a25d54c314692843a0086f6c7f9d38c30affce40 (diff) | |
download | Ishtar-8d9998014f3d7591f073dea645e3eee40b4917e6.tar.bz2 Ishtar-8d9998014f3d7591f073dea645e3eee40b4917e6.zip |
Merge branch 'master' into v0.9
Diffstat (limited to 'archaeological_finds')
-rw-r--r-- | archaeological_finds/forms.py | 22 | ||||
-rw-r--r-- | archaeological_finds/forms_treatments.py | 98 | ||||
-rw-r--r-- | archaeological_finds/locale/django.pot | 537 | ||||
-rw-r--r-- | archaeological_finds/models_finds.py | 94 | ||||
-rw-r--r-- | archaeological_finds/templates/ishtar/sheet_find.html | 4 | ||||
-rw-r--r-- | archaeological_finds/tests.py | 76 |
6 files changed, 536 insertions, 295 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index bdb602606..2e7cc75f5 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -36,7 +36,7 @@ from ishtar_common.models import valid_id, valid_ids, get_current_profile, \ from archaeological_operations.models import Period, ArchaeologicalSite, \ RelationType as OpeRelationType from archaeological_context_records.models import DatingType, DatingQuality, \ - ContextRecord + ContextRecord, RelationType as CRRelationType import models from ishtar_common.forms import FormSet, FloatField, \ @@ -61,7 +61,8 @@ from archaeological_finds.forms_treatments import TreatmentSelect, \ AdministrativeActTreatmentFileFormSelection, \ AdministrativeActTreatmentFileModifForm, SourceTreatmentFormSelection, \ SourceTreatmentFileFormSelection, TreatmentSourceFormSelection, \ - TreatmentFileSourceFormSelection + TreatmentFileSourceFormSelection, DashboardForm as DashboardTreatmentForm, \ + DashboardTreatmentFileForm __all__ = [ 'TreatmentSelect', 'TreatmentFormSelection', 'BaseTreatmentForm', @@ -75,7 +76,8 @@ __all__ = [ 'AdministrativeActTreatmentFormSelection', 'AdministrativeActTreatmentFileModifForm', 'SourceTreatmentFormSelection', 'SourceTreatmentFileFormSelection', 'TreatmentSourceFormSelection', - 'TreatmentFileSourceFormSelection', + 'TreatmentFileSourceFormSelection', 'DashboardTreatmentForm', + 'DashboardTreatmentFileForm', 'RecordFormSelection', 'FindForm', 'DateForm', 'DatingFormSet', 'FindSelect', 'FindFormSelection', 'FindFormSelectionWarehouseModule', 'MultipleFindFormSelection', 'MultipleFindFormSelectionWarehouseModule', @@ -359,9 +361,18 @@ class FindSelect(TableSelect): reverse_lazy('autocomplete-archaeologicalsite'), associated_model=ArchaeologicalSite), validators=[valid_id(ArchaeologicalSite)]) + base_finds__context_record = forms.IntegerField( + label=_("Context record"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-contextrecord'), + associated_model=ContextRecord), + validators=[valid_id(ContextRecord)]) ope_relation_types = forms.MultipleChoiceField( label=_(u"Search within related operations"), choices=[], widget=widgets.CheckboxSelectMultiple) + cr_relation_types = forms.MultipleChoiceField( + label=_(u"Search within related context records"), choices=[], + widget=widgets.CheckboxSelectMultiple) datings__period = forms.ChoiceField(label=_(u"Period"), choices=[]) material_types = forms.ChoiceField(label=_(u"Material type"), choices=[]) object_types = forms.ChoiceField(label=_(u"Object type"), choices=[]) @@ -415,12 +426,17 @@ class FindSelect(TableSelect): models.RemarkabilityType.get_help() self.fields['ope_relation_types'].choices = OpeRelationType.get_types( empty_first=False) + self.fields['cr_relation_types'].choices = CRRelationType.get_types( + empty_first=False) def get_input_ids(self): ids = super(FindSelect, self).get_input_ids() ids.pop(ids.index('ope_relation_types')) for idx, c in enumerate(self.fields['ope_relation_types'].choices): ids.append('ope_relation_types_{}'.format(idx)) + ids.pop(ids.index('cr_relation_types')) + for idx, c in enumerate(self.fields['cr_relation_types'].choices): + ids.append('cr_relation_types_{}'.format(idx)) return ids diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py index b3ad8b115..83fb11028 100644 --- a/archaeological_finds/forms_treatments.py +++ b/archaeological_finds/forms_treatments.py @@ -129,12 +129,12 @@ class BaseTreatmentForm(ManageOldType, forms.Form): validators=[valid_id(Container)], required=False) external_id = forms.CharField( label=_(u"External ref."), max_length=200, required=False) - comment = forms.CharField(label=_(u"Comment"), - widget=forms.Textarea, required=False) - description = forms.CharField(label=_(u"Description"), - widget=forms.Textarea, required=False) goal = forms.CharField(label=_(u"Goal"), widget=forms.Textarea, required=False) + description = forms.CharField(label=_(u"Description"), + widget=forms.Textarea, required=False) + comment = forms.CharField(label=_(u"Comment"), + widget=forms.Textarea, required=False) start_date = forms.DateField(label=_(u"Start date"), required=False, widget=widgets.JQueryDate) end_date = forms.DateField(label=_(u"Closing date"), required=False, @@ -239,6 +239,7 @@ class TreatmentModifyForm(BaseTreatmentForm): def __init__(self, *args, **kwargs): super(TreatmentModifyForm, self).__init__(*args, **kwargs) + self.fields.pop('target_is_basket') self.fields.keyOrder.pop(self.fields.keyOrder.index('index')) self.fields.keyOrder.insert( self.fields.keyOrder.index('year') + 1, 'index') @@ -277,6 +278,50 @@ class TreatmentDeletionForm(FinalForm): u"lost!") confirm_end_msg = _(u"Would you like to delete this treatment?") +SLICING = (("month", _(u"months")), ('year', _(u"years")),) + +DATE_SOURCE = (("start", _(u"Start date")), ("end", _(u"Closing date")),) + + +class DashboardForm(forms.Form): + slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING, + required=False) + date_source = forms.ChoiceField( + label=_("Date get from"), choices=DATE_SOURCE, required=False) + treatment_type = forms.ChoiceField(label=_("Treatment type"), choices=[], + required=False) + after = forms.DateField(label=_(u"Date after"), + widget=widgets.JQueryDate, required=False) + before = forms.DateField(label=_(u"Date before"), + widget=widgets.JQueryDate, required=False) + + def __init__(self, *args, **kwargs): + if 'prefix' not in kwargs: + kwargs['prefix'] = 'treatments' + super(DashboardForm, self).__init__(*args, **kwargs) + self.fields['treatment_type'].choices = \ + models.TreatmentType.get_types() + + def get_date_source(self): + date_source = 'start' + if hasattr(self, 'cleaned_data') and \ + self.cleaned_data.get('date_source'): + date_source = self.cleaned_data['date_source'] + return date_source + + def get_filter(self): + if not hasattr(self, 'cleaned_data') or not self.cleaned_data: + return {} + fltr = {} + date_source = self.get_date_source() + if self.cleaned_data.get('treatment_type'): + fltr['treatment_types__pk'] = self.cleaned_data['treatment_type'] + if self.cleaned_data.get('after'): + fltr[date_source + '_date__gte'] = self.cleaned_data['after'] + if self.cleaned_data.get('before'): + fltr[date_source + '_date__lte'] = self.cleaned_data['before'] + return fltr + # administrative act treatment @@ -484,6 +529,51 @@ class TreatmentFileDeletionForm(FinalForm): confirm_msg = _(u"Are you sure you want to delete this treatment request?") confirm_end_msg = _(u"Would you like to delete this treatment request?") +DATE_SOURCE_FILE = ( + ("creation", _(u"Creation date")), + ("reception", _(u"Reception date")), + ("end", _(u"Closing date")),) + + +class DashboardTreatmentFileForm(forms.Form): + slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING, + required=False) + date_source = forms.ChoiceField( + label=_("Date get from"), choices=DATE_SOURCE_FILE, required=False) + treatmentfile_type = forms.ChoiceField(label=_("Treatment request type"), + choices=[], required=False) + after = forms.DateField(label=_(u"Date after"), + widget=widgets.JQueryDate, required=False) + before = forms.DateField(label=_(u"Date before"), + widget=widgets.JQueryDate, required=False) + + def __init__(self, *args, **kwargs): + if 'prefix' not in kwargs: + kwargs['prefix'] = 'treatmentfiles' + super(DashboardTreatmentFileForm, self).__init__(*args, **kwargs) + self.fields['treatmentfile_type'].choices = \ + models.TreatmentFileType.get_types() + + def get_date_source(self): + date_source = 'creation' + if hasattr(self, 'cleaned_data') and \ + self.cleaned_data.get('date_source'): + date_source = self.cleaned_data['date_source'] + return date_source + + def get_filter(self): + if not hasattr(self, 'cleaned_data') or not self.cleaned_data: + return {} + fltr = {} + date_source = self.get_date_source() + if self.cleaned_data.get('treatmentfile_type'): + fltr['type__pk'] = self.cleaned_data['treatmentfile_type'] + if self.cleaned_data.get('after'): + fltr[date_source + '_date__gte'] = self.cleaned_data['after'] + if self.cleaned_data.get('before'): + fltr[date_source + '_date__lte'] = self.cleaned_data['before'] + return fltr + class AdministrativeActTreatmentFileSelect(TableSelect): year = forms.IntegerField(label=_("Year")) diff --git a/archaeological_finds/locale/django.pot b/archaeological_finds/locale/django.pot index d2c407d1c..f3b087244 100644 --- a/archaeological_finds/locale/django.pot +++ b/archaeological_finds/locale/django.pot @@ -9,161 +9,161 @@ msgid "" msgstr "" -#: forms.py:93 forms.py:97 models_finds.py:519 wizards.py:64 +#: forms.py:95 forms.py:99 forms.py:365 models_finds.py:538 wizards.py:64 msgid "Context record" msgstr "" -#: forms.py:126 ishtar_menu.py:32 models_finds.py:683 models_finds.py:1114 -#: models_finds.py:1135 models_treatments.py:298 +#: forms.py:128 ishtar_menu.py:32 models_finds.py:705 models_finds.py:1160 +#: models_finds.py:1181 models_treatments.py:298 #: templates/ishtar/sheet_find.html:5 msgid "Find" msgstr "" -#: forms.py:140 forms.py:337 forms.py:605 models_finds.py:150 -#: models_finds.py:613 +#: forms.py:142 forms.py:347 forms.py:629 models_finds.py:151 +#: models_finds.py:635 msgid "Free ID" msgstr "" -#: forms.py:142 models_finds.py:666 +#: forms.py:144 models_finds.py:688 msgid "Previous ID" msgstr "" -#: forms.py:143 forms.py:368 forms_treatments.py:134 models_finds.py:154 -#: models_finds.py:614 models_treatments.py:128 +#: forms.py:145 forms.py:387 forms_treatments.py:134 models_finds.py:155 +#: models_finds.py:636 models_treatments.py:128 msgid "Description" msgstr "" -#: forms.py:146 forms.py:370 models_finds.py:163 +#: forms.py:148 forms.py:389 models_finds.py:164 msgid "Batch/object" msgstr "" -#: forms.py:148 models_finds.py:643 +#: forms.py:150 models_finds.py:665 msgid "Is complete?" msgstr "" -#: forms.py:151 forms.py:358 forms.py:609 models_finds.py:50 +#: forms.py:153 forms.py:377 forms.py:633 models_finds.py:51 msgid "Material type" msgstr "" -#: forms.py:154 forms.py:362 models_finds.py:62 models_finds.py:618 +#: forms.py:155 forms.py:381 models_finds.py:63 models_finds.py:640 msgid "Conservatory state" msgstr "" -#: forms.py:157 models_finds.py:620 +#: forms.py:158 models_finds.py:642 msgid "Conservatory comment" msgstr "" -#: forms.py:160 models_finds.py:112 models_finds.py:646 +#: forms.py:161 models_finds.py:113 models_finds.py:668 msgid "Object types" msgstr "" -#: forms.py:164 forms.py:361 models_finds.py:71 +#: forms.py:164 forms.py:380 models_finds.py:72 msgid "Preservation type" msgstr "" -#: forms.py:167 forms.py:364 models_finds.py:648 +#: forms.py:167 forms.py:383 models_finds.py:670 msgid "Integrity / interest" msgstr "" -#: forms.py:170 forms.py:366 models_finds.py:651 +#: forms.py:170 forms.py:385 models_finds.py:673 msgid "Remarkability" msgstr "" -#: forms.py:173 models_finds.py:168 +#: forms.py:173 models_finds.py:169 msgid "Point of topographic reference" msgstr "" -#: forms.py:176 models_finds.py:170 templates/ishtar/sheet_find.html:205 +#: forms.py:176 models_finds.py:171 templates/ishtar/sheet_find.html:209 msgid "X" msgstr "" -#: forms.py:177 models_finds.py:171 templates/ishtar/sheet_find.html:206 +#: forms.py:177 models_finds.py:172 templates/ishtar/sheet_find.html:210 msgid "Y" msgstr "" -#: forms.py:178 models_finds.py:172 templates/ishtar/sheet_find.html:207 +#: forms.py:178 models_finds.py:173 templates/ishtar/sheet_find.html:211 msgid "Z" msgstr "" -#: forms.py:180 models_finds.py:180 +#: forms.py:180 models_finds.py:181 msgid "Spatial Reference System" msgstr "" -#: forms.py:183 models_finds.py:173 +#: forms.py:183 models_finds.py:174 msgid "Estimated error for X" msgstr "" -#: forms.py:185 models_finds.py:175 +#: forms.py:185 models_finds.py:176 msgid "Estimated error for Y" msgstr "" -#: forms.py:187 models_finds.py:177 +#: forms.py:187 models_finds.py:178 msgid "Estimated error for Z" msgstr "" -#: forms.py:188 models_finds.py:655 +#: forms.py:188 models_finds.py:677 msgid "Length (cm)" msgstr "" -#: forms.py:189 models_finds.py:656 +#: forms.py:189 models_finds.py:678 msgid "Width (cm)" msgstr "" -#: forms.py:190 models_finds.py:657 +#: forms.py:190 models_finds.py:679 msgid "Height (cm)" msgstr "" -#: forms.py:191 models_finds.py:658 +#: forms.py:191 models_finds.py:680 msgid "Diameter (cm)" msgstr "" -#: forms.py:192 models_finds.py:659 +#: forms.py:192 models_finds.py:681 msgid "Thickness (cm)" msgstr "" -#: forms.py:193 forms.py:610 models_finds.py:625 +#: forms.py:193 forms.py:634 models_finds.py:647 msgid "Volume (l)" msgstr "" -#: forms.py:194 forms.py:611 models_finds.py:626 +#: forms.py:194 forms.py:635 models_finds.py:648 msgid "Weight (g)" msgstr "" -#: forms.py:196 models_finds.py:660 +#: forms.py:196 models_finds.py:682 msgid "Dimensions comment" msgstr "" -#: forms.py:197 forms.py:612 models_finds.py:629 +#: forms.py:197 forms.py:636 models_finds.py:651 msgid "Find number" msgstr "" -#: forms.py:199 models_finds.py:654 +#: forms.py:199 models_finds.py:676 msgid "Minimum number of individuals (MNI)" msgstr "" -#: forms.py:200 models_finds.py:662 +#: forms.py:200 models_finds.py:684 msgid "Mark" msgstr "" -#: forms.py:201 forms.py:371 models_finds.py:668 +#: forms.py:201 forms.py:390 models_finds.py:690 msgid "Check" msgstr "" -#: forms.py:203 models_finds.py:670 +#: forms.py:203 models_finds.py:692 msgid "Check date" msgstr "" -#: forms.py:204 forms_treatments.py:132 forms_treatments.py:434 -#: models_finds.py:155 models_finds.py:663 models_treatments.py:127 +#: forms.py:204 forms_treatments.py:136 forms_treatments.py:479 +#: models_finds.py:156 models_finds.py:685 models_treatments.py:127 #: models_treatments.py:511 msgid "Comment" msgstr "" -#: forms.py:207 models_finds.py:664 +#: forms.py:207 models_finds.py:686 msgid "Comment on dating" msgstr "" -#: forms.py:208 models_finds.py:672 +#: forms.py:208 models_finds.py:694 msgid "Estimated value" msgstr "" @@ -178,181 +178,186 @@ msgid "" "p>" msgstr "" -#: forms.py:285 +#: forms.py:295 msgid "You should at least provide X, Y and the spatial reference system used." msgstr "" -#: forms.py:294 +#: forms.py:304 msgid "Coordinates are not relevant for the spatial reference system used: {}." msgstr "" -#: forms.py:300 forms.py:331 models_finds.py:637 +#: forms.py:310 forms.py:341 models_finds.py:659 msgid "Dating" msgstr "" -#: forms.py:305 forms.py:357 +#: forms.py:315 forms.py:376 msgid "Period" msgstr "" -#: forms.py:306 forms_treatments.py:138 forms_treatments.py:436 -#: models_finds.py:1140 models_treatments.py:130 models_treatments.py:309 -#: templates/ishtar/sheet_find.html:91 templates/ishtar/sheet_find.html:133 +#: forms.py:316 forms_treatments.py:138 forms_treatments.py:283 +#: forms_treatments.py:481 models_finds.py:1186 models_treatments.py:130 +#: models_treatments.py:309 templates/ishtar/sheet_find.html:95 +#: templates/ishtar/sheet_find.html:137 msgid "Start date" msgstr "" -#: forms.py:308 models_finds.py:1141 models_treatments.py:310 -#: templates/ishtar/sheet_find.html:92 templates/ishtar/sheet_find.html:134 +#: forms.py:318 models_finds.py:1187 models_treatments.py:310 +#: templates/ishtar/sheet_find.html:96 templates/ishtar/sheet_find.html:138 msgid "End date" msgstr "" -#: forms.py:309 +#: forms.py:319 msgid "Quality" msgstr "" -#: forms.py:311 +#: forms.py:321 msgid "Dating type" msgstr "" -#: forms.py:313 +#: forms.py:323 msgid "Precise dating" msgstr "" -#: forms.py:335 models_finds.py:187 +#: forms.py:345 models_finds.py:188 msgid "Short ID" msgstr "" -#: forms.py:336 models_finds.py:190 +#: forms.py:346 models_finds.py:191 msgid "Complete ID" msgstr "" -#: forms.py:340 forms_treatments.py:54 forms_treatments.py:96 -#: forms_treatments.py:284 forms_treatments.py:356 forms_treatments.py:406 -#: forms_treatments.py:489 models_treatments.py:103 models_treatments.py:483 +#: forms.py:350 forms_treatments.py:54 forms_treatments.py:96 +#: forms_treatments.py:329 forms_treatments.py:401 forms_treatments.py:451 +#: forms_treatments.py:579 models_treatments.py:103 models_treatments.py:483 msgid "Year" msgstr "" -#: forms.py:342 +#: forms.py:352 msgid "Operation's number (index by year)" msgstr "" -#: forms.py:345 +#: forms.py:355 msgid "Code PATRIARCHE" msgstr "" -#: forms.py:349 +#: forms.py:359 msgid "Archaeological site" msgstr "" -#: forms.py:355 +#: forms.py:371 msgid "Search within related operations" msgstr "" -#: forms.py:359 models_finds.py:111 +#: forms.py:374 +msgid "Search within related context records" +msgstr "" + +#: forms.py:378 models_finds.py:112 msgid "Object type" msgstr "" -#: forms.py:372 forms_treatments.py:57 +#: forms.py:391 forms_treatments.py:57 msgid "Has an image?" msgstr "" -#: forms.py:421 +#: forms.py:445 msgid "Warehouse (location)" msgstr "" -#: forms.py:427 +#: forms.py:451 msgid "Warehouse (responsible)" msgstr "" -#: forms.py:432 +#: forms.py:456 msgid "Container ID" msgstr "" -#: forms.py:433 +#: forms.py:457 msgid "Container ref." msgstr "" -#: forms.py:437 forms.py:460 views.py:149 +#: forms.py:461 forms.py:484 views.py:149 msgid "Find search" msgstr "" -#: forms.py:485 templates/ishtar/sheet_treatment.html:46 +#: forms.py:509 templates/ishtar/sheet_treatment.html:46 msgid "Upstream finds" msgstr "" -#: forms.py:487 models_finds.py:684 +#: forms.py:511 models_finds.py:706 msgid "Finds" msgstr "" -#: forms.py:499 +#: forms.py:523 msgid "You should at least select one archaeological find." msgstr "" -#: forms.py:602 +#: forms.py:626 msgid "Resulting find" msgstr "" -#: forms.py:607 +#: forms.py:631 msgid "Precise description" msgstr "" -#: forms.py:622 +#: forms.py:646 msgid "Resulting finds" msgstr "" -#: forms.py:627 +#: forms.py:651 msgid "Would you like to delete this find?" msgstr "" -#: forms.py:631 models_treatments.py:91 +#: forms.py:655 models_treatments.py:91 msgid "Upstream find" msgstr "" -#: forms.py:644 +#: forms.py:668 msgid "Archaeological find search" msgstr "" -#: forms.py:646 +#: forms.py:670 msgid "You should select an archaeological find." msgstr "" -#: forms.py:651 +#: forms.py:675 msgid "Year of the operation" msgstr "" -#: forms.py:653 +#: forms.py:677 msgid "Numeric reference" msgstr "" -#: forms.py:660 +#: forms.py:684 msgid "Period of the archaeological find" msgstr "" -#: forms.py:662 +#: forms.py:686 msgid "Material type of the archaeological find" msgstr "" -#: forms.py:664 +#: forms.py:688 msgid "Description of the archaeological find" msgstr "" -#: forms.py:676 forms_treatments.py:590 forms_treatments.py:616 +#: forms.py:700 forms_treatments.py:680 forms_treatments.py:706 msgid "Documentation search" msgstr "" -#: forms.py:678 forms_treatments.py:592 forms_treatments.py:618 +#: forms.py:702 forms_treatments.py:682 forms_treatments.py:708 msgid "You should select a document." msgstr "" -#: forms.py:695 +#: forms.py:719 msgid "Another basket already exists with this name." msgstr "" -#: forms.py:705 forms.py:709 forms_treatments.py:175 ishtar_menu.py:57 +#: forms.py:729 forms.py:733 forms_treatments.py:175 ishtar_menu.py:57 msgid "Basket" msgstr "" #: forms_treatments.py:52 forms_treatments.py:92 models_treatments.py:99 -#: templates/ishtar/sheet_find.html:85 templates/ishtar/sheet_find.html:127 +#: templates/ishtar/sheet_find.html:89 templates/ishtar/sheet_find.html:131 msgid "Label" msgstr "" @@ -360,20 +365,20 @@ msgstr "" msgid "Other ref." msgstr "" -#: forms_treatments.py:55 forms_treatments.py:237 forms_treatments.py:285 -#: forms_treatments.py:348 forms_treatments.py:357 forms_treatments.py:459 -#: forms_treatments.py:490 forms_treatments.py:557 models_treatments.py:105 +#: forms_treatments.py:55 forms_treatments.py:237 forms_treatments.py:330 +#: forms_treatments.py:393 forms_treatments.py:402 forms_treatments.py:504 +#: forms_treatments.py:580 forms_treatments.py:647 models_treatments.py:105 #: models_treatments.py:485 msgid "Index" msgstr "" -#: forms_treatments.py:56 forms_treatments.py:101 forms_treatments.py:301 -#: forms_treatments.py:578 models_treatments.py:56 models_treatments.py:110 -#: models_treatments.py:308 +#: forms_treatments.py:56 forms_treatments.py:101 forms_treatments.py:291 +#: forms_treatments.py:346 forms_treatments.py:668 models_treatments.py:56 +#: models_treatments.py:110 models_treatments.py:308 msgid "Treatment type" msgstr "" -#: forms_treatments.py:68 forms_treatments.py:560 views.py:398 +#: forms_treatments.py:68 forms_treatments.py:650 views.py:398 msgid "Treatment search" msgstr "" @@ -382,7 +387,7 @@ msgid "Base treatment" msgstr "" #: forms_treatments.py:103 models_treatments.py:93 models_treatments.py:112 -#: templates/ishtar/sheet_find.html:87 templates/ishtar/sheet_find.html:129 +#: templates/ishtar/sheet_find.html:91 templates/ishtar/sheet_find.html:133 msgid "State" msgstr "" @@ -390,7 +395,7 @@ msgstr "" msgid "Target" msgstr "" -#: forms_treatments.py:107 forms_treatments.py:417 models_treatments.py:120 +#: forms_treatments.py:107 forms_treatments.py:462 models_treatments.py:120 msgid "Responsible" msgstr "" @@ -406,16 +411,16 @@ msgstr "" msgid "Container (relevant for packaging)" msgstr "" -#: forms_treatments.py:131 forms_treatments.py:413 +#: forms_treatments.py:131 forms_treatments.py:458 msgid "External ref." msgstr "" -#: forms_treatments.py:136 models_treatments.py:129 +#: forms_treatments.py:132 models_treatments.py:129 msgid "Goal" msgstr "" -#: forms_treatments.py:140 forms_treatments.py:442 models_treatments.py:131 -#: models_treatments.py:505 +#: forms_treatments.py:140 forms_treatments.py:283 forms_treatments.py:487 +#: forms_treatments.py:535 models_treatments.py:131 models_treatments.py:505 msgid "Closing date" msgstr "" @@ -457,145 +462,173 @@ msgstr "" msgid "A responsible or an organization must be defined." msgstr "" -#: forms_treatments.py:256 +#: forms_treatments.py:257 msgid "Another treatment with this index exists for {}." msgstr "" -#: forms_treatments.py:262 models_treatments.py:108 +#: forms_treatments.py:263 models_treatments.py:108 msgid "Associated request" msgstr "" -#: forms_treatments.py:266 forms_treatments.py:397 ishtar_menu.py:108 +#: forms_treatments.py:267 forms_treatments.py:442 ishtar_menu.py:108 #: models_treatments.py:516 models_treatments.py:544 models_treatments.py:619 #: wizards.py:187 templates/ishtar/sheet_treatmentfile.html:5 msgid "Treatment request" msgstr "" -#: forms_treatments.py:275 +#: forms_treatments.py:276 msgid "" "Are you sure you want to delete this treatment? All changes made to the " "associated finds since this treatment record will be lost!" msgstr "" -#: forms_treatments.py:278 +#: forms_treatments.py:279 msgid "Would you like to delete this treatment?" msgstr "" -#: forms_treatments.py:286 forms_treatments.py:334 forms_treatments.py:491 -#: forms_treatments.py:542 +#: forms_treatments.py:281 +msgid "months" +msgstr "" + +#: forms_treatments.py:281 +msgid "years" +msgstr "" + +#: forms_treatments.py:287 forms_treatments.py:539 +msgid "Slicing" +msgstr "" + +#: forms_treatments.py:290 forms_treatments.py:542 +msgid "Date get from" +msgstr "" + +#: forms_treatments.py:293 forms_treatments.py:545 +msgid "Date after" +msgstr "" + +#: forms_treatments.py:295 forms_treatments.py:547 +msgid "Date before" +msgstr "" + +#: forms_treatments.py:331 forms_treatments.py:379 forms_treatments.py:581 +#: forms_treatments.py:632 msgid "Act type" msgstr "" -#: forms_treatments.py:287 forms_treatments.py:492 +#: forms_treatments.py:332 forms_treatments.py:582 msgid "Indexed?" msgstr "" -#: forms_treatments.py:288 forms_treatments.py:493 +#: forms_treatments.py:333 forms_treatments.py:583 msgid "Object" msgstr "" -#: forms_treatments.py:292 forms_treatments.py:497 +#: forms_treatments.py:337 forms_treatments.py:587 msgid "Signature date after" msgstr "" -#: forms_treatments.py:294 forms_treatments.py:499 +#: forms_treatments.py:339 forms_treatments.py:589 msgid "Signature date before" msgstr "" -#: forms_treatments.py:296 forms_treatments.py:573 +#: forms_treatments.py:341 forms_treatments.py:663 msgid "Treatment name" msgstr "" -#: forms_treatments.py:297 forms_treatments.py:574 +#: forms_treatments.py:342 forms_treatments.py:664 msgid "Treatment year" msgstr "" -#: forms_treatments.py:298 forms_treatments.py:575 +#: forms_treatments.py:343 forms_treatments.py:665 msgid "Treatment index" msgstr "" -#: forms_treatments.py:300 forms_treatments.py:577 +#: forms_treatments.py:345 forms_treatments.py:667 msgid "Treatment internal reference" msgstr "" -#: forms_treatments.py:304 forms_treatments.py:511 +#: forms_treatments.py:349 forms_treatments.py:601 msgid "Modified by" msgstr "" -#: forms_treatments.py:354 forms_treatments.py:404 models_treatments.py:490 +#: forms_treatments.py:399 forms_treatments.py:449 models_treatments.py:490 msgid "Name" msgstr "" -#: forms_treatments.py:355 forms_treatments.py:411 +#: forms_treatments.py:400 forms_treatments.py:456 msgid "Internal ref." msgstr "" -#: forms_treatments.py:358 forms_treatments.py:415 models_treatments.py:92 -#: templates/ishtar/sheet_find.html:86 templates/ishtar/sheet_find.html:128 -#: templates/ishtar/sheet_find.html:228 +#: forms_treatments.py:403 forms_treatments.py:460 models_treatments.py:92 +#: templates/ishtar/sheet_find.html:90 templates/ishtar/sheet_find.html:132 +#: templates/ishtar/sheet_find.html:232 msgid "Type" msgstr "" -#: forms_treatments.py:360 +#: forms_treatments.py:405 msgid "In charge" msgstr "" -#: forms_treatments.py:366 forms_treatments.py:423 models_treatments.py:499 +#: forms_treatments.py:411 forms_treatments.py:468 models_treatments.py:499 #: templates/ishtar/sheet_treatmentfile.html:31 msgid "Applicant" msgstr "" -#: forms_treatments.py:372 forms_treatments.py:429 models_treatments.py:503 +#: forms_treatments.py:417 forms_treatments.py:474 models_treatments.py:503 #: templates/ishtar/sheet_treatmentfile.html:38 msgid "Applicant organisation" msgstr "" -#: forms_treatments.py:385 forms_treatments.py:565 views.py:502 +#: forms_treatments.py:430 forms_treatments.py:655 views.py:502 msgid "Treatment request search" msgstr "" -#: forms_treatments.py:439 models_treatments.py:509 +#: forms_treatments.py:484 forms_treatments.py:534 models_treatments.py:509 msgid "Reception date" msgstr "" -#: forms_treatments.py:478 +#: forms_treatments.py:523 msgid "Another treatment request with this index exists for {}." msgstr "" -#: forms_treatments.py:484 +#: forms_treatments.py:529 msgid "Are you sure you want to delete this treatment request?" msgstr "" -#: forms_treatments.py:485 +#: forms_treatments.py:530 msgid "Would you like to delete this treatment request?" msgstr "" -#: forms_treatments.py:501 forms_treatments.py:597 +#: forms_treatments.py:533 models_treatments.py:507 +msgid "Creation date" +msgstr "" + +#: forms_treatments.py:543 forms_treatments.py:598 forms_treatments.py:694 +#: models_treatments.py:468 models_treatments.py:492 +msgid "Treatment request type" +msgstr "" + +#: forms_treatments.py:591 forms_treatments.py:687 msgid "Treatment request name" msgstr "" -#: forms_treatments.py:503 forms_treatments.py:599 +#: forms_treatments.py:593 forms_treatments.py:689 msgid "Treatment request year" msgstr "" -#: forms_treatments.py:505 forms_treatments.py:601 +#: forms_treatments.py:595 forms_treatments.py:691 msgid "Treatment request index" msgstr "" -#: forms_treatments.py:507 forms_treatments.py:603 +#: forms_treatments.py:597 forms_treatments.py:693 msgid "Treatment request internal reference" msgstr "" -#: forms_treatments.py:508 forms_treatments.py:604 models_treatments.py:468 -#: models_treatments.py:492 -msgid "Treatment request type" -msgstr "" - -#: forms_treatments.py:562 +#: forms_treatments.py:652 msgid "You should select a treatment." msgstr "" -#: forms_treatments.py:568 +#: forms_treatments.py:658 msgid "You should select a treatment request." msgstr "" @@ -629,12 +662,12 @@ msgstr "" msgid "Documentation" msgstr "" -#: ishtar_menu.py:133 ishtar_menu.py:214 models_finds.py:1137 +#: ishtar_menu.py:133 ishtar_menu.py:214 models_finds.py:1183 msgid "Administrative act" msgstr "" -#: ishtar_menu.py:151 ishtar_menu.py:233 templates/ishtar/sheet_find.html:222 -#: templates/ishtar/sheet_find.html:224 +#: ishtar_menu.py:151 ishtar_menu.py:233 templates/ishtar/sheet_find.html:226 +#: templates/ishtar/sheet_find.html:228 msgid "Documents" msgstr "" @@ -652,303 +685,303 @@ msgstr "" msgid "Simple treatments" msgstr "" -#: models_finds.py:43 +#: models_finds.py:44 msgid "Code" msgstr "" -#: models_finds.py:44 +#: models_finds.py:45 msgid "Recommendation" msgstr "" -#: models_finds.py:47 +#: models_finds.py:48 msgid "Parent material" msgstr "" -#: models_finds.py:51 models_finds.py:539 models_finds.py:616 +#: models_finds.py:52 models_finds.py:558 models_finds.py:638 msgid "Material types" msgstr "" -#: models_finds.py:59 +#: models_finds.py:60 msgid "Parent conservatory state" msgstr "" -#: models_finds.py:63 +#: models_finds.py:64 msgid "Conservatory states" msgstr "" -#: models_finds.py:72 +#: models_finds.py:73 msgid "Preservation types" msgstr "" -#: models_finds.py:80 +#: models_finds.py:81 msgid "Integrity / interest type" msgstr "" -#: models_finds.py:81 +#: models_finds.py:82 msgid "Integrity / interest types" msgstr "" -#: models_finds.py:89 +#: models_finds.py:90 msgid "Remarkability type" msgstr "" -#: models_finds.py:90 +#: models_finds.py:91 msgid "Remarkability types" msgstr "" -#: models_finds.py:97 models_finds.py:612 models_treatments.py:40 +#: models_finds.py:98 models_finds.py:634 models_treatments.py:40 #: models_treatments.py:304 msgid "Order" msgstr "" -#: models_finds.py:99 +#: models_finds.py:100 msgid "Batch type" msgstr "" -#: models_finds.py:100 +#: models_finds.py:101 msgid "Batch types" msgstr "" -#: models_finds.py:108 +#: models_finds.py:109 msgid "Parent" msgstr "" -#: models_finds.py:151 models_finds.py:609 models_treatments.py:125 +#: models_finds.py:152 models_finds.py:631 models_treatments.py:125 #: models_treatments.py:488 msgid "External ID" msgstr "" -#: models_finds.py:153 models_finds.py:611 +#: models_finds.py:154 models_finds.py:633 msgid "External ID is set automatically" msgstr "" -#: models_finds.py:156 +#: models_finds.py:157 msgid "Special interest" msgstr "" -#: models_finds.py:160 +#: models_finds.py:161 msgid "Context Record" msgstr "" -#: models_finds.py:161 +#: models_finds.py:162 msgid "Discovery date" msgstr "" -#: models_finds.py:166 +#: models_finds.py:167 msgid "Material index" msgstr "" -#: models_finds.py:182 +#: models_finds.py:183 msgid "Point (2D)" msgstr "" -#: models_finds.py:183 +#: models_finds.py:184 msgid "Point" msgstr "" -#: models_finds.py:184 +#: models_finds.py:185 msgid "Line" msgstr "" -#: models_finds.py:185 +#: models_finds.py:186 msgid "Polygon" msgstr "" -#: models_finds.py:188 models_finds.py:191 +#: models_finds.py:189 models_finds.py:192 msgid "Cached value - do not edit" msgstr "" -#: models_finds.py:197 models_finds.py:607 +#: models_finds.py:198 models_finds.py:629 msgid "Base find" msgstr "" -#: models_finds.py:198 +#: models_finds.py:199 msgid "Base finds" msgstr "" -#: models_finds.py:200 +#: models_finds.py:201 msgid "Can view all Base finds" msgstr "" -#: models_finds.py:201 +#: models_finds.py:202 msgid "Can view own Base find" msgstr "" -#: models_finds.py:202 +#: models_finds.py:203 msgid "Can add own Base find" msgstr "" -#: models_finds.py:203 +#: models_finds.py:204 msgid "Can change own Base find" msgstr "" -#: models_finds.py:204 +#: models_finds.py:205 msgid "Can delete own Base find" msgstr "" -#: models_finds.py:443 +#: models_finds.py:462 msgid "g" msgstr "" -#: models_finds.py:444 +#: models_finds.py:463 msgid "kg" msgstr "" -#: models_finds.py:446 +#: models_finds.py:465 msgid "Not checked" msgstr "" -#: models_finds.py:447 +#: models_finds.py:466 msgid "Checked but incorrect" msgstr "" -#: models_finds.py:448 +#: models_finds.py:467 msgid "Checked and correct" msgstr "" -#: models_finds.py:520 +#: models_finds.py:539 msgid "Base find - Short ID" msgstr "" -#: models_finds.py:521 +#: models_finds.py:540 msgid "Base find - Complete ID" msgstr "" -#: models_finds.py:523 +#: models_finds.py:542 msgid "Operation (code)" msgstr "" -#: models_finds.py:525 +#: models_finds.py:544 msgid "Town" msgstr "" -#: models_finds.py:527 +#: models_finds.py:546 msgid "Operation (name)" msgstr "" -#: models_finds.py:529 +#: models_finds.py:548 msgid "Parcel" msgstr "" -#: models_finds.py:530 +#: models_finds.py:549 msgid "Batch" msgstr "" -#: models_finds.py:531 +#: models_finds.py:550 msgid "Base find - Comment" msgstr "" -#: models_finds.py:532 +#: models_finds.py:551 msgid "Base find - Description" msgstr "" -#: models_finds.py:533 +#: models_finds.py:552 msgid "Base find - Topographic localisation" msgstr "" -#: models_finds.py:535 +#: models_finds.py:554 msgid "Base find - Special interest" msgstr "" -#: models_finds.py:536 +#: models_finds.py:555 msgid "Base find - Discovery date" msgstr "" -#: models_finds.py:537 models_finds.py:640 models_treatments.py:132 -#: models_treatments.py:312 templates/ishtar/sheet_find.html:90 -#: templates/ishtar/sheet_find.html:132 +#: models_finds.py:556 models_finds.py:662 models_treatments.py:132 +#: models_treatments.py:312 templates/ishtar/sheet_find.html:94 +#: templates/ishtar/sheet_find.html:136 msgid "Container" msgstr "" -#: models_finds.py:538 +#: models_finds.py:557 msgid "Periods" msgstr "" -#: models_finds.py:623 +#: models_finds.py:645 msgid "Type of preservation to consider" msgstr "" -#: models_finds.py:627 +#: models_finds.py:649 msgid "Weight unit" msgstr "" -#: models_finds.py:633 templates/ishtar/sheet_find.html:78 +#: models_finds.py:655 templates/ishtar/sheet_find.html:82 msgid "Upstream treatment" msgstr "" -#: models_finds.py:636 templates/ishtar/sheet_find.html:120 +#: models_finds.py:658 templates/ishtar/sheet_find.html:124 msgid "Downstream treatment" msgstr "" -#: models_finds.py:675 +#: models_finds.py:697 msgid "Collection" msgstr "" -#: models_finds.py:677 models_treatments.py:144 models_treatments.py:512 +#: models_finds.py:699 models_treatments.py:144 models_treatments.py:512 msgid "Cached name" msgstr "" -#: models_finds.py:686 +#: models_finds.py:708 msgid "Can view all Finds" msgstr "" -#: models_finds.py:687 +#: models_finds.py:709 msgid "Can view own Find" msgstr "" -#: models_finds.py:688 +#: models_finds.py:710 msgid "Can add own Find" msgstr "" -#: models_finds.py:689 +#: models_finds.py:711 msgid "Can change own Find" msgstr "" -#: models_finds.py:690 +#: models_finds.py:712 msgid "Can delete own Find" msgstr "" -#: models_finds.py:696 +#: models_finds.py:718 msgid "FIND" msgstr "" -#: models_finds.py:1100 +#: models_finds.py:1146 msgid "Find documentation" msgstr "" -#: models_finds.py:1101 +#: models_finds.py:1147 msgid "Find documentations" msgstr "" -#: models_finds.py:1104 +#: models_finds.py:1150 msgid "Can view all Find sources" msgstr "" -#: models_finds.py:1106 +#: models_finds.py:1152 msgid "Can view own Find source" msgstr "" -#: models_finds.py:1108 +#: models_finds.py:1154 msgid "Can add own Find source" msgstr "" -#: models_finds.py:1110 +#: models_finds.py:1156 msgid "Can change own Find source" msgstr "" -#: models_finds.py:1112 +#: models_finds.py:1158 msgid "Can delete own Find source" msgstr "" -#: models_finds.py:1138 +#: models_finds.py:1184 msgid "Person" msgstr "" -#: models_finds.py:1144 +#: models_finds.py:1190 msgid "Property" msgstr "" -#: models_finds.py:1145 +#: models_finds.py:1191 msgid "Properties" msgstr "" @@ -1016,7 +1049,7 @@ msgstr "" msgid "Target a basket" msgstr "" -#: models_treatments.py:149 templates/ishtar/sheet_find.html:75 +#: models_treatments.py:149 templates/ishtar/sheet_find.html:79 #: templates/ishtar/sheet_treatmentfile.html:46 msgid "Treatments" msgstr "" @@ -1045,8 +1078,8 @@ msgstr "" msgid "TREATMENT" msgstr "" -#: models_treatments.py:313 templates/ishtar/sheet_find.html:89 -#: templates/ishtar/sheet_find.html:131 +#: models_treatments.py:313 templates/ishtar/sheet_find.html:93 +#: templates/ishtar/sheet_find.html:135 msgid "Doer" msgstr "" @@ -1070,10 +1103,6 @@ msgstr "" msgid "Person in charge" msgstr "" -#: models_treatments.py:507 -msgid "Creation date" -msgstr "" - #: models_treatments.py:517 msgid "Treatment requests" msgstr "" @@ -1155,30 +1184,18 @@ msgid "Can view Treatment request source" msgstr "" #: models_treatments.py:633 -msgid "Can add Treatment request source" -msgstr "" - -#: models_treatments.py:635 -msgid "Can change Treatment request source" -msgstr "" - -#: models_treatments.py:637 -msgid "Can delete Treatment request source" -msgstr "" - -#: models_treatments.py:639 msgid "Can view own Treatment request source" msgstr "" -#: models_treatments.py:641 +#: models_treatments.py:635 msgid "Can add own Treatment request source" msgstr "" -#: models_treatments.py:643 +#: models_treatments.py:637 msgid "Can change own Treatment request source" msgstr "" -#: models_treatments.py:645 +#: models_treatments.py:639 msgid "Can delete own Treatment request source" msgstr "" @@ -1306,55 +1323,61 @@ msgstr "" msgid "Operation" msgstr "" -#: templates/ishtar/sheet_find.html:25 +#: templates/ishtar/sheet_find.html:14 +msgid "" +"This sheet has a downstream treatment: it is related to an old version of " +"the find." +msgstr "" + +#: templates/ishtar/sheet_find.html:29 msgid "Administrative index" msgstr "" -#: templates/ishtar/sheet_find.html:67 +#: templates/ishtar/sheet_find.html:71 msgid "Warehouse" msgstr "" -#: templates/ishtar/sheet_find.html:84 templates/ishtar/sheet_find.html:126 +#: templates/ishtar/sheet_find.html:88 templates/ishtar/sheet_find.html:130 msgid "Year - index" msgstr "" -#: templates/ishtar/sheet_find.html:88 templates/ishtar/sheet_find.html:130 +#: templates/ishtar/sheet_find.html:92 templates/ishtar/sheet_find.html:134 msgid "Related finds (max. 15 displayed)" msgstr "" -#: templates/ishtar/sheet_find.html:116 +#: templates/ishtar/sheet_find.html:120 msgid "Export as CSV" msgstr "" -#: templates/ishtar/sheet_find.html:116 templates/ishtar/sheet_find.html:159 +#: templates/ishtar/sheet_find.html:120 templates/ishtar/sheet_find.html:163 msgid "CSV" msgstr "" -#: templates/ishtar/sheet_find.html:164 +#: templates/ishtar/sheet_find.html:168 msgid "Associated base finds" msgstr "" -#: templates/ishtar/sheet_find.html:171 +#: templates/ishtar/sheet_find.html:175 msgid "Internal ID" msgstr "" -#: templates/ishtar/sheet_find.html:203 +#: templates/ishtar/sheet_find.html:207 msgid "Coordinates" msgstr "" -#: templates/ishtar/sheet_find.html:210 +#: templates/ishtar/sheet_find.html:214 msgid "SRID" msgstr "" -#: templates/ishtar/sheet_find.html:227 +#: templates/ishtar/sheet_find.html:231 msgid "Title" msgstr "" -#: templates/ishtar/sheet_find.html:229 +#: templates/ishtar/sheet_find.html:233 msgid "Authors" msgstr "" -#: templates/ishtar/sheet_find.html:230 +#: templates/ishtar/sheet_find.html:234 msgid "Link" msgstr "" diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index d33933264..668546602 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -31,7 +31,8 @@ from ishtar_common.utils import cached_label_changed, post_save_point from ishtar_common.models import GeneralType, ImageModel, BaseHistorizedItem, \ ShortMenuItem, LightHistorizedItem, HistoricalRecords, OwnPerms, Source, \ - Person, Basket, get_external_id, post_save_cache, ValueGetter + Person, Basket, get_external_id, post_save_cache, ValueGetter, \ + get_current_profile from archaeological_operations.models import AdministrativeAct from archaeological_context_records.models import ContextRecord, Dating @@ -212,13 +213,31 @@ class BaseFind(BaseHistorizedItem, OwnPerms): finds = self.find.filter().order_by("-order").all() return finds and finds[0] - @classmethod - def get_max_index(cls, operation): - q = BaseFind.objects \ - .filter(context_record__operation=operation) + def generate_index(self): + """ + Generate index based on operation or context record (based on + the configuration) + + :return: True if index has been changed. + """ + profile = get_current_profile() + if profile.find_index == u'O': + operation = self.context_record.operation + q = Find.objects \ + .filter(base_finds__context_record__operation=operation) + elif profile.find_index == u'CR': + cr = self.context_record + q = Find.objects \ + .filter(base_finds__context_record=cr) + else: + return False + if self.pk: + q = q.exclude(pk=self.pk) if q.count(): - return q.aggregate(Max('index'))['index__max'] - return 0 + self.index = q.aggregate(Max('index'))['index__max'] + 1 + else: + self.index = 1 + return True def _ope_code(self): if not self.context_record.operation: @@ -551,7 +570,10 @@ class Find(ValueGetter, BaseHistorizedItem, ImageModel, OwnPerms, REVERSED_BOOL_FIELDS = ['image__isnull'] RELATION_TYPES_PREFIX = { 'ope_relation_types': - 'base_finds__context_record__operation__'} + 'base_finds__context_record__operation__', + 'cr_relation_types': + 'base_finds__context_record__', + } RELATIVE_SESSION_NAMES = [ ('contextrecord', 'base_finds__context_record__pk'), ('operation', 'base_finds__context_record__operation__pk'), @@ -989,6 +1011,43 @@ class Find(ValueGetter, BaseHistorizedItem, ImageModel, OwnPerms, c.execute(sql, args) transaction.commit_unless_managed() + def generate_index(self): + """ + Generate index based on operation or context record (based on + the configuration) + + :return: True if index has been changed. + """ + bfs = self.base_finds + profile = get_current_profile() + if profile.find_index == u'O': + bfs = bfs.filter( + context_record__operation__pk__isnull=False).order_by( + '-context_record__operation__start_date') + if not bfs.count(): + return False + operation = bfs.all()[0].context_record.operation + q = Find.objects \ + .filter(base_finds__context_record__operation=operation) + elif profile.find_index == u'CR': + bfs = bfs.filter( + context_record__pk__isnull=False).order_by( + 'context_record__pk') + if not bfs.count(): + return False + cr = bfs.all()[0].context_record + q = Find.objects \ + .filter(base_finds__context_record=cr) + else: + return False + if self.pk: + q = q.exclude(pk=self.pk) + if q.count(): + self.index = q.aggregate(Max('index'))['index__max'] + 1 + else: + self.index = 1 + return True + def save(self, *args, **kwargs): super(Find, self).save(*args, **kwargs) @@ -1007,28 +1066,15 @@ class Find(ValueGetter, BaseHistorizedItem, ImageModel, OwnPerms, q = self.base_finds if not self.index and q.count(): - operation = q.filter( - context_record__operation__pk__isnull=False).order_by( - '-context_record__operation__start_date') - if operation.count(): - operation = operation.all()[0].context_record.operation - q = Find.objects \ - .filter(base_finds__context_record__operation=operation) - if self.pk: - q = q.exclude(pk=self.pk) - if q.count(): - self.index = q.aggregate(Max('index'))['index__max'] + 1 - else: - self.index = 1 + changed = self.generate_index() + if changed: self._cached_label_checked = False self.save() for base_find in self.base_finds.filter( context_record__operation__pk__isnull=False).all(): modified = False if not base_find.index: - modified = True - base_find.index = BaseFind.get_max_index( - base_find.context_record.operation) + 1 + modified = base_find.generate_index() short_id = base_find.short_id() if base_find.cache_short_id != short_id: base_find.cache_short_id = short_id diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index a78eb7706..db192cc9f 100644 --- a/archaeological_finds/templates/ishtar/sheet_find.html +++ b/archaeological_finds/templates/ishtar/sheet_find.html @@ -9,6 +9,10 @@ {% if item.image %} <a href='{{item.image.url}}' rel="prettyPhoto" title="{{item.label}}" class='photo'><img src='{{item.thumbnail.url}}'/></a> {% endif%} +{% if item.downstream_treatment %} +<p class='alert'><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> + {% trans "This sheet has a downstream treatment: it is related to an old version of the find." %}</p> +{% endif %} <p class="window-refs">{{ item.label|default:"" }}</p> <p class='window-refs'>{% for base_find in item.base_finds.all %}{% if forloop.counter0 %} – {% endif %}{{base_find.complete_id}}{% endfor %}</p> diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 1268b4f03..3d33cf693 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -28,7 +28,7 @@ from django.test.client import Client from ishtar_common.models import ImporterType, IshtarUser, ImporterColumn,\ FormaterType, ImportTarget -from ishtar_common.models import Person +from ishtar_common.models import Person, get_current_profile from archaeological_context_records.models import Period, Dating from archaeological_finds import models, views from archaeological_warehouse.models import Warehouse, WarehouseType @@ -91,7 +91,7 @@ class FindInit(ContextRecordInit): self.base_find = [] -class AFindWizardCreationTest(WizardTest, FindInit, TestCase): +class FindWizardCreationTest(WizardTest, FindInit, TestCase): # TODO: first to be run because of strange init things... fixtures = [settings.ROOT_PATH + '../fixtures/initial_data.json', @@ -134,12 +134,13 @@ class AFindWizardCreationTest(WizardTest, FindInit, TestCase): cr = self.create_context_record( data={'parcel': self.create_parcel()[-1]}, force=True)[-1] - self.form_datas[0].form_datas['selecrecord-find_creation']['pk'] = cr.pk + self.form_datas[0].form_datas['selecrecord-find_creation']['pk'] = \ + cr.pk self.form_datas[0].form_datas['dating-find_creation'][0]['period'] = \ Period.objects.all()[0].pk self.find_number = models.Find.objects.count() self.basefind_number = models.BaseFind.objects.count() - super(AFindWizardCreationTest, self).pre_wizard() + super(FindWizardCreationTest, self).pre_wizard() def post_wizard(self): self.assertEqual(models.BaseFind.objects.count(), @@ -148,8 +149,7 @@ class AFindWizardCreationTest(WizardTest, FindInit, TestCase): self.find_number + 1) -class ATreatmentWizardCreationTest(WizardTest, FindInit, TestCase): - # TODO: first to be run because of strange init things... +class TreatmentWizardCreationTest(WizardTest, FindInit, TestCase): fixtures = [settings.ROOT_PATH + '../fixtures/initial_data.json', settings.ROOT_PATH + @@ -206,7 +206,7 @@ class ATreatmentWizardCreationTest(WizardTest, FindInit, TestCase): self.form_datas[0].form_datas['selecfind-treatment_creation'][ 'resulting_pk'] = self.find.pk self.treatment_number = models.Treatment.objects.count() - super(ATreatmentWizardCreationTest, self).pre_wizard() + super(TreatmentWizardCreationTest, self).pre_wizard() def post_wizard(self): self.assertEqual(models.Treatment.objects.count(), @@ -312,6 +312,68 @@ class FindTest(FindInit, TestCase): base_find.context_record.external_id, base_find.label)) + def testIndex(self): + profile = get_current_profile() + profile.find_index = u"O" + profile.save() + profile = get_current_profile(force=True) + + op1 = self.create_operation()[-1] + op2 = self.create_operation()[-1] + op1_cr1 = self.create_context_record(data={'label': "CR1", + 'operation': op1})[-1] + op1_cr2 = self.create_context_record(data={'label': "CR2", + 'operation': op1})[-1] + op2_cr1 = self.create_context_record(data={'label': "CR3", + 'operation': op2})[-1] + self.create_finds(data_base={'context_record': op1_cr1}) + find_1 = self.finds[-1] + bf_1 = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_1.index, 1) + self.assertEqual(bf_1.index, 1) + + # index is based on operations + self.create_finds(data_base={'context_record': op1_cr2}) + find_2 = self.finds[-1] + bf_2 = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_2.index, 2) + self.assertEqual(bf_2.index, 2) + + self.create_finds(data_base={'context_record': op2_cr1}) + find_3 = self.finds[-1] + bf_3 = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_3.index, 1) + self.assertEqual(bf_3.index, 1) + + profile = get_current_profile(force=True) + profile.find_index = u"CR" + profile.save() + profile = get_current_profile(force=True) + + op3 = self.create_operation()[-1] + op3_cr1 = self.create_context_record(data={'label': "CR1", + 'operation': op3})[-1] + op3_cr2 = self.create_context_record(data={'label': "CR2", + 'operation': op3})[-1] + self.create_finds(data_base={'context_record': op3_cr1}) + find_1b = self.finds[-1] + bf_1b = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_1b.index, 1) + self.assertEqual(bf_1b.index, 1) + + # index now based on context records + self.create_finds(data_base={'context_record': op3_cr2}) + find_2b = self.finds[-1] + bf_2b = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_2b.index, 1) + self.assertEqual(bf_2b.index, 1) + + self.create_finds(data_base={'context_record': op3_cr2}) + find_3b = self.finds[-1] + bf_3b = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_3b.index, 2) + self.assertEqual(bf_3b.index, 2) + def testShowFind(self): find = self.finds[0] response = self.client.get(reverse('display-find', args=[find.pk])) |