[damned-lies] Allow members of ADMIN_GROUP to change team coordinator



commit d55d6c44b3f615bae4ab23af20f54f879c68a3cd
Author: Claude Paroz <claude 2xlibre net>
Date:   Mon May 9 11:14:53 2011 +0200

    Allow members of ADMIN_GROUP to change team coordinator

 media/css/main.css             |    2 +-
 settings.py                    |    2 +-
 teams/forms.py                 |   46 +++++++++++++++++++++++++++++++++++----
 teams/urls.py                  |    2 +-
 teams/views.py                 |    2 +-
 templates/teams/team_edit.html |   19 ++++++++++++----
 6 files changed, 59 insertions(+), 14 deletions(-)
---
diff --git a/media/css/main.css b/media/css/main.css
index ad5bde5..b6b2a63 100644
--- a/media/css/main.css
+++ b/media/css/main.css
@@ -321,7 +321,7 @@ div.face_image {
 
 ul.errorlist {
   list-style: none;
-  margin-left: 0;
+  margin: 0.5em 0;
   padding: 0;
 }
 
diff --git a/settings.py b/settings.py
index 1d247b7..0c1ccfc 100644
--- a/settings.py
+++ b/settings.py
@@ -140,7 +140,7 @@ INTERNAL_IPS=('127.0.0.1',)
 MESSAGE_STORAGE = 'django.contrib.messages.storage.fallback.FallbackStorage'
 LOGIN_REDIRECT_URL = '/'
 
-# Members of this group can edit all team's details
+# Members of this group can edit all team's details and change team coordinatorship
 ADMIN_GROUP = ''
 
 try:
diff --git a/teams/forms.py b/teams/forms.py
index fccbde8..8037791 100644
--- a/teams/forms.py
+++ b/teams/forms.py
@@ -1,17 +1,53 @@
 from django import forms
 from django.utils.translation import ugettext as _
-from teams.models import Team, ROLE_CHOICES
+
+from common.utils import is_site_admin
+from teams.models import Team, Role, ROLE_CHOICES
 
 class EditTeamDetailsForm(forms.ModelForm):
     class Meta:
         model = Team
         fields = ('webpage_url', 'mailing_list', 'mailing_list_subscribe', 'use_workflow', 'presentation')
+        widgets = {
+            'webpage_url':  forms.TextInput(attrs={'size': 60}),
+            'mailing_list': forms.TextInput(attrs={'size': 60}),
+            'mailing_list_subscribe': forms.TextInput(attrs={'size': 60}),
+            'presentation': forms.Textarea(attrs={'cols': 60}),
+        }
 
-    def __init__(self, *args, **kwargs):
+    def __init__(self, user, *args, **kwargs):
         super(EditTeamDetailsForm, self).__init__(*args, **kwargs)
-        for f in ('webpage_url', 'mailing_list', 'mailing_list_subscribe'):
-            self.fields[f].widget.attrs['size'] = 60
-        self.fields['presentation'].widget.attrs["cols"] = 60
+        self.user = user
+        if is_site_admin(user):
+            # Add coordinatorship dropdown
+            all_members = [(r.id, r.person.name) for r in Role.objects.select_related('person').filter(team=self.instance)]
+            all_members.insert(0, ('', '-------'))
+            try:
+                current_coord_pk = Role.objects.filter(team=self.instance, role='coordinator')[0].pk
+            except IndexError:
+                current_coord_pk = None
+            self.fields['coordinatorship'] = forms.ChoiceField(
+                label    = _("Coordinator"),
+                choices  = all_members,
+                required = False,
+                initial  = current_coord_pk
+            )
+
+    def save(self, *args, **kwargs):
+        super(EditTeamDetailsForm, self).save(*args, **kwargs)
+        if 'coordinatorship' in self.changed_data and is_site_admin(self.user):
+            # Change coordinator
+            try:
+                # Pass current coordinator as committer
+                current_coord = Role.objects.filter(team=self.instance, role='coordinator')[0]
+                current_coord.role = 'committer'
+                current_coord.save()
+            except IndexError:
+                pass
+            if self.cleaned_data['coordinatorship']:
+                new_coord = Role.objects.get(pk=self.cleaned_data['coordinatorship'])
+                new_coord.role = 'coordinator'
+                new_coord.save()
 
 class EditMemberRoleForm(forms.Form):
 
diff --git a/teams/urls.py b/teams/urls.py
index 292c130..72eabe6 100644
--- a/teams/urls.py
+++ b/teams/urls.py
@@ -16,7 +16,7 @@ urlpatterns = patterns('',
         view = 'teams.views.teams',
         name = 'teams'),
     url(
-        regex = r'^(?P<team_slug>[\w\- ]+)$',
+        regex = r'^(?P<team_slug>[\w\- ]+)/$',
         view = 'teams.views.team',
         name = 'team_slug'),
     url(
diff --git a/teams/views.py b/teams/views.py
index 8a8ac88..dfd5ea9 100644
--- a/teams/views.py
+++ b/teams/views.py
@@ -125,7 +125,7 @@ def team_edit(request, team_slug):
     team = get_object_or_404(Team, name=team_slug)
     if not (team.can_edit(request.user) or utils.is_site_admin(request.user)):
         return HttpResponseForbidden("You are not allowed to edit this team.")
-    form = EditTeamDetailsForm(request.POST or None, instance=team)
+    form = EditTeamDetailsForm(request.user, request.POST or None, instance=team)
     if request.method == 'POST':
         if form.is_valid():
             form.save()
diff --git a/templates/teams/team_edit.html b/templates/teams/team_edit.html
index 5b44542..260011d 100644
--- a/templates/teams/team_edit.html
+++ b/templates/teams/team_edit.html
@@ -17,12 +17,21 @@ $(document).ready(function() {
 
 <form action="#" method="POST">
 <table>
-  <tr><th>{{ form.webpage_url.label }}:</th><td>{{ form.webpage_url }}</td></tr>
-  <tr><th>{{ form.mailing_list.label }}:</th><td>{{ form.mailing_list }}</td></tr>
-  <tr><th>{{ form.mailing_list_subscribe.label }}:</th><td>{{ form.mailing_list_subscribe }}</td></tr>
-  <tr><th></th><td>{{ form.use_workflow }} <label for="id_use_workflow">{% trans "This team is using the Vertimus translation workflow" %}</label>
+  {% if form.coordinatorship %}
+  <tr><th>{{ form.coordinatorship.label }}:</th>
+      <td>{{ form.coordinatorship.errors}}{{ form.coordinatorship }}</td></tr>
+  {% endif %}
+  <tr><th>{{ form.webpage_url.label }}:</th>
+      <td>{{ form.webpage_url.errors}}{{ form.webpage_url }}</td></tr>
+  <tr><th>{{ form.mailing_list.label }}:</th>
+      <td>{{ form.mailing_list.errors }}{{ form.mailing_list }}</td></tr>
+  <tr><th>{{ form.mailing_list_subscribe.label }}:</th>
+      <td>{{ form.mailing_list_subscribe.errors }}{{ form.mailing_list_subscribe }}</td></tr>
+  <tr><th></th>
+      <td>{{ form.use_workflow }} <label for="id_use_workflow">{% trans "This team is using the Vertimus translation workflow" %}</label>
   <tr><th valign="top"><span class="help">&nbsp;</span><br />{{ form.presentation.label }}:</th>
-      <td><span class="help">{% trans "This content may use <a href='http://en.wikipedia.org/wiki/Markdown'>Markdown</a> syntax" %}<br />
+      <td>{{ form.presentation.label.errors }}
+          <span class="help">{% trans "This content may use <a href='http://en.wikipedia.org/wiki/Markdown'>Markdown</a> syntax" %}<br />
           {{ form.presentation }}</td></tr>
   <tr><td colspan="2" align="right"><input type="submit" value="{% trans 'Save' %}"/></td></tr>
 </table>



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