summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2020-12-29 12:09:08 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-28 12:15:23 +0100
commit752d3d8eda5cd968faf0d370ae2d781575c60d90 (patch)
tree6f28b883d2ab3d8d94c0774134ce3d8d703ff277
parentff8cf8f853914a847609c05c973e5ac199e30c6b (diff)
downloadIshtar-752d3d8eda5cd968faf0d370ae2d781575c60d90.tar.bz2
Ishtar-752d3d8eda5cd968faf0d370ae2d781575c60d90.zip
Unaccent search for person/orga. Tips for operation form
-rw-r--r--archaeological_operations/forms.py48
-rw-r--r--archaeological_operations/models.py10
-rw-r--r--example_project/settings.py1
-rw-r--r--ishtar_common/migrations/0208_unaccent.py17
-rw-r--r--ishtar_common/models.py8
-rw-r--r--ishtar_common/views.py16
6 files changed, 67 insertions, 33 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index c4eef1fc2..98f263ab6 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -30,6 +30,7 @@ from django.core import validators
from django.db.models import Max
from django.forms.formsets import formset_factory, DELETION_FIELD_NAME, \
TOTAL_FORM_COUNT
+from django.utils.functional import lazy
from django.utils.safestring import mark_safe
from ishtar_common.utils import ugettext_lazy as _, pgettext_lazy
@@ -46,7 +47,8 @@ from ishtar_common.forms_common import TownFormSet, get_town_field, TownForm
from ishtar_common.models import valid_id, valid_ids, Person, Town, \
DocumentTemplate, Organization, get_current_profile, \
person_type_pks_lazy, person_type_pk_lazy, organization_type_pks_lazy, \
- organization_type_pk_lazy, SpatialReferenceSystem, Area
+ organization_type_pk_lazy, SpatialReferenceSystem, Area, \
+ get_sra_agent_label, get_sra_agent_head_scientist_label, get_operator_label
from ishtar_common.wizards import MultiValueDict
from .widgets import ParcelWidget, SelectParcelWidget, OAWidget
@@ -793,7 +795,7 @@ class OperationFormGeneral(CustomForm, ManageOldType):
validators=[validators.MinValueValidator(1000),
validators.MaxValueValidator(2100)])
old_code = forms.CharField(
- label=_(u"Old code"), required=False,
+ label=_("Old code"), required=False,
validators=[validators.MaxLengthValidator(200)])
scientist = forms.IntegerField(
label=_("Head scientist"),
@@ -802,6 +804,7 @@ class OperationFormGeneral(CustomForm, ManageOldType):
'autocomplete-person',
args=[person_type_pks_lazy(['head_scientist', 'sra_agent'])]),
associated_model=Person,
+ tips=lazy(get_sra_agent_head_scientist_label),
limit={
'person_types': (person_type_pk_lazy('head_scientist'),
person_type_pk_lazy('sra_agent'))},
@@ -813,6 +816,7 @@ class OperationFormGeneral(CustomForm, ManageOldType):
reverse_lazy('autocomplete-organization',
args=[organization_type_pk_lazy('operator')]),
limit={'organization_type': organization_type_pk_lazy('operator')},
+ tips=lazy(get_operator_label),
associated_model=Organization, new=True),
validators=[valid_id(Organization)], required=False)
operator_reference = forms.CharField(label=_(u"Operator reference"),
@@ -824,6 +828,7 @@ class OperationFormGeneral(CustomForm, ManageOldType):
'autocomplete-person',
args=[person_type_pks_lazy(['sra_agent'])]),
associated_model=Person,
+ tips=lazy(get_sra_agent_label),
limit={'person_types': [person_type_pk_lazy('sra_agent')]},
new=True),
validators=[valid_id(Person)], required=False)
@@ -840,11 +845,11 @@ class OperationFormGeneral(CustomForm, ManageOldType):
report_processing = forms.ChoiceField(label=_(u"Report processing"),
choices=[], required=False)
if settings.COUNTRY == 'fr':
- cira_date = DateField(label=u"Date avis CIRA", required=False)
+ cira_date = DateField(label="Date avis CTRA/CIRA", required=False)
negative_result = forms.NullBooleanField(
- required=False, label=u"Résultat considéré comme négatif")
+ required=False, label="Résultat considéré comme négatif")
cira_rapporteur = forms.IntegerField(
- label=u"Rapporteur CIRA",
+ label="Rapporteur CTRA/CIRA",
widget=widgets.JQueryAutoComplete(
reverse_lazy(
'autocomplete-person',
@@ -853,41 +858,42 @@ class OperationFormGeneral(CustomForm, ManageOldType):
limit={'person_types': [
person_type_pk_lazy('sra_agent'),
person_type_pk_lazy('head_scientist')]},
+ tips=lazy(get_sra_agent_head_scientist_label),
associated_model=Person, new=True),
validators=[valid_id(Person)], required=False)
documentation_deadline = DateField(
- label=_(u"Deadline for submission of the documentation"),
+ label=_("Deadline for submission of the documentation"),
required=False)
documentation_received = forms.NullBooleanField(
- required=False, label=_(u"Documentation received"))
+ required=False, label=_("Documentation received"))
finds_deadline = DateField(
- label=_(u"Deadline for submission of the finds"), required=False,
+ label=_("Deadline for submission of the finds"), required=False,
)
finds_received = forms.NullBooleanField(
- required=False, label=_(u"Finds received"))
+ required=False, label=_("Finds received"))
- comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea,
+ comment = forms.CharField(label=_("Comment"), widget=forms.Textarea,
required=False)
scientific_documentation_comment = forms.CharField(
- label=_(u"Comment about scientific documentation"),
+ label=_("Comment about scientific documentation"),
widget=forms.Textarea, required=False)
- record_quality_type = forms.ChoiceField(label=_(u"Record quality"),
+ record_quality_type = forms.ChoiceField(label=_("Record quality"),
required=False)
virtual_operation = forms.BooleanField(required=False,
- label=_(u"Virtual operation"))
+ label=_("Virtual operation"))
- HEADERS['x'] = FormHeader(_(u"Coordinates"))
- x = forms.FloatField(label=_(u"X"), required=False)
- estimated_error_x = forms.FloatField(label=_(u"Estimated error for X"),
+ HEADERS['x'] = FormHeader(_("Coordinates"))
+ x = forms.FloatField(label=_("X"), required=False)
+ estimated_error_x = forms.FloatField(label=_("Estimated error for X"),
required=False)
- y = forms.FloatField(label=_(u"Y"), required=False)
- estimated_error_y = forms.FloatField(label=_(u"Estimated error for Y"),
+ y = forms.FloatField(label=_("Y"), required=False)
+ estimated_error_y = forms.FloatField(label=_("Estimated error for Y"),
required=False)
- z = forms.FloatField(label=_(u"Z"), required=False)
- estimated_error_z = forms.FloatField(label=_(u"Estimated error for Z"),
+ z = forms.FloatField(label=_("Z"), required=False)
+ estimated_error_z = forms.FloatField(label=_("Estimated error for Z"),
required=False)
spatial_reference_system = forms.ChoiceField(
- label=_(u"Spatial Reference System"), required=False, choices=[])
+ label=_("Spatial Reference System"), required=False, choices=[])
FILE_FIELDS = [
'report_delivery_date',
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 7f23399ea..8436121a4 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -786,9 +786,9 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem,
'in_charge__surname': _("In charge (surname)"),
'in_charge__name': _("In charge (name)"),
'in_charge__attached_to__name': _("In charge - Organization (name)"),
- 'cira_rapporteur__surname': "Rapporteur CIRA (prénom)",
- 'cira_rapporteur__name': "Rapporteur CIRA (nom)",
- 'cira_rapporteur__attached_to__name': "Rapporteur CIRA - "
+ 'cira_rapporteur__surname': "Rapporteur CTRA/CIRA (prénom)",
+ 'cira_rapporteur__name': "Rapporteur CTRA/CIRA (nom)",
+ 'cira_rapporteur__attached_to__name': "Rapporteur CTRA/CIRA - "
"Organisation (nom)",
'archaeological_sites__reference':
_("Archaeological sites (reference)"),
@@ -1116,10 +1116,10 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem,
null=True) # preventive diag
cira_rapporteur = models.ForeignKey(
Person, related_name='cira_rapporteur', null=True, blank=True,
- on_delete=models.SET_NULL, verbose_name="Rapporteur CIRA")
+ on_delete=models.SET_NULL, verbose_name="Rapporteur CTRA/CIRA")
negative_result = models.NullBooleanField(
"Résultat considéré comme négatif", blank=True, null=True)
- cira_date = models.DateField("Date avis CIRA", null=True, blank=True)
+ cira_date = models.DateField("Date avis CTRA/CIRA", null=True, blank=True)
eas_number = models.CharField("Numéro de l'EA", max_length=20,
null=True, blank=True)
## end fr
diff --git a/example_project/settings.py b/example_project/settings.py
index 53c436501..c5b1171bd 100644
--- a/example_project/settings.py
+++ b/example_project/settings.py
@@ -172,6 +172,7 @@ INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
+ 'django.contrib.postgres',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.gis',
diff --git a/ishtar_common/migrations/0208_unaccent.py b/ishtar_common/migrations/0208_unaccent.py
new file mode 100644
index 000000000..57aa9ea9e
--- /dev/null
+++ b/ishtar_common/migrations/0208_unaccent.py
@@ -0,0 +1,17 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.27 on 2020-12-29 11:50
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+from django.contrib.postgres.operations import UnaccentExtension
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0207_auto_20201207_2337'),
+ ]
+
+ operations = [
+ UnaccentExtension()
+ ]
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index c178b187f..807bbc64f 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1862,6 +1862,14 @@ def get_publisher_label():
return _("Error: publisher type is missing")
+def get_operator_label():
+ if apps.ready:
+ lbl = get_general_type_label(OrganizationType, "operator")
+ if lbl:
+ return lbl
+ return _("Error: operator type is missing")
+
+
class TitleType(GenderedType):
long_title = models.TextField(_("Long title"), default="", blank=True)
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index e445cb44d..d5b38ebed 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -613,9 +613,9 @@ def autocomplete_ishtaruser(request):
return HttpResponseBadRequest()
query = Q()
for q in q.split(' '):
- qu = (Q(person__name__icontains=q) |
- Q(person__surname__icontains=q) |
- Q(person__raw_name__icontains=q))
+ qu = (Q(person__name__unaccent__icontains=q) |
+ Q(person__surname__unaccent__icontains=q) |
+ Q(person__raw_name__unaccent__icontains=q))
query = query & qu
users = models.IshtarUser.objects.filter(query).distinct()[:limit]
data = json.dumps([
@@ -643,10 +643,12 @@ def autocomplete_person(request, person_types=None, attached_to=None,
return HttpResponseBadRequest()
query = Q()
for q in q.split(' '):
- qu = (Q(name__icontains=q) | Q(surname__icontains=q) |
- Q(email__icontains=q) | Q(attached_to__name__icontains=q))
+ qu = (Q(name__unaccent__icontains=q) |
+ Q(surname__unaccent__icontains=q) |
+ Q(email__unaccent__icontains=q) |
+ Q(attached_to__name__unaccent__icontains=q))
if permissive:
- qu = qu | Q(raw_name__icontains=q)
+ qu = qu | Q(raw_name__unaccent__icontains=q)
query = query & qu
if attached_to:
query = query & Q(attached_to__pk__in=attached_to.split('_'))
@@ -780,7 +782,7 @@ def autocomplete_organization(request, orga_type=None):
q = request.GET.get('term')
query = Q()
for q in q.split(' '):
- extra = Q(cached_label__icontains=q)
+ extra = Q(cached_label__unaccent__icontains=q)
query = query & extra
if orga_type:
try: