[damned-lies] Add checkbox with option to cherry-pick commit to master branch



commit 6b433003910e2aa629fc3ab290f2baa453387183
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Oct 17 16:49:45 2015 +0200

    Add checkbox with option to cherry-pick commit to master branch
    
    Fixes bug #726786.

 stats/templatetags/stats_extras.py      |   12 ++++++++++++
 templates/vertimus/vertimus_detail.html |    8 ++++++--
 vertimus/forms.py                       |    6 ++++++
 vertimus/models.py                      |    5 +++--
 4 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py
index 81711da..cf66c4e 100644
--- a/stats/templatetags/stats_extras.py
+++ b/stats/templatetags/stats_extras.py
@@ -1,9 +1,12 @@
 # -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
 import re
 
 from django import template
 from django.conf import settings
 from django.utils.encoding import force_text
+from django.utils.html import format_html
 from django.utils.safestring import mark_safe
 from django.utils.translation import get_language_bidi
 
@@ -235,6 +238,15 @@ def as_tr(field):
         field.name, field.label_tag(), errors_html, field.as_widget(), help_link, help_html)
     )
 
+ register filter
+def as_tr_cb(field):
+    label = field.label
+    if field.help_text:
+        label = mark_safe('%s <span class="help">(%s)</span>' % (label, field.help_text))
+    return format_html(
+        '<tr class="tr_{}"><td></td><td>{} <label for="id_{}">{}</label></td></tr>',
+        field.name, field.as_widget(), field.name, label
+    )
 
 @register.filter
 def bugzilla_linkify(text):
diff --git a/templates/vertimus/vertimus_detail.html b/templates/vertimus/vertimus_detail.html
index 44d9409..ebbb9f8 100644
--- a/templates/vertimus/vertimus_detail.html
+++ b/templates/vertimus/vertimus_detail.html
@@ -7,7 +7,7 @@
 
 {% block extrahead %}
 <style type="text/css">
-tr.tr_author { display: none; }
+tr.tr_author, tr.tr_sync_master { display: none; }
 </style>
 <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.growfield2.js"></script>
 <script type="text/javascript">
@@ -18,6 +18,7 @@ $(document).ready(function() {
       $("#id_action").change(function () {
         $("#id_send_to_ml").attr('checked', send_mail_defaults[$(this).val()]);
         $("tr.tr_author").toggle(this.value == 'CI');
+        $("tr.tr_sync_master").toggle(this.value == 'CI');
         $("tr.tr_file").toggle(this.value != 'CI');
       });
     }
@@ -241,10 +242,13 @@ $(document).ready(function() {
     <table>
       {{ action_form.action|as_tr }}
       {{ action_form.author|as_tr }}
+      {% if action_form.sync_master %}
+        {{ action_form.sync_master|as_tr_cb }}
+      {% endif %}
       {{ action_form.comment|as_tr }}
       {{ action_form.file|as_tr }}
       {% if action_form.send_to_ml %}
-      <tr><td></td><td>{{ action_form.send_to_ml }} <label for="id_send_to_ml">{{ 
action_form.send_to_ml.label }}</label></td></tr>
+        {{ action_form.send_to_ml|as_tr_cb }}
       {% endif %}
       <tr>
         <td></td>
diff --git a/vertimus/forms.py b/vertimus/forms.py
index fc8a6b0..f031573 100644
--- a/vertimus/forms.py
+++ b/vertimus/forms.py
@@ -71,6 +71,10 @@ class ActionForm(forms.Form):
         widget=forms.Textarea(attrs={'rows':8, 'cols':70}))
     author = forms.ModelChoiceField(label=_("Commit author"), empty_label=None,
         queryset=Person.objects.none(), widget=AuthorWidget, required=False)
+    sync_master = forms.BooleanField(
+        label=_("Sync with master"),
+        help_text=_("Try to cherry-pick the commit to the master branch"),
+        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)
@@ -87,6 +91,8 @@ class ActionForm(forms.Form):
             self.fields['author'].initial = state.get_latest_po_file_action().person
         if not has_mailing_list:
             del self.fields['send_to_ml']
+        if state.branch.is_head():
+            del self.fields['sync_master']
 
     def clean_file(self):
         data = self.cleaned_data['file']
diff --git a/vertimus/models.py b/vertimus/models.py
index a18299e..924c5fb 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -640,9 +640,10 @@ class ActionCI(Action):
         action_with_po = self.get_previous_action_with_po()
         try:
             author = form_data['author'].as_author() if form_data['author'] else None
+            sync = form_data.get('sync_master', False)
             state.branch.commit_po(
-                action_with_po.file.path, state.domain, state.language, author)
-        except:
+                action_with_po.file.path, state.domain, state.language, author, sync_master=sync)
+        except Exception:
             # Commit failed, state unchanged
             raise Exception(_("The commit failed. The error was: '%s'") % sys.exc_info()[1])
 


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