diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-05-12 17:02:56 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-05-12 17:02:56 +0200 |
commit | fe9484b72cd2daed7cfb2bf7f9b330bd0e0b76dd (patch) | |
tree | 592a834685dac25aad04bb0f4505ec9006e787b4 /archaeological_operations | |
parent | 9d3f78cb51f05c6f39d95b222bbd03cf19018e60 (diff) | |
download | Ishtar-fe9484b72cd2daed7cfb2bf7f9b330bd0e0b76dd.tar.bz2 Ishtar-fe9484b72cd2daed7cfb2bf7f9b330bd0e0b76dd.zip |
Work on registry search (refs #1680) - work on operations test
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/forms.py | 16 | ||||
-rw-r--r-- | archaeological_operations/models.py | 5 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 89 | ||||
-rw-r--r-- | archaeological_operations/views.py | 5 |
4 files changed, 102 insertions, 13 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 9bdb9ac77..dc9513977 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -185,6 +185,10 @@ ParcelFormSet = formset_factory(ParcelForm, can_delete=True, formset=ParcelFormSet) ParcelFormSet.form_label = _(u"Parcels") +SRA_AGENT, created =PersonType.objects.get_or_create(txt_idx='sra_agent') +HEAD_SCIENTIST, created = PersonType.objects.get_or_create( + txt_idx='head_scientist') + class OperationSelect(TableSelect): year = forms.IntegerField(label=_("Year")) operation_code = forms.IntegerField(label=_(u"Numeric reference")) @@ -198,8 +202,7 @@ class OperationSelect(TableSelect): scientist = forms.IntegerField( widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person', args=["_".join( - [unicode(PersonType.objects.get(txt_idx='head_scientist').pk), - unicode(PersonType.objects.get(txt_idx='sra_agent').pk)])]), + [unicode(HEAD_SCIENTIST.pk), unicode(SRA_AGENT.pk)])]), associated_model=Person), label=_(u"Scientist in charge")) in_charge = forms.IntegerField( widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person', @@ -284,6 +287,8 @@ 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' @@ -297,14 +302,12 @@ class OperationFormGeneral(forms.Form): scientist = forms.IntegerField(label=_("Head scientist"), widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person', args=["_".join( - [unicode(PersonType.objects.get(txt_idx='head_scientist').pk), - unicode(PersonType.objects.get(txt_idx='sra_agent').pk)])]), + [unicode(HEAD_SCIENTIST.pk), unicode(SRA_AGENT.pk)])]), associated_model=Person, new=True), validators=[valid_id(Person)], required=False) operator = forms.IntegerField(label=_("Operator"), widget=widgets.JQueryAutoComplete(reverse_lazy( - 'autocomplete-organization', - args=[OrganizationType.objects.get(txt_idx='operator').pk]), + 'autocomplete-organization', args=[OPERATOR.pk]), associated_model=Organization, new=True), validators=[valid_id(Organization)], required=False) in_charge = forms.IntegerField(label=_("In charge"), @@ -732,6 +735,7 @@ class GenerateDocForm(forms.Form): [(choice.pk , unicode(choice)) for choice in choices] class AdministrativeActRegisterSelect(AdministrativeActOpeSelect): + indexed = forms.NullBooleanField(label=_(u"Indexed?")) def __init__(self, *args, **kwargs): super(AdministrativeActRegisterSelect, self).__init__(*args, **kwargs) diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 65f544721..7bd84c6e7 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -58,6 +58,10 @@ class OperationType(GeneralType): except cls.DoesNotExist: pass items = cls.objects.filter(**dct) + if default: + exclude.append(default.txt_idx) + if exclude: + items = items.exclude(txt_idx__in=exclude) current_preventive, current_lst = None, None for item in items.order_by(*cls._meta.ordering).all(): if not current_lst or item.preventive != current_preventive: @@ -486,6 +490,7 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): _prefix = 'adminact_' class Meta: + ordering = ('index', 'act_type') verbose_name = _(u"Administrative act") verbose_name_plural = _(u"Administrative acts") permissions = ( diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 0a48f4d4a..afcbc39ff 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2012-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2012-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 @@ -20,20 +20,27 @@ """ Unit tests """ -import json, os +import json, os, datetime +from django.conf import settings from django.core.management import call_command +from django.core.urlresolvers import reverse from django.test import TestCase +from django.test.client import Client from django.contrib.auth.models import User import models -from ishtar_common.models import OrganizationType, Organization, Town +from ishtar_common.models import OrganizationType, Organization, Town, \ + PersonType class ImportOperationTest(TestCase): - fixtures = [settings.ROOT_PATH + '../ishtar_common/fixtures/initial_data.json', - settings.ROOT_PATH + '../archaeological_files/fixtures/initial_data.json', - settings.ROOT_PATH + '../archaeological_operations/fixtures/initial_data-fr.json'] + fixtures = [settings.ROOT_PATH + + '../ishtar_common/fixtures/initial_data.json', + settings.ROOT_PATH + + '../archaeological_files/fixtures/initial_data.json', + settings.ROOT_PATH + + '../archaeological_operations/fixtures/initial_data-fr.json'] def setUp(self): user = User.objects.create_user('username') @@ -296,3 +303,73 @@ class ImportOperationTest(TestCase): value) ) +def create_user(): + username = 'username4277' + password = 'dcbqj756456!@%' + user = User.objects.create_superuser(username, "nomail@nomail.com", + password) + return username, password, user + +def create_operation(user): + dct = {'year':2010, 'operation_type_id':1, + 'history_modifier':user,} + operations = [models.Operation.objects.create(**dct)] + return operations + +class OperationTest(TestCase): + fixtures = [settings.ROOT_PATH + + '../ishtar_common/fixtures/initial_data.json', + settings.ROOT_PATH + + '../archaeological_files/fixtures/initial_data.json', + settings.ROOT_PATH + + '../archaeological_operations/fixtures/initial_data-fr.json'] + + def setUp(self): + self.username, self.password, self.user = create_user() + self.operations = create_operation(self.user) + self.item = self.operations[0] + + def testSearch(self): + c = Client() + response = c.get(reverse('get-operation'), {'year': '2010',}) + # no result when no authentification + self.assertTrue(not json.loads(response.content)) + c.login(username=self.username, password=self.password) + response = c.get(reverse('get-operation'), {'year': '2010',}) + 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') + dct = {'history_modifier':user, + 'act_type':act_type, + 'operation':operation, + 'signature_date':datetime.date(2014, 05, 12), + 'index':322} + adminact, created = models.AdministrativeAct.objects.get_or_create(**dct) + return [act_type], [adminact] + + +class RegisterTest(TestCase): + fixtures = [settings.ROOT_PATH + + '../ishtar_common/fixtures/initial_data.json', + settings.ROOT_PATH + + '../archaeological_files/fixtures/initial_data.json', + settings.ROOT_PATH + + '../archaeological_operations/fixtures/initial_data-fr.json'] + + def setUp(self): + self.username, self.password, self.user = create_user() + self.operations = create_operation(self.user) + self.act_types, self.operations = create_administrativact( + self.user, self.operations[0]) + + def testSearch(self): + c = Client() + response = c.get(reverse('get-administrativeact'), {'year': '2014',}) + # no result when no authentification + self.assertTrue(not json.loads(response.content)) + c.login(username=self.username, password=self.password) + response = c.get(reverse('get-administrativeact'), {'year': '2014',}) + self.assertTrue(json.loads(response.content)['total'] == 1) + response = c.get(reverse('get-administrativeact'), {'indexed': '2',}) + self.assertTrue(json.loads(response.content)['total'] == 1) diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index 5d5038758..4156f09be 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -155,7 +155,10 @@ get_administrativeactop = get_item(models.AdministrativeAct, get_administrativeact = get_item(models.AdministrativeAct, 'get_administrativeact', 'administrativeact', - extra_request_keys={'year':'signature_date__year',}) + extra_request_keys={'year':'signature_date__year', + 'indexed':'index__isnull', + 'operation__towns':'operation__towns__pk'}, + reversed_bool_fields = ['index__isnull'],) show_administrativeact = show_item(models.AdministrativeAct, 'administrativeact') def dashboard_operation(request, *args, **kwargs): |