damned-lies r1428 - in trunk: . media/css people templates/people



Author: stephaner
Date: Tue Feb  3 22:35:02 2009
New Revision: 1428
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1428&view=rev

Log:
2009-02-03  StÃphane Raimbault  <stephane raimbault gmail com>

	Patch made with Claude to fix #570247.
	
	* media/css/layout.css: New 'inline' class to avoid style tag in
 	HTML code.
	* people/urls.py: New team_leave view (GET).
	* people/views.py: Messages are passed by the message_set
	relation (the old message still present in templates/base.html for
	stats). New person_team_leave() function. Extract RequestContext()
	call from render_to_response to avoid the get and delete of
	messages in manual commit context.
	* templates/people/person_base.html: Use new on_own_page
	boolean.
	* templates/people/person_detail.html: Use new on_own_page
	boolean. Indent.
	* templates/people/person_team_join_form.html: Removed useless
	hidden.
	* templates/people/person_team_membership.html: Change the string
	"Team membership" incorrect in this context. Add a javascript
	action to confirm the leaving (FIXME the message doesn't seem to
	be translated).	


Modified:
   trunk/ChangeLog
   trunk/media/css/layout.css
   trunk/people/urls.py
   trunk/people/views.py
   trunk/templates/people/person_base.html
   trunk/templates/people/person_detail.html
   trunk/templates/people/person_team_join_form.html
   trunk/templates/people/person_team_membership.html

Modified: trunk/media/css/layout.css
==============================================================================
--- trunk/media/css/layout.css	(original)
+++ trunk/media/css/layout.css	Tue Feb  3 22:35:02 2009
@@ -61,6 +61,10 @@
   text-align: center;
 }
 
+.inline {
+  display: inline;
+}
+
 /* Common page elements: Header, footer, etc. */
 
 #logo {

Modified: trunk/people/urls.py
==============================================================================
--- trunk/people/urls.py	(original)
+++ trunk/people/urls.py	Tue Feb  3 22:35:02 2009
@@ -15,6 +15,7 @@
     url(r'^detail_change/$', 'person_detail_change', name='person-detail-change-view'),
     url(r'^password_change/$', 'person_password_change', name='person-password-change-view'),
     url(r'^team_join/$', 'person_team_join', name='person-team-join-view'),
+    url(r'^team_leave/(?P<team_slug>[\w\- ]+)/$', 'person_team_leave', name='person-team-leave-view'),
     url(r'^(?P<person_id>\d+)/$', 'person_detail', name='person-id-view'),
     # equivalent to the previous, but using username instead of user pk
     url(r'^(?P<person_username>[\w \ \-]+)/$', 'person_detail', name='person-username-view'),

Modified: trunk/people/views.py
==============================================================================
--- trunk/people/views.py	(original)
+++ trunk/people/views.py	Tue Feb  3 22:35:02 2009
@@ -18,6 +18,8 @@
 # along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from django.core import urlresolvers
+from django.http import HttpResponseRedirect
 from django.shortcuts import render_to_response, get_object_or_404
 from django.utils.translation import ugettext as _, get_date_formats
 from django.template import RequestContext
@@ -25,7 +27,7 @@
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.forms import PasswordChangeForm
 from people.models import Person
-from teams.models import Role
+from teams.models import Team, Role
 from people.forms import TeamJoinForm, DetailForm
 from vertimus.models import StateDb
 
@@ -39,6 +41,7 @@
     context = {
         'pageSection': "teams",
         'person': person,
+        'on_own_page': request.user.is_authenticated() and person.username == request.user.username,
         'states': states,
         'dateformat': get_date_formats()[0],
     }
@@ -49,21 +52,20 @@
 def person_detail_change(request):
     """Handle the form to change the details"""
     person = get_object_or_404(Person, username=request.user.username)
-    messages = []
     if request.method == 'POST':
         form = DetailForm(request.POST, instance=person)
         if form.is_valid():
             form.save()
         else:
