summaryrefslogtreecommitdiff
path: root/archaeological_context_records
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-10 17:59:44 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-13 18:26:04 +0200
commit1ee3cc6e7f0b0d6207d065b155ed77bfbb5ad5c4 (patch)
tree04f21ad44a463b7e9677f56f9243b7e5de228811 /archaeological_context_records
parent1d94279572cd21e9d126ac73f6f13dad91c59c23 (diff)
downloadIshtar-1ee3cc6e7f0b0d6207d065b155ed77bfbb5ad5c4.tar.bz2
Ishtar-1ee3cc6e7f0b0d6207d065b155ed77bfbb5ad5c4.zip
Context record search configuration
Diffstat (limited to 'archaeological_context_records')
-rw-r--r--archaeological_context_records/forms.py41
-rw-r--r--archaeological_context_records/models.py57
2 files changed, 69 insertions, 29 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
index 2fd3fee9a..b659c64f1 100644
--- a/archaeological_context_records/forms.py
+++ b/archaeological_context_records/forms.py
@@ -57,7 +57,9 @@ class OperationFormSelection(CustomForm, forms.Form):
validators=[valid_id(Operation)])
-class RecordSelect(CustomForm, TableSelect):
+class RecordSelect(CustomForm, TableSelect): # OK
+ _model = models.ContextRecord
+
form_admin_name = _(u"Context record - 001 - Search")
form_slug = "contextrecord-001-search"
search_vector = forms.CharField(
@@ -80,38 +82,23 @@ class RecordSelect(CustomForm, TableSelect):
reverse_lazy('autocomplete-archaeologicalsite'),
associated_model=ArchaeologicalSite),
validators=[valid_id(ArchaeologicalSite)])
- ope_relation_types = forms.MultipleChoiceField(
- label=_(u"Search within related operations"), choices=[],
- widget=forms.CheckboxSelectMultiple)
+ ope_relation_types = forms.ChoiceField(
+ label=_(u"Search within related operations"), choices=[])
datings__period = forms.ChoiceField(label=_(u"Period"), choices=[])
unit = forms.ChoiceField(label=_(u"Unit type"), choices=[])
- parcel = ParcelField(label=_(u"Parcel (section/number/public domain)"))
- cr_relation_types = forms.MultipleChoiceField(
- label=_(u"Search within relations"), choices=[],
- widget=forms.CheckboxSelectMultiple)
+ parcel = forms.CharField(label=_(u"Parcel"))
+ cr_relation_types = forms.ChoiceField(
+ label=_(u"Search within relations"), choices=[])
- def __init__(self, *args, **kwargs):
- super(RecordSelect, self).__init__(*args, **kwargs)
- if 'datings__period' in self.fields:
- self.fields['datings__period'].choices = Period.get_types()
- self.fields['datings__period'].help_text = Period.get_help()
- if 'unit' in self.fields:
- self.fields['unit'].choices = models.Unit.get_types()
- self.fields['unit'].help_text = models.Unit.get_help()
- if 'cr_relation_types' in self.fields:
- self.fields['cr_relation_types'].choices = \
- models.RelationType.get_types(empty_first=False)
- if 'ope_relation_types' in self.fields:
- self.fields['ope_relation_types'].choices = \
- OpeRelationType.get_types(empty_first=False)
+ TYPES = [
+ FieldType('datings__period', Period),
+ FieldType('unit', models.Unit),
+ FieldType('cr_relation_types', models.RelationType),
+ FieldType('ope_relation_types', OpeRelationType),
+ ]
def get_input_ids(self):
ids = super(RecordSelect, self).get_input_ids()
- if 'parcel' in ids:
- ids.pop(ids.index('parcel'))
- ids.append('parcel_0')
- ids.append('parcel_1')
- ids.append('parcel_2')
if 'cr_relation_types' in ids:
ids.pop(ids.index('cr_relation_types'))
for idx, c in enumerate(self.fields['cr_relation_types'].choices):
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 211be9ade..97bf2a117 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -25,10 +25,10 @@ from django.core.urlresolvers import reverse
from django.db import connection, transaction
from django.db.models import Q
from django.db.models.signals import post_delete, post_save
-from django.utils.translation import ugettext_lazy as _, ugettext, pgettext
+from django.utils.translation import ugettext_lazy as _, pgettext, pgettext_lazy
from django.utils.text import slugify
-from ishtar_common.utils import cached_label_changed
+from ishtar_common.utils import cached_label_changed, TXT_SEARCH_COMMENT
from ishtar_common.models import Document, GeneralType, \
BaseHistorizedItem, HistoricalRecords, OwnPerms, ShortMenuItem, \
@@ -256,6 +256,55 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem,
RELATIVE_SESSION_NAMES = [
('operation', 'operation__pk'),
('file', 'operation__associated_file__pk')]
+ # alternative names of fields for searches
+ ALT_NAMES = {
+ 'label': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"id"),
+ 'label'
+ ),
+ 'town': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"town"),
+ 'town__cached_label__iexact'
+ ),
+ 'operation__year': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"operation-year"),
+ 'operation__year'
+ ),
+ 'operation__code_patriarche': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"patriarche"),
+ 'operation__code_patriarche'
+ ),
+ 'operation__operation_code': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"operation-code"),
+ 'operation__operation_code'
+ ),
+ 'archaeological_site': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"site"),
+ 'archaeological_site__cached_label__icontains'
+ ),
+ 'ope_relation_types': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"operation-relation-type"),
+ 'ope_relation_types'
+ ),
+ 'datings__period': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"period"),
+ 'datings__period__label__iexact'
+ ),
+ 'unit': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"unit-type"),
+ 'unit__label__iexact'
+ ),
+ 'parcel': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"parcel"),
+ 'parcel__cached_label__iexact'
+ ),
+ 'cr_relation_types': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"record-relation-type"),
+ 'cr_relation_types'
+ ),
+ }
+ for v in ALT_NAMES.values():
+ EXTRA_REQUEST_KEYS[v[0]] = v[1]
# fields
external_id = models.TextField(_(u"External ID"), blank=True, null=True)
@@ -670,5 +719,9 @@ class RecordRelationView(models.Model):
("view_recordrelation", u"Can view all record relations - view"),
]
+ @classmethod
+ def general_types(cls):
+ return []
+
def __unicode__(self):
return u"{} \"{}\"".format(self.relation_type, self.right_record)