[damned-lies] Add ability to specify commit author



commit 2954ccc17c3f1daeca8ef2ad290629d0fd5c3cb7
Author: Claude Paroz <claude 2xlibre net>
Date:   Mon Feb 3 18:01:44 2014 +0100

    Add ability to specify commit author
    
    Thanks Enrico Nicoletto for the suggestion.

 people/models.py                        |    3 +
 stats/models.py                         |    7 +-
 stats/templatetags/stats_extras.py      |    4 +-
 templates/vertimus/vertimus_detail.html |    6 ++
 vertimus/forms.py                       |   11 +++-
 vertimus/models.py                      |   51 ++++++++++------
 vertimus/tests/tests.py                 |  100 +++++++++++++++++++------------
 vertimus/views.py                       |    6 +-
 8 files changed, 119 insertions(+), 69 deletions(-)
---
diff --git a/people/models.py b/people/models.py
index f516937..5ddac2d 100644
--- a/people/models.py
+++ b/people/models.py
@@ -126,6 +126,9 @@ class Person(User):
     def __unicode__(self):
         return self.name
 
+    def as_author(self):
+        return "%s <%s>" % (self.name, self.email)
+
     @models.permalink
     def get_absolute_url(self):
         return ('person_detail_username', [self.username])
diff --git a/stats/models.py b/stats/models.py
index f0d0555..557e167 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -672,7 +672,7 @@ class Branch(models.Model):
             self.checkout_lock.release()
         return 1
 
-    def commit_po(self, po_file, domain, language, user):
+    def commit_po(self, po_file, domain, language, author):
         """ Commit the file 'po_file' in the branch VCS repository """
         if self.is_vcs_readonly():
             raise Exception, "This branch is in read-only mode. Unable to commit"
@@ -695,8 +695,7 @@ class Branch(models.Model):
                 'branch':  self.name,
                 'po_file': dest_filename,
                 'lg_file': "LINGUAS",
-                'name':    user.name,
-                'email':   user.email,
+                'author': author,
                 'msg':     "Updated %s translation" % language.name,
             }
             with ModuleLock(self.module):
@@ -721,7 +720,7 @@ class Branch(models.Model):
                         utils.run_shell_command("cd \"%(dest)s\" && git add %(lg_file)s" % var_dict, 
raise_on_error=True)
                     var_dict['msg'] = "Added %s translation" % language.name
                 # git commit -m "Updated %s translation."
