Commits

Anonymous committed 61d451e

store owner in ProjectForm instance and send signal on 'private' 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()}
+        kwargs = {'form': ProjectForm(None)}
         add_web_hook_field(None, **kwargs)
         self.assertIn('webhook', kwargs['form'].fields)
 

transifex/projects/forms.py

 
 from transifex.projects.models import Project
 from transifex.projects.signals import (project_access_control_form_start,
-                                        project_form_init, project_form_save)
+                                        project_form_init, project_form_save,
+                                        project_private_check)
 from transifex.txcommon.widgets import SplitSelectDateTimeWidget
 
 
             'bug_tracker', 'source_language', 'logo',
         )
 
-    def __init__(self, *args, **kwargs):
+    def __init__(self, owner, *args, **kwargs):
+        # we need this because the number of private projects validation may
+        # depend on the owner's subscription
+        self.owner = owner
+
         super(ProjectForm, self).__init__(*args, **kwargs)
         # Disable the source_language widget when updating
         if self.instance and self.instance.id:
         project_form_save.send(sender=ProjectForm, form=self, instance=retval)
         return retval
 
+    def clean_private(self):
+        project_private_check.send(sender=ProjectForm, instance=self)
+        return self.cleaned_data['private']
+
     def clean_tags(self):
         project_tags_list = self.cleaned_data['tags']
         tags = list(set([tag.strip() for tag in project_tags_list.split(',')])) or []
             self._errors["project_type"] = self.error_class([project_type_msg])
             del cleaned_data["project_type"]
 
-        return cleaned_data
+        return cleaned_data

transifex/projects/signals.py

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

transifex/projects/views/project.py

         project = None
 
     if request.method == 'POST':
-        project_form = ProjectForm(request.POST, request.FILES, instance=project,
-                                prefix='project')
+        project_form = ProjectForm(request.user, request.POST, request.FILES,
+                                   instance=project, prefix='project')
         if project_form.is_valid():
             project = project_form.save(commit=False)
             project_id = project.id
         else:
             initial_data = {"maintainers": [request.user.pk]}
 
-        project_form = ProjectForm(instance=project, prefix='project',
-                                   initial=initial_data)
+        project_form = ProjectForm(request.user, instance=project,
+                                   prefix='project', initial=initial_data)
 
     return render_to_response(template_name, {
         'project_form': project_form,