[damned-lies] Add variable check in role form



commit 573c7be62f7f6bec62bcb7658ce87d789980e73e
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu May 4 22:45:24 2017 +0200

    Add variable check in role form

 teams/forms.py |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/teams/forms.py b/teams/forms.py
index 46c3df8..c2a4aa4 100644
--- a/teams/forms.py
+++ b/teams/forms.py
@@ -57,16 +57,18 @@ class EditMemberRoleForm(forms.Form):
 
     def __init__(self, roles, *args, **kwargs):
         super().__init__(*args, **kwargs)
-        choices = list(filter(lambda x:x[0]!='coordinator', ROLE_CHOICES))
-        choices.append(('inactivate', _("Mark as Inactive")))
-        choices.append(('remove', _("Remove From Team")))
+        choices = [x for x in ROLE_CHOICES if x[0] != 'coordinator']
+        choices.extend([
+            ('inactivate', _("Mark as Inactive")),
+            ('remove', _("Remove From Team"))
+        ])
         for role in roles:
             self.fields[str(role.pk)] = forms.ChoiceField(
                 choices=choices,
-                label = "<a href='%s'>%s</a>" % (role.person.get_absolute_url(), role.person.name),
+                label='<a href="%s">%s</a>' % (role.person.get_absolute_url(), role.person.name),
                 initial=role.role)
-        self.fields['form_type'] = forms.CharField(widget=forms.HiddenInput,
-                                                   initial=roles[0].role)
+        if roles:
+            self.fields['form_type'] = forms.CharField(widget=forms.HiddenInput, initial=roles[0].role)
 
     def get_fields(self):
         for key, field in self.fields.items():


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