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



Author: claudep
Date: Sat Dec 20 14:39:02 2008
New Revision: 1232
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1232&view=rev

Log:
2008-12-20  Claude Paroz  <claude 2xlibre net>

	* media/css/main.css: Various CSS improvements.
	* people/forms.py: New form to edit profile.
	* templates/people/person_detail.html:
	* people/urls.py:
	* people/views.py: Add the possibility to edit personal profile from
	person_detail template.
	* people/models.py: Add translatable help_text and field names because
	they are used in profile form.
	* templates/module_detail.html: Small adjustments to adapt main.css
	changes.
	* stats/models.py: Minor fixes.

Modified:
   trunk/ChangeLog
   trunk/media/css/main.css
   trunk/people/forms.py
   trunk/people/models.py
   trunk/people/urls.py
   trunk/people/views.py
   trunk/stats/models.py
   trunk/templates/module_detail.html
   trunk/templates/people/person_detail.html

Modified: trunk/media/css/main.css
==============================================================================
--- trunk/media/css/main.css	(original)
+++ trunk/media/css/main.css	Sat Dec 20 14:39:02 2008
@@ -1,3 +1,7 @@
+table.stats {
+  width: 100%;
+}
+
 .stats th { 
     text-align: left; 
     background: gray; 
@@ -86,10 +90,6 @@
 }
 
 
-table {
-  width: 100%;
-}
-
 td.fuzzy {
   background: #c98e7f;
 }
@@ -111,7 +111,7 @@
 div.maintainer {
   padding-left: 85px;
   margin-bottom: 12px;
-  clear: both;
+  clear: left;
 }
 
 div.mainpage {
@@ -129,6 +129,13 @@
   color: #aaaaaa;
 }
 
+div.right_actions {
+ float: right;
+ text-align: right;
+ padding: 5px;
+ background: #DCEAF7;
+}
+
 div.col1 { float: left }
 div.col2 { float: left }
 div.col3 { float: left }
@@ -149,6 +156,14 @@
   color:#999;
 }
 
+.djform td  {
+  font-size:10px;
+  color:#999;
+}
+.djform th {
+  vertical-align: top;
+}
+
 .error {
   font-style: italic;
   color: #666666;
@@ -160,6 +175,7 @@
   background: #FAE28E;
 }
 
+ul.errorlist { list-style: none; margin-left:0; padding:0; }
 .errorlist li { font-size:12px !important; display:block; padding:4px 5px 4px 25px; margin:0 0 3px 0; border:1px solid red; color:white; background:red url(../img/admin/icon_alert.gif) 5px .3em no-repeat; }
 
 .footnote {

Modified: trunk/people/forms.py
==============================================================================
--- trunk/people/forms.py	(original)
+++ trunk/people/forms.py	Sat Dec 20 14:39:02 2008
@@ -76,4 +76,9 @@
                   (email,), fail_silently=False)
 
         return new_user
-                           
+
+class EditProfileForm(forms.ModelForm):
+    class Meta:
+        model = Person
+        fields = ('first_name', 'last_name', 'email', 'image', 'webpage_url', 'irc_nick', 'bugzilla_account')
+

Modified: trunk/people/models.py
==============================================================================
--- trunk/people/models.py	(original)
+++ trunk/people/models.py	Sat Dec 20 14:39:02 2008
@@ -21,6 +21,7 @@
 
 import datetime
 from django.db import models
+from django.utils.translation import ugettext_lazy as _
 from django.contrib.auth.models import User, UserManager
 
 def obfuscate_email(email):
@@ -32,10 +33,12 @@
     """ The User class of D-L. """
 
     svn_account = models.SlugField(max_length=20, null=True, blank=True)