-            messages.append("Sorry, the form is not valid.")
+            request.user.message_set.create(message="Sorry, the form is not valid.")
     else:
         form = DetailForm(instance=person)
 
     context = {
         'pageSection': "teams",
         'person': person,
+        'on_own_page': person.username == request.user.username,
         'form': form,
-        'messages': messages
     }
     return render_to_response('people/person_detail_change_form.html', context,
             context_instance=RequestContext(request))
@@ -73,41 +75,57 @@
 def person_team_join(request):
     """Handle the form to join a team"""
     person = get_object_or_404(Person, username=request.user.username)
-    messages = []
     if request.method == 'POST':
         form = TeamJoinForm(request.POST)
         if form.is_valid():
             team = form.cleaned_data['teams']
-            new_role = Role(team=team, person=person) # role default to translator
+            # Role default to 'translator'
+            new_role = Role(team=team, person=person)
             try:
                 new_role.save()
-                transaction.commit()
+                request.user.message_set.create(message=_("You have successfully joined the team '%s'.") % team.get_description())
             except IntegrityError:
                 transaction.rollback()
-                messages.append(_("You are already member of this team."))
+                request.user.message_set.create(message=_("You are already member of this team."))
     else:
         form = TeamJoinForm()
 
     context = {
         'pageSection': "teams",
         'person': person,
+        'on_own_page': person.username == request.user.username,
         'form': form,
-        'messages': messages
     }
+
+    context_instance = RequestContext(request)
+    transaction.commit()
     return render_to_response('people/person_team_join_form.html', context, 
-            context_instance=RequestContext(request))
+            context_instance=context_instance)
 
+ login_required
+def person_team_leave(request, team_slug):
+    person = get_object_or_404(Person, username=request.user.username)
+    team = get_object_or_404(Team, name=team_slug)
+    try:
+        role = Role.objects.get(team=team, person=person)
+        role.delete()
+        person.message_set.create(message=_("You have been removed from the team '%s'.") % team.get_description())
+    except Role.DoesNotExist:
+        # Message no i18n'ed, should never happen under normal conditions
+        person.message_set.create(message="You are not a member of this team.")
+    # redirect to normal person detail
+    return HttpResponseRedirect(urlresolvers.reverse('person-username-view', 
+                                                     args=(person.username,)))
 
 @login_required
 def person_password_change(request):
     """Handle the generic form to change the password"""
     person = get_object_or_404(Person, username=request.user.username)
-    messages = []
 
     if request.method == 'POST':
         form = PasswordChangeForm(request.user, request.POST)
         if form.is_valid():
-            messages.append(_("Your password has been changed."))
+            request.user.message_set.create(message=_("Your password has been changed."))
             form.save()
     else:
         form = PasswordChangeForm(request.user)
@@ -115,8 +133,8 @@
     context = {
         'pageSection': "teams",
         'person': person,
+        'on_own_page': person.username == request.user.username,
         'form': form,
-        'messages': messages
     }
     return render_to_response('people/person_password_change_form.html', context,
             context_instance=RequestContext(request))

Modified: trunk/templates/people/person_base.html
==============================================================================
--- trunk/templates/people/person_base.html	(original)
+++ trunk/templates/people/person_base.html	Tue Feb  3 22:35:02 2009
@@ -6,8 +6,7 @@
 
 {% block content %}
 <div class="mainpage">
-  {% if user.is_authenticated %}
-  {% ifequal user.username person.username %}
+  {% if on_own_page %}
   <div class="right_actions">
     <ul>
       <li><a href="{% url person-detail-change-view %}">{% trans "Change your details" %}</a></li>
@@ -15,7 +14,6 @@
       <li><a href="{% url person-team-join-view %}">{% trans "Join a team" %}</a></li>
     </ul>
   </div>
-  {% endifequal %}
   {% endif %}
 
   {% include "people/person_overview.html" %}

