Commits

Anonymous committed be4c711

send signal on ProjectAccessControlForm 'project_type' validation

Comments (0)

Files changed (4)

transifex/addons/webhooks/tests.py

     """Test signal handlers for project edit form."""
 
     def test_add_field(self):
-        kwargs = {'form': ProjectForm(None)}
+        kwargs = {'form': ProjectForm()}
         add_web_hook_field(None, **kwargs)
         self.assertIn('webhook', kwargs['form'].fields)
 

transifex/projects/forms.py

             'bug_tracker', 'source_language', 'logo',
         )
 
-    def __init__(self, owner, *args, **kwargs):
+    def __init__(self, *args, **kwargs):
         # we need this because the number of private projects validation may
         # depend on the owner's subscription
-        self.owner = owner
+        self.owner = kwargs.get('owner', None)
 
         super(ProjectForm, self).__init__(*args, **kwargs)
         # Disable the source_language widget when updating
             del cleaned_data["project_type"]
 
         return cleaned_data
+
+    def clean_project_type(self):
+        project_type_check.send(sender=ProjectForm, instance=self)
+        return self.cleaned_data['project_type']

transifex/projects/signals.py

 
 #Signals used by subscriptions
 project_private_check = Signal(providing_args=['instance'])
+project_type_check = Signal(providing_args=['instance'])
 
 class ClaNotSignedError(Exception): pass

transifex/projects/views/project.py

         project = None
 
     if request.method == 'POST':
-        project_form = ProjectForm(request.user, request.POST, request.FILES,
-                                   instance=project, prefix='project')
+        project_form = ProjectForm(
+            request.POST, request.FILES, instance=project, prefix='project',
+            owner=request.user
+        )
         if project_form.is_valid():
             project = project_form.save(commit=False)
             project_id = project.id