diff options
-rw-r--r-- | archaeological_finds/forms.py | 2 | ||||
-rw-r--r-- | archaeological_finds/migrations/0033_auto_20180813_1310.py | 86 | ||||
-rw-r--r-- | archaeological_finds/models.py | 4 | ||||
-rw-r--r-- | archaeological_finds/models_finds.py | 128 |
4 files changed, 216 insertions, 4 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index 0c9788d4f..b291f4417 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -406,6 +406,8 @@ DatingFormSet.form_slug = "find-040-dating" class FindSelect(CustomForm, TableSelect): + _model = models.Find + form_admin_name = _(u"Find - 001 - Search") form_slug = "find-001-search" search_vector = forms.CharField( diff --git a/archaeological_finds/migrations/0033_auto_20180813_1310.py b/archaeological_finds/migrations/0033_auto_20180813_1310.py new file mode 100644 index 000000000..aea94a8e9 --- /dev/null +++ b/archaeological_finds/migrations/0033_auto_20180813_1310.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-08-13 13:10 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion +import ishtar_common.models +import re + + +def migrate_finds(apps, schema_editor): + Find = apps.get_model('archaeological_finds', 'Find') + CheckedType = apps.get_model('archaeological_finds', + 'RecordQualityType') + + not_checked, c = CheckedType.objects.get_or_create( + txt_idx=u"not-checked", + defaults={ + "label": u"Non vérifié", + "order": 10 + } + ) + checked_not_correct, c = CheckedType.objects.get_or_create( + txt_idx=u"checked-not-correct", + defaults={ + "label": u"Vérifié mais incorrect", + "order": 20 + } + ) + checked_correct, c = CheckedType.objects.get_or_create( + txt_idx=u"checked-correct", + defaults={ + "label": u"Vérifié et correct", + "order": 30 + } + ) + CHECK_CHOICES = { + 'NC': not_checked, + 'CI': checked_not_correct, + 'CC': checked_correct, + } + + for f in Find.objects.all(): + if not f.checked: + continue + f.checked_type = CHECK_CHOICES[f.checked] + f.skip_history_when_saving = True + f.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_finds', '0032_auto_20180619_0911'), + ] + + operations = [ + migrations.CreateModel( + name='CheckedType', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('label', models.TextField(verbose_name='Label')), + ('txt_idx', models.TextField(help_text='The slug is the standardized version of the name. It contains only lowercase letters, numbers and hyphens. Each slug must be unique.', unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+\\Z'), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')], verbose_name='Textual ID')), + ('comment', models.TextField(blank=True, null=True, verbose_name='Comment')), + ('available', models.BooleanField(default=True, verbose_name='Available')), + ], + options={ + 'ordering': ('label',), + 'verbose_name': 'Checked type', + 'verbose_name_plural': 'Checked types', + }, + bases=(ishtar_common.models.Cached, models.Model), + ), + migrations.AddField( + model_name='find', + name='checked_type', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='archaeological_finds.CheckedType', verbose_name='Check'), + ), + migrations.AddField( + model_name='historicalfind', + name='checked_type', + field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='archaeological_finds.CheckedType'), + ), + migrations.RunPython(migrate_finds), + ] diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 1052edb19..98d495d7c 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -1,5 +1,5 @@ from archaeological_finds.models_finds import MaterialType, ConservatoryState, \ - IntegrityType, RemarkabilityType, ObjectType, BaseFind, \ + CheckedType, IntegrityType, RemarkabilityType, ObjectType, BaseFind, \ FindBasket, Find, Property, CHECK_CHOICES, BatchType, \ BFBulkView, FBulkView, FirstBaseFindView, AlterationType, \ AlterationCauseType, TreatmentEmergencyType, TreatmentType, \ @@ -9,7 +9,7 @@ from archaeological_finds.models_treatments import Treatment, \ FindTreatments, TreatmentFile, TreatmentFileType, \ TreatmentState -__all__ = ['MaterialType', 'ConservatoryState', 'IntegrityType', +__all__ = ['MaterialType', 'ConservatoryState', 'IntegrityType', 'CheckedType', 'RemarkabilityType', 'ObjectType', 'BaseFind', 'FindBasket', 'Find', 'Property', 'BFBulkView', 'FBulkView', 'FirstBaseFindView', 'AlterationType', 'AlterationCauseType', 'TreatmentEmergencyType', diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 1ebfb6a15..322cf90e4 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -27,10 +27,11 @@ from django.db.models import Max, Q from django.db.models.signals import m2m_changed, post_save, post_delete, \ pre_delete from django.core.exceptions import ObjectDoesNotExist -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _, pgettext_lazy from ishtar_common.data_importer import post_importer_action, ImporterError -from ishtar_common.utils import cached_label_changed, post_save_point +from ishtar_common.utils import cached_label_changed, post_save_point, \ + TXT_SEARCH_COMMENT from ishtar_common.models import Document, GeneralType, \ HierarchicalType, BaseHistorizedItem, ShortMenuItem, LightHistorizedItem, \ @@ -211,6 +212,17 @@ post_save.connect(post_save_cache, sender=CommunicabilityType) post_delete.connect(post_save_cache, sender=CommunicabilityType) +class CheckedType(GeneralType): + class Meta: + verbose_name = _(u"Checked type") + verbose_name_plural = _(u"Checked types") + ordering = ('label',) + + +post_save.connect(post_save_cache, sender=CheckedType) +post_delete.connect(post_save_cache, sender=CheckedType) + + class BFBulkView(object): CREATE_SQL = """ CREATE VIEW basefind_cached_bulk_update @@ -713,6 +725,116 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, if key not in EXTRA_REQUEST_KEYS] ) ) + # alternative names of fields for searches + ALT_NAMES = { + 'base_finds__cache_short_id': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"short-id"), + 'base_finds__cache_short_id__iexact' + ), + 'base_finds__cache_complete_id': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"complete-id"), + 'base_finds__cache_complete_id__iexact' + ), + 'label': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"free-id"), + 'label__iexact' + ), + 'denomination': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"denomination"), + 'denomination__icontains' + ), + 'base_finds__context_record__town': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"town"), + 'base_finds__context_record__town__cached_label__iexact' + ), + 'base_finds__context_record__operation__year': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"year"), + 'base_finds__context_record__operation__year' + ), + 'base_finds__context_record__operation__operation_code': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"operation-code"), + 'base_finds__context_record__operation__operation_code' + ), + 'base_finds__context_record__operation__code_patriarche': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"code-patriarche"), + 'base_finds__context_record__operation__code_patriarche' + ), + 'base_finds__context_record__operation__operation_type': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"operation-type"), + 'base_finds__context_record__operation__operation_type' + '__label__iexact' + ), + 'base_finds__context_record__town__areas': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"area"), + 'base_finds__context_record__town__areas__label__iexact', + ), + 'archaeological_sites': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"site"), + 'base_finds__context_record__operation__archaeological_sites__' + 'cached_label__icontains', + ), + 'archaeological_sites_context_record': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"context-record-site"), + 'base_finds__context_record__archaeological_site__' + 'cached_label__icontains', + ), + 'base_finds__context_record': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"context-record"), + 'base_finds__context_record__cached_label__icontains', + ), + 'ope_relation_types': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"operation-relation-type"), + 'ope_relation_types' + ), + 'cr_relation_types': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"context-record-relation-type"), + 'cr_relation_types' + ), + 'datings__period': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"period"), + 'datings__period__label__iexact', + ), + 'material_types': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"material"), + 'material_types__label__iexact', + ), + 'object_types': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"object-type"), + 'object_types__label__iexact', + ), + 'preservation_to_considers': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"preservation"), + 'preservation_to_considers__label__iexact', + ), + 'conservatory_state': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"conservatory"), + 'conservatory_state__label__iexact', + ), + 'integrities': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"integrity"), + 'integrities__label__iexact', + ), + 'remarkabilities': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"remarkability"), + 'remarkabilities__label__iexact', + ), + 'base_finds__find__description': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"description"), + 'base_finds__find__description__icontains', + ), + 'base_finds__batch': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"batch"), + 'base_finds__batch__label__iexact', + ), + 'checked': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"checked"), + 'checked_type__label__iexact', + ), + + + } + for v in ALT_NAMES.values(): + EXTRA_REQUEST_KEYS[v[0]] = v[1] # fields base_finds = models.ManyToManyField(BaseFind, verbose_name=_(u"Base find"), @@ -801,6 +923,8 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, null=True) previous_id = models.TextField(_(u"Previous ID"), blank=True, null=True) index = models.IntegerField(u"Index", default=0) + checked_type = models.ForeignKey(CheckedType, verbose_name=_(u"Check"), + blank=True, null=True) checked = models.CharField(_(u"Check"), max_length=2, default=u'NC', choices=CHECK_CHOICES) check_date = models.DateField(_(u"Check date"), |