diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-05-12 17:45:08 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-05-12 17:45:08 +0200 |
commit | 7d8bfcc053c9d3448e405f90df6eff214ac7d2e3 (patch) | |
tree | 9071c6c3d33e85fe13288a893607ec08789f420f | |
parent | fe9484b72cd2daed7cfb2bf7f9b330bd0e0b76dd (diff) | |
download | Ishtar-7d8bfcc053c9d3448e405f90df6eff214ac7d2e3.tar.bz2 Ishtar-7d8bfcc053c9d3448e405f90df6eff214ac7d2e3.zip |
Add operator to searches (refs #1678)
-rw-r--r-- | archaeological_operations/forms.py | 9 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 20 | ||||
-rw-r--r-- | archaeological_operations/views.py | 3 | ||||
-rw-r--r-- | ishtar_common/models.py | 2 |
4 files changed, 27 insertions, 7 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index dc9513977..11055ccfb 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -189,6 +189,8 @@ SRA_AGENT, created =PersonType.objects.get_or_create(txt_idx='sra_agent') HEAD_SCIENTIST, created = PersonType.objects.get_or_create( txt_idx='head_scientist') +OPERATOR, created = OrganizationType.objects.get_or_create(txt_idx='operator') + class OperationSelect(TableSelect): year = forms.IntegerField(label=_("Year")) operation_code = forms.IntegerField(label=_(u"Numeric reference")) @@ -209,6 +211,11 @@ class OperationSelect(TableSelect): args=["_".join( [unicode(PersonType.objects.get(txt_idx='sra_agent').pk)])]), associated_model=Person), label=_(u"In charge")) + operator = forms.IntegerField(label=_("Operator"), + widget=widgets.JQueryAutoComplete(reverse_lazy( + 'autocomplete-organization', args=[OPERATOR.pk]), + associated_model=Organization), + validators=[valid_id(Organization)]) remains = forms.ChoiceField(label=_(u"Remains"), choices=[]) periods = forms.ChoiceField(label=_(u"Periods"), choices=[]) start_before = forms.DateField(label=_(u"Started before"), @@ -287,8 +294,6 @@ class OperationFormFileChoice(forms.Form): associated_model=File), validators=[valid_id(File)], required=False) -OPERATOR, created = OrganizationType.objects.get_or_create(txt_idx='operator') - class OperationFormGeneral(forms.Form): form_label = _(u"General") base_model = 'archaeological_site' diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index afcbc39ff..2dd3c519e 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -310,9 +310,19 @@ def create_user(): password) return username, password, user -def create_operation(user): +def create_orga(user): + orga_type, created = OrganizationType.objects.get_or_create( + txt_idx='operator') + orga, created = Organization.objects.get_or_create(name='Operator', + organization_type=orga_type, + history_modifier=user) + return [orga] + +def create_operation(user, orga=None): dct = {'year':2010, 'operation_type_id':1, - 'history_modifier':user,} + 'history_modifier':user,} + if orga: + dct['operator'] = orga operations = [models.Operation.objects.create(**dct)] return operations @@ -326,7 +336,8 @@ class OperationTest(TestCase): def setUp(self): self.username, self.password, self.user = create_user() - self.operations = create_operation(self.user) + self.orgas = create_orga(self.user) + self.operations = create_operation(self.user, self.orgas[0]) self.item = self.operations[0] def testSearch(self): @@ -337,6 +348,9 @@ class OperationTest(TestCase): c.login(username=self.username, password=self.password) response = c.get(reverse('get-operation'), {'year': '2010',}) self.assertTrue(json.loads(response.content)['total'] == 1) + response = c.get(reverse('get-operation'), + {'operator': self.orgas[0].pk}) + self.assertTrue(json.loads(response.content)['total'] == 1) def create_administrativact(user, operation): act_type, created = models.ActType.objects.get_or_create(txt_idx='act_type') diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index 4156f09be..88d82bc3a 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -159,7 +159,8 @@ get_administrativeact = get_item(models.AdministrativeAct, 'indexed':'index__isnull', 'operation__towns':'operation__towns__pk'}, reversed_bool_fields = ['index__isnull'],) -show_administrativeact = show_item(models.AdministrativeAct, 'administrativeact') +show_administrativeact = show_item(models.AdministrativeAct, + 'administrativeact') def dashboard_operation(request, *args, **kwargs): """ diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 429c8217b..fd4a76dc0 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2010-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2010-2014 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as |