-    image = models.URLField(null=True, blank=True)
-    webpage_url = models.URLField(null=True, blank=True)
-    irc_nick = models.SlugField(max_length=20, null=True, blank=True)
-    bugzilla_account = models.EmailField(null=True, blank=True)
+    image = models.URLField(_("Image"), null=True, blank=True,
+                            help_text=_("URL to an image file (.jpg, .png, ...) of an hackergotchi"))
+    webpage_url = models.URLField(_("Web page"), null=True, blank=True)
+    irc_nick = models.SlugField(_("IRC nickname"), max_length=20, null=True, blank=True)
+    bugzilla_account = models.EmailField(_("Bugzilla account"), null=True, blank=True,
+                                         help_text=_("This shoud be an email, useful if not equal to 'email' field"))
     activation_key = models.CharField(max_length=40, null=True, blank=True)
 
     # Use UserManager to get the create_user method, etc.

Modified: trunk/people/urls.py
==============================================================================
--- trunk/people/urls.py	(original)
+++ trunk/people/urls.py	Sat Dec 20 14:39:02 2008
@@ -13,5 +13,6 @@
     url(r'^$', 'django.views.generic.list_detail.object_list', dict(info_dict_list), 'persons'),                    
     url(r'^(?P<object_id>\d+)/$', 'people.views.person_detail_from_id', name='person_from_id'),
     # equivalent to the previous, but using username instead of user pk
-    url(r'^(?P<slug>\w+)/$', 'people.views.person_detail_from_username', name='person')
+    url(r'^(?P<slug>\w+)/$', 'people.views.person_detail_from_username', name='person'),
+    url(r'^(?P<slug>\w+)/edit$', 'people.views.person_detail_from_username', {'edit_profile': True}, name='person_edit'),
 )

Modified: trunk/people/views.py
==============================================================================
--- trunk/people/views.py	(original)
+++ trunk/people/views.py	Sat Dec 20 14:39:02 2008
@@ -22,32 +22,51 @@
 from django.template import RequestContext
 from people.models import Person
 from teams.models import Role
-from people.forms import JoinTeamForm
+from people.forms import JoinTeamForm, EditProfileForm
 
-def person_detail_from_username(request, slug):
+def person_detail_from_username(request, slug, edit_profile=False):
     person = get_object_or_404(Person, username=slug)
-    return person_detail(request, person)
+    return person_detail(request, person, edit_profile)
 
-def person_detail_from_id(request, object_id):
+def person_detail_from_id(request, object_id, edit_profile=False):
     person = get_object_or_404(Person, pk=object_id)
-    return person_detail(request, person)
+    return person_detail(request, person, edit_profile)
 
-def person_detail(request, person):
-    if request.method == 'POST':
-        form = JoinTeamForm(request.POST)
-        if form.is_valid():
+def person_detail(request, person, edit_profile):
+    messages = []
+    # Handle the form to join a team
+    if request.method == 'POST' and request.POST.get('join_team_form',None):
+        join_form = JoinTeamForm(request.POST)
+        if join_form.is_valid():
             if request.user.username == person.username:
-                team = form.cleaned_data['teams']
+                team = join_form.cleaned_data['teams']
                 new_role = Role(team=team, person=person) # role default to translator
                 new_role.save()
             else:
-                messages.append("Sorry, you're not allowed to modify this user.")
+                messages.append(_("Sorry, you're not allowed to modify this user."))
     else:
-        form = JoinTeamForm()
+        join_form = JoinTeamForm()
+    # Handle the form to edit profile
+    profile_form = None
+    if request.method == 'POST' and request.POST.get('edit_profile_form',None):
+        form = EditProfileForm(request.POST, instance=person)
+        if form.is_valid():
+            if request.user.username == person.username:
+                form.save()
+            else:
+                messages.append(_("Sorry, you're not allowed to modify this user."))
+        else:
+            messages.append("Sorry, the form is not valid.")
+            profile_form = form
+    elif edit_profile:
+        profile_form = EditProfileForm(instance=person)
+        
     context = {
         'pageSection': "teams",
         'person': person,
-        'form': form
+        'join_form': join_form,
+        'profile_form': profile_form,
+        'messages': messages
     }
     return render_to_response('people/person_detail.html', context, context_instance=RequestContext(request))
 

