diff options
Diffstat (limited to 'archaeological_operations')
| -rw-r--r-- | archaeological_operations/forms.py | 7 | ||||
| -rw-r--r-- | archaeological_operations/tests.py | 23 | ||||
| -rw-r--r-- | archaeological_operations/wizards.py | 6 | 
3 files changed, 33 insertions, 3 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 61be371d1..47fe746f5 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -997,8 +997,10 @@ OperationFormModifGeneral.associated_models = \  OperationFormModifGeneral.associated_models['associated_file'] = File -class CollaboratorForm(forms.Form): +class CollaboratorForm(CustomForm, forms.Form):      form_label = _(u"Collaborators") +    form_admin_name = _(u"Operation - Collaborators") +    form_slug = "operation-collaborators"      base_models = ['collaborator']      associated_models = {'collaborator': Person, }      collaborator = widgets.Select2MultipleField( @@ -1006,7 +1008,8 @@ class CollaboratorForm(forms.Form):      def __init__(self, *args, **kwargs):          super(CollaboratorForm, self).__init__(*args, **kwargs) -        self.fields['collaborator'].widget.attrs['full-width'] = True +        if 'collaborator' in self.fields: +            self.fields['collaborator'].widget.attrs['full-width'] = True  class OperationFormPreventive(forms.Form): diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 9f07aff45..af6199774 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1221,6 +1221,29 @@ class CustomFormTest(TestCase, OperationInitTest):              msg="filter user - 'address' field not found on the modification "                  "wizard. It should not have been filtered.") +    def test_enabled(self): +        c = Client() +        c.login(username=self.username, password=self.password) + +        cls_wiz = OperationWizardModifTest +        url = reverse(cls_wiz.url_name) +        # first wizard step +        step = 'selec-operation_modification' +        cls_wiz.wizard_post(c, url, step, {'pk': self.operations[0].pk}) + +        step = 'collaborators-operation_modification' +        data = { +            '{}{}-current_step'.format(cls_wiz.url_name, +                                       cls_wiz.wizard_name): [step], +        } +        response = c.post(url, data) +        self.assertNotEqual(response.status_code, 404) +        CustomForm.objects.create( +            name="Test2", form="operation-collaborators", available=True, +            apply_to_all=True, enabled=False) +        response = c.post(url, data) +        self.assertEqual(response.status_code, 404) +  class OperationSearchTest(TestCase, OperationInitTest):      fixtures = FILE_FIXTURES diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index fffe34ca7..24c1af45b 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -23,6 +23,7 @@ from django.conf import settings  from django.core.exceptions import ObjectDoesNotExist  from django.core.urlresolvers import reverse  from django.db.models import Max +from django.http import Http404  from django.shortcuts import render  from django.utils.translation import ugettext_lazy as _ @@ -149,7 +150,10 @@ class OperationWizard(Wizard):              data = {}          if not step:              step = self.steps.current -        form = self.get_form_list()[step] +        try: +            form = self.get_form_list()[step] +        except KeyError: +            raise Http404()          # manage the dynamic choice of towns          if step.startswith('towns') and hasattr(form, 'management_form'):              data['TOWNS'] = self.get_towns()  | 
