[damned-lies] Prevent commit authors without email address



commit e5060a7c432ba898abd605b21d4edc088e8cd0b8
Author: Claude Paroz <claude 2xlibre net>
Date:   Tue Apr 19 08:52:41 2016 +0200

    Prevent commit authors without email address

 vertimus/forms.py       |   18 ++++++++++--------
 vertimus/tests/tests.py |   31 ++++++++++++++++++++++---------
 2 files changed, 32 insertions(+), 17 deletions(-)
---
diff --git a/vertimus/forms.py b/vertimus/forms.py
index 70b36f3..fa36050 100644
--- a/vertimus/forms.py
+++ b/vertimus/forms.py
@@ -23,7 +23,6 @@ import os
 from django import forms
 from django.core.urlresolvers import reverse
 from django.utils.html import format_html
-from django.utils.safestring import mark_safe
 from django.utils.translation import ugettext, ugettext_lazy as _
 from vertimus.models import Action, ActionCI
 from stats.models import Person
@@ -42,18 +41,21 @@ class ActionWidget(forms.Select):
 
 
 class AuthorWidget(forms.Select):
-    """ Custom widget to disable people without full name """
+    """ Custom widget to disable people without full name or email """
     def render_options(self, choices, selected_choices):
         output = ["<option value=\"\">--------</option>"]
         field = self.choices.field
-        for obj in field.queryset.all():
-            val, label = field.prepare_value(obj), field.label_from_instance(obj)
+        for pers in field.queryset.all():
+            val, label = field.prepare_value(pers), field.label_from_instance(pers)
             selected_html = ''
-            if label == obj.username:
-                selected_html = mark_safe(' disabled="disabled"')
-                label += ugettext(" (full name missing)")
+            if label == pers.username:
+                selected_html = ' disabled'
+                label = ugettext("%(name)s (full name missing)") % {'name': label}
+            elif not pers.email:
+                selected_html = ' disabled'
+                label = ugettext("%(name)s (email missing)") % {'name': label}
             elif val in selected_choices:
-                selected_html = mark_safe(' selected="selected"')
+                selected_html = ' selected'
             output.append(format_html(u'<option value="{0}"{1}>{2}</option>',
                 val, selected_html, label))
         return '\n'.join(output)
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index ecae0ab..4e01e35 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -357,8 +357,12 @@ class VertimusTest(TeamsAndRolesTests):
 
         action = Action.new_by_name('WC', person=self.pt)
         action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Hi!"})
-        p3 = Person.objects.create(username=u'ûsername')
-        action = Action.new_by_name('WC', person=p3)
+        # Adding users with incomplete profiles
+        pers_no_full_name = Person.objects.create(username=u'ûsername')
+        action = Action.new_by_name('WC', person=pers_no_full_name)
+        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Hello!"})
+        pers_no_email = Person.objects.create(username=u'noemail', first_name="Sven", last_name="Brkc")
+        action = Action.new_by_name('WC', person=pers_no_email)
         action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Hello!"})
 
         self.upload_file(state, 'UP')
@@ -366,17 +370,26 @@ class VertimusTest(TeamsAndRolesTests):
         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), 3)
+        self.assertEqual(len(form.fields['author'].choices), 4)
         choices = list(form.fields['author'].choices)
-        self.assertListEqual(
+        self.assertEqual(
             [choices[0][1], choices[1][1]],
-            ['John Reviewer', 'John Translator'])
+            ['John Reviewer', 'John Translator']
+        )
         self.assertEqual(form.fields['author'].initial, self.pr)
         rendered_form = form.as_p()
-        self.assertIn(u'<option value="%d" disabled="disabled">ûsername (full name missing)</option>' % 
p3.pk,
-                      rendered_form)
-        self.assertIn('<option value="%d">John Translator</option>' % self.pt.pk,
-                      rendered_form)
+        self.assertIn(
+            u'<option value="%d" disabled>ûsername (full name missing)</option>' % pers_no_full_name.pk,
+            rendered_form
+        )
+        self.assertIn(
+            '<option value="%d" disabled>Sven Brkc (email missing)</option>' % pers_no_email.pk,
+            rendered_form
+        )
+        self.assertIn(
+            '<option value="%d">John Translator</option>' % self.pt.pk,
+            rendered_form
+        )
 
     def test_action_ci_no_fullname(self):
         """


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