Modified: trunk/stats/models.py
==============================================================================
--- trunk/stats/models.py	(original)
+++ trunk/stats/models.py	Sat Dec 20 14:39:02 2008
@@ -117,7 +117,7 @@
     def pre_save(self, model_instance, add):
         """ Check if branch is valid before saving the instance """
         if not model_instance.checkout():
-            raise Exception, "Branch not valid: error while checking out the branch."
+            raise ValueError("Branch not valid: error while checking out the branch.")
         return getattr(model_instance, self.attname)
 
 class Branch(models.Model):
@@ -883,7 +883,7 @@
         return self.modname
     
     def module_description(self):
-        return self.branch.module.description
+        return self.branch.module.description or self.branch.module.name
         
     def get_translationstat(self):
         return "%d%%&nbsp;(%d/%d/%d)" % (self.tr_percentage(), self.translated, self.fuzzy, self.untranslated)

Modified: trunk/templates/module_detail.html
==============================================================================
--- trunk/templates/module_detail.html	(original)
+++ trunk/templates/module_detail.html	Sat Dec 20 14:39:02 2008
@@ -22,7 +22,7 @@
   <p><a href="{{ module.homepage }}">{{ module.homepage }}</a></p>
 {% endif %}
 
-<table>
+<table width="100%">
   <tr>
     <td width="50%" valign="top">
       {% if module.maintainers.all %}
@@ -72,7 +72,7 @@
       <p>{% trans "This branch is currently string-frozen." %}</p>
     {% endif %}
 
-    <table><tr><td valign="top"><!-- split to two columns -->
+    <table width="100%"><tr><td valign="top"><!-- split to two columns -->
     {% with branch.get_doc_stats as stats %}
     {% if stats|length %}
       {% if not stats|length_is:"1" %}

Modified: trunk/templates/people/person_detail.html
==============================================================================
--- trunk/templates/people/person_detail.html	(original)
+++ trunk/templates/people/person_detail.html	Sat Dec 20 14:39:02 2008
@@ -9,11 +9,27 @@
   <h2>{{ person.name }}</h2>
   {% if user.is_authenticated %}
     {% ifequal user.username person.username %}
-      <div style="float: right">{% include "logout_form.html" %}</div>
+      <div class="right_actions">
+        {% include "logout_form.html" %}<br />
+        {% if not profile_form %}
+        <a href="{% url people.views.person_detail_from_username slug=person.username %}edit">
+          <img src="/media/img/edit.png" alt="{% trans "Edit" %}" title="{% trans "Edit" %}" /></a>
+        {% endif %}
+      </div>
     {% endifequal %}
   {% endif %}
 
-  {% include "person_base.html" %}
+  {% if profile_form %}
+    <div class="maintainer">
+    <form action="." method="POST" class="djform"><table>
+    {{ profile_form.as_table }}
+    <tr><td colspan="2" align="center"><input type="submit" value="{% trans "Save" %}"></td></tr>
+    <input type="hidden" name="edit_profile_form" value="1" />
+    </form></table>
+    </div>
+  {% else %}
+    {% include "person_base.html" %}
+  {% endif %}
   
   <div class="maintainer">
   {% if person.maintains_modules.all %}
@@ -39,9 +55,10 @@
     
   {% if user.is_authenticated %}
     {% ifequal user.username person.username %}
-      <form action="#" method="POST">
+      <form action="." method="POST">
       <p><em>{% trans "I would like to join the following team as 'translator':" %}</em><br />
-       {{ form.teams }}  <input type="submit" value="{% trans "Join" %}">
+       {{ join_form.teams }}  <input type="submit" value="{% trans "Join" %}">
+       <input type="hidden" name="join_team_form" value="1" />
       </form>
     {% endifequal %}
   {% endif %}



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