diff options
| -rw-r--r-- | archaeological_context_records/models.py | 1 | ||||
| -rw-r--r-- | archaeological_files/models.py | 9 | ||||
| -rw-r--r-- | archaeological_finds/models_finds.py | 1 | ||||
| -rw-r--r-- | archaeological_finds/models_treatments.py | 2 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 19 | ||||
| -rw-r--r-- | archaeological_warehouse/forms.py | 4 | ||||
| -rw-r--r-- | archaeological_warehouse/models.py | 1 | ||||
| -rw-r--r-- | ishtar_common/models.py | 16 | ||||
| -rw-r--r-- | ishtar_common/views_item.py | 78 | 
9 files changed, 69 insertions, 62 deletions
| diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 474d71e7c..cc51c3b7a 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -378,6 +378,7 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,              'cr_relation_types'          ),      } +    ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)      PARENT_ONLY_SEARCH_VECTORS = ["operation", "archaeological_site", "parcel"]      BASE_SEARCH_VECTORS = [ diff --git a/archaeological_files/models.py b/archaeological_files/models.py index e8df6cdae..8794be6ad 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -205,15 +205,8 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, OwnPerms, ValueGetter,                            u"general-contractor-organization"),              'general_contractor__attached_to__cached_label__iexact'          ), -        'history_creator': SearchAltName( -            pgettext_lazy("key for text search", u"created-by"), -            'history_creator__ishtaruser__person__cached_label__iexact' -        ), -        'history_modifier': SearchAltName( -            pgettext_lazy("key for text search", u"modified-by"), -            'history_modifier__ishtaruser__person__cached_label__iexact' -        ),      } +    ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)      POST_PROCESS_REQUEST = {          'towns__numero_insee__startswith': '_get_department_code', diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 2616d61fa..2d78b883e 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -1295,6 +1295,7 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem,                  pgettext_lazy(u"key for text search", u"appraisal-date-after"),                  'appraisal_date__gte'),      } +    ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)      DYNAMIC_REQUESTS = {          'current_division': DynamicRequest( diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index 512fd8a05..84855180a 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -119,6 +119,7 @@ class Treatment(DashboardFormItem, ValueGetter, DocumentItem,              'treatment_types__label__iexact'          ),      } +    ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)      HISTORICAL_M2M = [          'treatment_types',      ] @@ -928,6 +929,7 @@ class TreatmentFile(DashboardFormItem, ClosedItem, DocumentItem,              'applicant_organisation__cached_label__iexact'          ),      } +    ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)      # fields      year = models.IntegerField(_(u"Year"), default=get_current_year) diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 9f1e29e5e..98be07abd 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -221,6 +221,7 @@ class ArchaeologicalSite(DocumentItem, BaseHistorizedItem, QRCodeItem,              'affmar_number__iexact'          ),      } +    ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)      UP_MODEL_QUERY = {          "operation": (pgettext_lazy("key for text search", u"operation"), @@ -753,14 +754,6 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem,                            u"site"),              'archaeological_sites__cached_label__icontains'          ), -        'history_creator': SearchAltName( -            pgettext_lazy("key for text search", u"created-by"), -            'history_creator__ishtaruser__person__cached_label__iexact' -        ), -        'history_modifier': SearchAltName( -            pgettext_lazy("key for text search", u"modified-by"), -            'history_modifier__ishtaruser__person__cached_label__iexact' -        ),          'documentation_received': SearchAltName(              pgettext_lazy("key for text search", u"documentation-received"),              'documentation_received' @@ -790,6 +783,7 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem,              'drassm_code__iexact'          ),      } +    ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)      QA_EDIT = QuickAction(          url="operation-qa-bulk-update", icon_class="fa fa-pencil",          text=_(u"Bulk update"), target="many", @@ -1735,14 +1729,6 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):              pgettext_lazy("key for text search", u"object"),              'act_object__icontains'          ), -        'history_creator': SearchAltName( -            pgettext_lazy("key for text search", u"created-by"), -            'history_creator__ishtaruser__person__cached_label__iexact' -        ), -        'history_modifier': SearchAltName( -            pgettext_lazy("key for text search", u"modified-by"), -            'history_modifier__ishtaruser__person__cached_label__iexact' -        ),          'signature_date_before': SearchAltName(              pgettext_lazy("key for text search", u"signature-before"),              'signature_date__lte' @@ -1826,6 +1812,7 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):              'treatment_file__type__label__iexact'          ),      } +    ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)      UP_MODEL_QUERY = {} diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 05e0860cb..e25161fef 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -40,7 +40,7 @@ from bootstrap_datepicker.widgets import DatePicker  from ishtar_common.forms import name_validator, reverse_lazy, \      get_form_selection, ManageOldType, FinalForm, FormSet, \ -    CustomForm, FieldType, HistorySelect, FormHeader +    CustomForm, FieldType, HistorySelect, FormHeader, TableSelect  from ishtar_common.forms_common import get_town_field  from archaeological_finds.forms import FindMultipleFormSelection, \      SelectFindBasketForm @@ -87,7 +87,7 @@ SelectedDivisionFormset.form_admin_name = _(u"Warehouse - 020 - Divisions")  SelectedDivisionFormset.form_slug = "warehouse-020-divisions" -class WarehouseSelect(HistorySelect): +class WarehouseSelect(CustomForm, TableSelect):      _model = models.Warehouse      form_admin_name = _(u"Warehouse - 001 - Search")      form_slug = "warehouse-001-search" diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 9783682a9..08d773a4f 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -474,6 +474,7 @@ class Container(DocumentItem, LightHistorizedItem, QRCodeItem, GeoItem,                  'finds__description__iexact'),      } +    ALT_NAMES.update(LightHistorizedItem.ALT_NAMES)      DYNAMIC_REQUESTS = {          'division': DynamicRequest( diff --git a/ishtar_common/models.py b/ishtar_common/models.py index c9a66f861..e5235f808 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1866,6 +1866,21 @@ class BaseHistorizedItem(FullSearch, Imported, JsonData, FixAssociated):      last_modified = models.DateTimeField(auto_now=True)      history_m2m = JSONField(default={}, blank=True) +    ALT_NAMES = { +        'history_creator': SearchAltName( +            pgettext_lazy("key for text search", u"created-by"), +            'history_creator__ishtaruser__person__cached_label__iexact' +        ), +        'history_modifier': SearchAltName( +            pgettext_lazy("key for text search", u"modified-by"), +            'history_modifier__ishtaruser__person__cached_label__iexact' +        ), +        'modified_since': SearchAltName( +            pgettext_lazy("key for text search", u"modified-since"), +            'last_modified__gte' +        ), +    } +      class Meta:          abstract = True @@ -4531,6 +4546,7 @@ class Document(BaseHistorizedItem, OwnPerms, ImageModel, ValueGetter, MainItem):              'warehouses__name__iexact'          ),      } +    ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)      objects = ExternalIdManager()      RELATIVE_SESSION_NAMES = [ diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 96190f083..d54c7d15b 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -661,43 +661,47 @@ for language_code, language_lbl in settings.LANGUAGES:  def _manage_dated_fields(dated_fields, dct): +    keys = list(dct.keys())      for k in dated_fields: -        if k in dct: -            if not dct[k]: -                dct.pop(k) -                continue -            value = dct[k].replace('"', '').strip() -            has_today = False -            for today in TODAYS: -                if value.startswith(today): -                    base_date = datetime.date.today() -                    value = value[len(today):].replace(' ', '') -                    if value and value[0] in (u"-", u"+"): -                        sign = value[0] -                        try: -                            days = int(value[1:]) -                        except ValueError: -                            days = 0 -                        if days: -                            if sign == u"-": -                                base_date = base_date - datetime.timedelta( -                                    days=days) -                            else: -                                base_date = base_date + datetime.timedelta( -                                    days=days) -                    dct[k] = base_date.strftime('%Y-%m-%d') -                    has_today = True -                    break -            if has_today: -                continue -            try: -                items = value.split('/') -                assert len(items) == 3 -                dct[k] = virtualtime.datetime(*map(lambda x: int(x), -                                              reversed(items))) \ -                    .strftime('%Y-%m-%d') -            except AssertionError: -                dct.pop(k) +        res = [j for j in keys if j.startswith(k)] +        if not res: +            continue +        k = res[0] +        if not dct[k]: +            dct.pop(k) +            continue +        value = dct[k].replace('"', '').strip() +        has_today = False +        for today in TODAYS: +            if value.startswith(today): +                base_date = datetime.date.today() +                value = value[len(today):].replace(' ', '') +                if value and value[0] in (u"-", u"+"): +                    sign = value[0] +                    try: +                        days = int(value[1:]) +                    except ValueError: +                        days = 0 +                    if days: +                        if sign == u"-": +                            base_date = base_date - datetime.timedelta( +                                days=days) +                        else: +                            base_date = base_date + datetime.timedelta( +                                days=days) +                dct[k] = base_date.strftime('%Y-%m-%d') +                has_today = True +                break +        if has_today: +            continue +        try: +            items = value.split('/') +            assert len(items) == 3 +            dct[k] = virtualtime.datetime(*map(lambda x: int(x), +                                          reversed(items))) \ +                .strftime('%Y-%m-%d') +        except AssertionError: +            dct.pop(k)  def _clean_type_val(val): @@ -1180,6 +1184,7 @@ def _get_data_from_query_old(items, query_table_cols, request,  DEFAULT_ROW_NUMBER = 10  # length is used by ajax DataTables requests  EXCLUDED_FIELDS = ['length'] +BASE_DATED_FIELDS = ['last_modified']  def get_item(model, func_name, default_name, extra_request_keys=None, @@ -1288,6 +1293,7 @@ def get_item(model, func_name, default_name, extra_request_keys=None,              my_dated_fields = model.DATED_FIELDS[:]          else:              my_dated_fields = dated_fields[:] if dated_fields else [] +        my_dated_fields += BASE_DATED_FIELDS          if not associated_models and hasattr(model, 'ASSOCIATED_MODELS'):              my_associated_models = model.ASSOCIATED_MODELS[:]          else: | 