Modified: trunk/templates/people/person_detail.html
==============================================================================
--- trunk/templates/people/person_detail.html	(original)
+++ trunk/templates/people/person_detail.html	Tue Feb  3 22:35:02 2009
@@ -16,30 +16,31 @@
 {% endblock %}
 
 {% block subcontent %}
-{% if user.is_authenticated %}
-{% ifequal user.username person.username %}
+{% if on_own_page %}
   <br clear="right" />
   <div style="float:right; text-align:right;">
-  <form action="/i18n/setlang/" method="post">
-  {% trans "Site Language:" %} <select name="language">
-  {% for lang in LANGUAGES %}
-    {% ifequal lang.0 LANGUAGE_CODE %}
-    <option value="{{ lang.0 }}" selected="selected">{% trans  lang.1 %}</option>
-    {% else %}
-    <option value="{{ lang.0 }}" >{% trans lang.1 %}</option>
-    {% endifequal %}
-  {% endfor %}
-  </select><br />
-  <input type="submit" value="{% trans "Choose" %}" />
-  </form></div>
-{% endifequal %}
+    <form action="/i18n/setlang/" method="post">
+      {% trans "Site Language:" %}
+      <select name="language">
+      {% for lang in LANGUAGES %}
+        {% ifequal lang.0 LANGUAGE_CODE %}
+        <option value="{{ lang.0 }}" selected="selected">{% trans lang.1 %}</option>
+        {% else %}
+        <option value="{{ lang.0 }}" >{% trans lang.1 %}</option>
+        {% endifequal %}
+      {% endfor %}
+      </select>
+      <br/>
+      <input type="submit" value="{% trans "Choose" %}" />
+    </form>
+  </div>
 {% endif %}
 
 {% if person.maintains_modules.all %}
 <h2>{% trans "Maintains:" %}</h2>
 <ul>
   {% for module in person.maintains_modules.all %}
-  <li><a href="{{ module.get_absolute_url }} ">{{ module.description }}</a></li>
+  <li><a href="{{ module.get_absolute_url }}">{{ module.description }}</a></li>
   {% endfor %}
 </ul>
 {% endif %}
@@ -63,7 +64,6 @@
 {% endfor %}
 </tbody>
 </table>
-
 {% endif %}
 
 {% endblock %}

Modified: trunk/templates/people/person_team_join_form.html
==============================================================================
--- trunk/templates/people/person_team_join_form.html	(original)
+++ trunk/templates/people/person_team_join_form.html	Tue Feb  3 22:35:02 2009
@@ -11,7 +11,6 @@
   <p><em>{% trans "I would like to join the following team as 'translator':" %}</em><br />
     {{ form.teams }}
     <input type="submit" value="{% trans "Join" %}">
-    <input type="hidden" name="join_team_form" value="1" />
 </form>
 
 {% endblock %}

Modified: trunk/templates/people/person_team_membership.html
==============================================================================
--- trunk/templates/people/person_team_membership.html	(original)
+++ trunk/templates/people/person_team_membership.html	Tue Feb  3 22:35:02 2009
@@ -2,11 +2,17 @@
 {% load stats_extras %}
 
 {% if person.role_set.all %}
-<h2>{% trans "Team membership" %}</h2>
+<h2>{% trans "Member of teams" %}</h2>
 <ul>
   {% for role in person.role_set.all %}
   {% with role.role as role_name %}
   <li>{% blocktrans with role.team|linked_with:role.team.get_description|safe as team_name %}Member of {{ team_name }} team ({{ role_name }}){% endblocktrans %}
+      {% if on_own_page %}
+      <form class="inline" method="GET" action="{% url person-team-leave-view role.team.name %}">
+        <input type="submit" value="{% trans "Leave" %}"
+               onClick="javascript:return confirm('{% trans "Are you sure you want to leave the team?" %}')">
+      </form>
+      {% endif %}
   </li>
   {% endwith %}
   {% endfor %}



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