-                utils.run_shell_command("cd \"%(dest)s\" && git commit -m \"%(msg)s\" --author \"%(name)s 
<%(email)s>\"" % var_dict,
+                utils.run_shell_command("cd \"%(dest)s\" && git commit -m \"%(msg)s\" --author 
\"%(author)s\"" % var_dict,
                     raise_on_error=True)
                 # git push
                 utils.run_shell_command("cd \"%(dest)s\" && git push" % var_dict, raise_on_error=True)
diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py
index bc5149a..cfdfa49 100644
--- a/stats/templatetags/stats_extras.py
+++ b/stats/templatetags/stats_extras.py
@@ -222,8 +222,8 @@ def as_tr(field):
         errors = u''.join(["<li>%s</li>" % err for err in field.errors])
         errors_html = u'<ul class="errorlist">%s</ul>' % errors
 
-    return mark_safe(u'<tr><th>%s:</th><td>%s%s%s%s</td></tr>' % (
-        field.label_tag(), errors_html, field.as_widget(), help_link, help_html)
+    return mark_safe(u'<tr class="tr_%s"><th>%s:</th><td>%s%s%s%s</td></tr>' % (
+        field.name, field.label_tag(), errors_html, field.as_widget(), help_link, help_html)
     )
 
 
diff --git a/templates/vertimus/vertimus_detail.html b/templates/vertimus/vertimus_detail.html
index 1706259..44abc67 100644
--- a/templates/vertimus/vertimus_detail.html
+++ b/templates/vertimus/vertimus_detail.html
@@ -7,6 +7,9 @@
 {% endblock %}
 
 {% block extrahead %}
+<style type="text/css">
+tr.tr_author { display: none; }
+</style>
 <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.growfield2.js"></script>
 <script type="text/javascript">
 $(document).ready(function() {
@@ -15,6 +18,8 @@ $(document).ready(function() {
       $("#id_send_to_ml").attr('checked', send_mail_defaults[$("#id_action").val()]);
       $("#id_action").change(function () {
         $("#id_send_to_ml").attr('checked', send_mail_defaults[$(this).val()]);
+        $("tr.tr_author").toggle(this.value == 'CI');
+        $("tr.tr_file").toggle(this.value != 'CI');
       });
     }
 });
@@ -231,6 +236,7 @@ $(document).ready(function() {
     {% csrf_token %}
     <table>
       {{ action_form.action|as_tr }}
+      {{ action_form.author|as_tr }}
       {{ action_form.comment|as_tr }}
       {{ action_form.file|as_tr }}
       {% if action_form.send_to_ml %}
diff --git a/vertimus/forms.py b/vertimus/forms.py
index f10910d..6cadbab 100644
--- a/vertimus/forms.py
+++ b/vertimus/forms.py
@@ -23,7 +23,8 @@ import os
 from django import forms
 from django.core.urlresolvers import reverse
 from django.utils.translation import ugettext_lazy as _
-from vertimus.models import Action
+from vertimus.models import Action, ActionCI
+from stats.models import Person
 from stats.utils import po_file_stats
 
 class ActionWidget(forms.Select):
@@ -44,17 +45,23 @@ class ActionForm(forms.Form):
         max_length=5000,
         required=False,
         widget=forms.Textarea(attrs={'rows':8, 'cols':70}))
+    author = forms.ModelChoiceField(label=_("Commit author"), empty_label=None,
+        queryset=Person.objects.none(), required=False)
     file = forms.FileField(label=_("File"), required=False,
                            help_text=_("Upload a .po, .gz, .bz2 or .png file"))
     send_to_ml = forms.BooleanField(label=_("Send message to the team mailing list"), required=False)
 
-    def __init__(self, actions, has_mailing_list, *args, **kwargs):
+    def __init__(self, state, actions, has_mailing_list, *args, **kwargs):
         super(ActionForm, self).__init__(*args, **kwargs)
         self.actions = actions
         self.fields['action'].choices = [
             (act.name, act.description) for act in actions
         ]
         self.fields['action'].help_link = reverse('help', args=['vertimus_workflow'])
+        if state and ActionCI in map(type, self.actions):
+            self.fields['author'].queryset = state.involved_persons()
+            self.fields['author'].required = True
+            self.fields['author'].initial = state.get_latest_po_file_action().person
         if not has_mailing_list:
             del self.fields['send_to_ml']
 
diff --git a/vertimus/models.py b/vertimus/models.py
index 5526d96..4a47388 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -121,6 +121,18 @@ class State(models.Model):
             sequence = query[0]['sequence']
         return sequence
 
+    def involved_persons(self):
+        """
+        Return all persons having posted any action on the current state.
+        """
+        return Person.objects.filter(action__state_db=self).distinct()
+
+    def get_latest_po_file_action(self):
+        try:
+            return Action.objects.filter(file__endswith=".po", state_db=self).latest('id')
+        except Action.DoesNotExist:
+            return None
+
 
 class StateNone(State):
     name = 'None'
@@ -208,7 +220,8 @@ class StateProofread(State):
             action_names = ['TC', 'RP', 'TR']
         else:
             action_names = []
-        if not self.branch.is_vcs_readonly() and person.is_committer(self.language.team):
+        if (not self.branch.is_vcs_readonly() and person.is_committer(self.language.team)
+                and self.get_latest_po_file_action() is not None):
             action_names.insert(1, 'CI')
 
         return self._get_available_actions(person, action_names)
@@ -239,7 +252,7 @@ class StateToCommit(State):
     def get_available_actions(self, person):
         if person.is_committer(self.language.team):
             action_names = ['RC', 'TR']
-            if not self.branch.is_vcs_readonly():
+            if not self.branch.is_vcs_readonly() and self.get_latest_po_file_action() is not None:
                 action_names.insert(1, 'CI')
         else:
             action_names = []
@@ -413,7 +426,7 @@ class Action(ActionAbstract):
             self.created = datetime.today()
         super(Action, self).save(*args, **kwargs)
 
-    def apply_on(self, state, send_to_ml):
+    def apply_on(self, state, form_data):
         if not self in state.get_available_actions(self.person):
             raise Exception('Not allowed')
         self.state_db = state
@@ -430,9 +443,9 @@ class Action(ActionAbstract):
         if self.target_state == StateCommitted:
             # Committed is the last state of the workflow, archive actions
             arch_action = self.new_by_name('AA', person=self.person)
-            arch_action.apply_on(self.state_db, False)
+            arch_action.apply_on(self.state_db, {})
 
-        if send_to_ml:
+        if form_data.get('send_to_ml'):
             self.send_mail_new_state(state, (state.language.team.mailing_list,))
 
     def get_previous_action_with_po(self):
@@ -547,16 +560,14 @@ class ActionWC(Action):
     class Meta:
         proxy = True
 
-    def apply_on(self, state, send_to_ml):
-        super(ActionWC, self).apply_on(state, False)
+    def apply_on(self, state, form_data):
+        super(ActionWC, self).apply_on(state, {})
 
-        if send_to_ml:
+        if form_data.get('send_to_ml'):
             recipients = (state.language.team.mailing_list,)
         else:
             # Send an email to all translators of the page
-            translator_emails = set()
-            for d in Person.objects.filter(action__state_db=state).values('email'):
-                translator_emails.add(d['email'])
+            translator_emails = set(state.involved_persons().values_list('email', flat=True))
             # Remove None items from the list
             recipients = filter(lambda x: x is not None, translator_emails)
 
@@ -605,8 +616,8 @@ class ActionTC(Action):
     class Meta:
         proxy = True
 
-    def apply_on(self, state, send_to_ml):
-        super(ActionTC, self).apply_on(state, send_to_ml)
+    def apply_on(self, state, form_data):
+        super(ActionTC, self).apply_on(state, form_data)
         # Send an email to all committers of the team
         committers = [c.email for c in state.language.team.get_committers()]
         self.send_mail_new_state(state, committers)
@@ -619,16 +630,16 @@ class ActionCI(Action):
     class Meta:
         proxy = True
 
-    def apply_on(self, state, send_to_ml):
+    def apply_on(self, state, form_data):
         self.state_db = state
         action_with_po = self.get_previous_action_with_po()
         try:
-            state.branch.commit_po(action_with_po.file.path, state.domain, state.language, self.person)
+            state.branch.commit_po(action_with_po.file.path, state.domain, state.language, 
form_data['author'].as_author())
         except:
             # Commit failed, state unchanged
             raise Exception(_("The commit failed. The error was: '%s'") % sys.exc_info()[1])
 
-        super(ActionCI, self).apply_on(state, send_to_ml) # Mail sent in super
+        super(ActionCI, self).apply_on(state, form_data) # Mail sent in super
 
 class ActionRC(Action):
     name = 'RC'
@@ -662,8 +673,8 @@ class ActionAA(Action):
     class Meta:
         proxy = True
 
-    def apply_on(self, state, send_to_ml):
-        super(ActionAA, self).apply_on(state, send_to_ml)
+    def apply_on(self, state, form_data):
+        super(ActionAA, self).apply_on(state, form_data)
         all_actions = Action.objects.filter(state_db=state).order_by('id').all()
 
         sequence = None
@@ -700,7 +711,7 @@ class ActionUNDO(Action):
     class Meta:
         proxy = True
 
-    def apply_on(self, state, send_to_ml):
+    def apply_on(self, state, form_data):
         self.state_db = state
         self.save()
 
@@ -719,7 +730,7 @@ class ActionUNDO(Action):
             state.change_state(action.target_state, action.person)
             return
         state.change_state(StateNone)
-        if send_to_ml:
+        if form_data.get('send_to_ml'):
             self.send_mail_new_state(state, (state.language.team.mailing_list,))
 
 class ActionSeparator(object):
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index 16f08af..fd1220b 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -41,8 +41,8 @@ class VertimusTest(TeamsAndRolesTests):
         self.m = Module.objects.create(name='gedit', description='GNOME Editor',
             bugs_base="https://bugzilla.gnome.org/";,
             bugs_product='gedit', bugs_component='general',
-            vcs_type='svn', vcs_root="http://svn.gnome.org/svn";,
-            vcs_web="http://svn.gnome.org/viewvc/gedit";)
+            vcs_type='git', vcs_root="git://git.gnome.org/gedit",
+            vcs_web="http://git.gnome.org/browse/gedit/";)
 
         Branch.checkout_on_creation = False
         self.b = Branch(name='gnome-2-24', module=self.m)
@@ -198,18 +198,18 @@ class VertimusTest(TeamsAndRolesTests):
         prev_updated = state.updated
 
         action = Action.new_by_name('WC', person=self.pt, comment="Hi!")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
         self.assertEqual(len(mail.outbox), 1)
         self.assertEqual(mail.outbox[0].recipients(), [self.pt.email])
         # Test that submitting a comment without text generates a validation error
-        form = ActionForm([ActionWC()], True, QueryDict('action=WC&comment='))
+        form = ActionForm(state, [ActionWC()], True, QueryDict('action=WC&comment='))
         self.assertTrue("A comment is needed" in str(form.errors))
         self.assertNotEqual(state.updated, prev_updated)
 
         # Test send comment to mailing list
         mail.outbox = []
         action = Action.new_by_name('WC', person=self.pt, comment="Hi again!")
-        action.apply_on(state, True)
+        action.apply_on(state, {'send_to_ml': True})
         self.assertEqual(len(mail.outbox), 1)
         self.assertEqual(mail.outbox[0].recipients(), [self.l.team.mailing_list])
         self.assertIn(u"Hi again!", mail.outbox[0].body)
@@ -219,7 +219,7 @@ class VertimusTest(TeamsAndRolesTests):
         state.save()
 
         action = Action.new_by_name('RT', person=self.pt, comment="Reserved!")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
         self.assertTrue(isinstance(state, StateTranslating))
 
     @test_scratchdir
@@ -235,7 +235,7 @@ class VertimusTest(TeamsAndRolesTests):
         test_file = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "valid_po.po"), 'r')
 
         action = Action.new_by_name('UT', person=self.pt, comment="Done by translator.", 
file=File(test_file))
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         self.assertEqual(action.file.url, '/media/upload/gedit-gnome-2-24-po-fr-%d.po' % state.id)
         self.assertEqual(action.merged_file.url(), '/media/upload/gedit-gnome-2-24-po-fr-%d.merged.po' % 
state.id)
@@ -257,7 +257,7 @@ class VertimusTest(TeamsAndRolesTests):
         state.save()
 
         action = Action.new_by_name('RP', person=self.pr, comment="Reserved by a reviewer!")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
         self.assertTrue(isinstance(state, StateProofreading))
 
     def test_action_up(self):
@@ -268,7 +268,7 @@ class VertimusTest(TeamsAndRolesTests):
         test_file.name = 'mytestfile.po'
 
         action = Action.new_by_name('UP', person=self.pr, comment="Done.", file=test_file)
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
         self.files_to_clean.append(action.file.path)
         self.assertTrue(isinstance(state, StateProofread))
 
@@ -277,7 +277,7 @@ class VertimusTest(TeamsAndRolesTests):
         state.save()
 
         action = Action.new_by_name('TC', person=self.pr, comment="Ready!")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
         self.assertTrue(isinstance(state, StateToCommit))
 
     def test_action_rc(self):
@@ -285,9 +285,33 @@ class VertimusTest(TeamsAndRolesTests):
         state.save()
 
         action = Action.new_by_name('RC', person=self.pc, comment="This work is mine!")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
         self.assertTrue(isinstance(state, StateCommitting))
 
+    def test_action_ci(self):
+        self.b.module.vcs_root = self.b.module.vcs_root.replace('git://', 'ssh://')
+        self.b.module.save()
+        state = StateProofreading(branch=self.b, domain=self.d, language=self.l, person=self.pr)
+        state.save()
+
+        action = Action.new_by_name('WC', person=self.pt, comment="Hi!")
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
+
+        test_file = ContentFile('test content')
+        test_file.name = 'mytestfile.po'
+        action = Action.new_by_name('UP', person=self.pr, comment="Done.", file=test_file)
+        action.apply_on(state, {})
+
+        self.assertIn(ActionCI, map(type, state.get_available_actions(self.pcoo)))
+
+        form = ActionForm(state, state.get_available_actions(self.pcoo), True)
+        self.assertEqual(len(form.fields['author'].choices), 2)
+        choices = list(form.fields['author'].choices)
+        self.assertListEqual(
+            [choices[0][1], choices[1][1]],
+            ['John Reviewer', 'John Translator'])
+        self.assertEqual(form.fields['author'].initial, self.pr)
+
     def test_action_ic(self):
         state = StateProofreading(branch=self.b, domain=self.d, language=self.l, person=self.pr)
         state.save()
@@ -297,7 +321,7 @@ class VertimusTest(TeamsAndRolesTests):
         test_file.name = 'mytestfile.po'
 
         action = Action.new_by_name('UP', person=self.pr, comment="Done.", file=test_file)
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
         self.assertEqual(len(mail.outbox), 1) # Mail sent to mailing list
         mail.outbox = []
 
@@ -305,15 +329,15 @@ class VertimusTest(TeamsAndRolesTests):
         self.assertTrue(os.access(file_path, os.W_OK))
 
         action = Action.new_by_name('TC', person=self.pc, comment="To commit.")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
         self.assertEqual(len(mail.outbox), 1) # Mail sent to committers
         mail.outbox = []
 
         action = Action.new_by_name('RC', person=self.pc, comment="Reserved commit.")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('IC', person=self.pc, comment="Committed.")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
         # Mail sent to mailing list
         self.assertEqual(len(mail.outbox), 1)
         self.assertEqual(mail.outbox[0].recipients(), [self.l.team.mailing_list])
@@ -334,7 +358,7 @@ class VertimusTest(TeamsAndRolesTests):
         state.save()
 
         action = Action.new_by_name('TR', person=self.pc, comment="Bad work :-/")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
         self.assertTrue(isinstance(state, StateToReview))
 
     def test_action_aa(self):
@@ -342,7 +366,7 @@ class VertimusTest(TeamsAndRolesTests):
         state.save()
 
         action = Action.new_by_name('AA', person=self.pc, comment="I don't want to disappear :)")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         state = State.objects.get(branch=self.b, domain=self.d, language=self.l)
         self.assertTrue(isinstance(state, StateNone))
@@ -353,38 +377,38 @@ class VertimusTest(TeamsAndRolesTests):
         state.save()
 
         action = Action.new_by_name('RT', person=self.pt, comment="Reserved!")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('UNDO', person=self.pt, comment="Ooops! I don't want to do that. Sorry.")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         self.assertEqual(state.name, 'None')
 
         action = Action.new_by_name('RT', person=self.pt, comment="Translating")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('UT', person=self.pt, comment="Translated")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('RT', person=self.pt, comment="Reserved!")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('UNDO', person=self.pt, comment="Ooops! I don't want to do that. Sorry.")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         self.assertEqual(state.name, 'Translated')
 
         action = Action.new_by_name('RT', person=self.pt, comment="Translating 1")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('UNDO', person=self.pt, comment="Undo 1")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('RT', person=self.pt, comment="Translating 2")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('UNDO', person=self.pt, comment="Undo 2")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         self.assertEqual(state.name, 'Translated')
 
@@ -394,7 +418,7 @@ class VertimusTest(TeamsAndRolesTests):
         state.save()
 
         action = Action.new_by_name('WC', person=self.pt, comment="Hi!")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         self.m.delete()
         self.assertEqual(Action.objects.all().count(), 0)
@@ -424,18 +448,18 @@ class VertimusTest(TeamsAndRolesTests):
         # Test a non valid po file
         post_content = QueryDict('action=WC&comment=Test1')
         post_file = MultiValueDict({'file': [SimpleUploadedFile('filename.po', 'Not valid po file 
content')]})
-        form = ActionForm([ActionWC()], True, post_content, post_file)
+        form = ActionForm(None, [ActionWC()], True, post_content, post_file)
 
         self.assertTrue('file' in form.errors)
 
         # Test a valid po file
         f = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "valid_po.po"), 'r')
         post_file = MultiValueDict({'file': [File(f)]})
-        form = ActionForm([ActionWC()], True, post_content, post_file)
+        form = ActionForm(None, [ActionWC()], True, post_content, post_file)
         self.assertTrue(form.is_valid())
 
         # Test form without file
-        form = ActionForm([ActionWC()], True, post_content)
+        form = ActionForm(None, [ActionWC()], True, post_content)
         self.assertTrue(form.is_valid())
 
     def test_feeds(self):
@@ -443,7 +467,7 @@ class VertimusTest(TeamsAndRolesTests):
         state.save()
 
         action = Action.new_by_name('RT', person=self.pt, comment="Translating")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         response = self.client.get(reverse('lang_feed', args=[self.l.locale]))
         self.assertContains(response,
@@ -472,22 +496,22 @@ class VertimusTest(TeamsAndRolesTests):
         state.save()
 
         action = Action.new_by_name('RT', person=self.pr, comment="Reserved!")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('UNDO', person=self.pr, comment="Ooops! I don't want to do that. Sorry.")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('RT', person=self.pr, comment="Translating")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('UT', person=self.pr, comment="Translated")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('RP', person=self.pr, comment="Proofreading")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         action = Action.new_by_name('UNDO', person=self.pr, comment="Ooops! I don't want to do that. Sorry.")
-        action.apply_on(state, action.send_mail_to_ml)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
         actions_db = Action.objects.filter(state_db__id=state.id).exclude(name='WC').order_by('-id')
 
diff --git a/vertimus/views.py b/vertimus/views.py
index 54e963b..add6779 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -96,7 +96,7 @@ def vertimus(request, branch, domain, language, stats=None, level="0"):
         has_ml = language.team and bool(language.team.mailing_list) or False
         if request.method == 'POST':
             action_form = ActionForm(
-                available_actions, has_ml, request.POST, request.FILES)
+                state, available_actions, has_ml, request.POST, request.FILES)
 
             if action_form.is_valid():
                 # Process the data in form.cleaned_data
@@ -106,7 +106,7 @@ def vertimus(request, branch, domain, language, stats=None, level="0"):
                 action = Action.new_by_name(action, person=person, comment=comment,
                     file=request.FILES.get('file', None))
                 try:
-                    action.apply_on(state, action_form.cleaned_data.get('send_to_ml'))
+                    action.apply_on(state, action_form.cleaned_data)
                 except SendMailFailed:
                     messages.error(request,
                         _("A problem occurred while sending mail, no mail have been sent"))
@@ -119,7 +119,7 @@ def vertimus(request, branch, domain, language, stats=None, level="0"):
                         args=(branch.module.name, branch.name, domain.name,
                               language.locale)))
         else:
-            action_form = ActionForm(available_actions, has_ml)
+            action_form = ActionForm(state, available_actions, has_ml)
     else:
         action_form = None
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]