]> git.parisson.com Git - telemeta.git/commitdiff
add user profile model and view
authoryomguy <yomguy@parisson.com>
Tue, 29 Mar 2011 13:12:57 +0000 (15:12 +0200)
committeryomguy <yomguy@parisson.com>
Tue, 29 Mar 2011 13:12:57 +0000 (15:12 +0200)
telemeta/models/core.py
telemeta/models/system.py
telemeta/templates/telemeta/profile_detail.html [new file with mode: 0644]
telemeta/templates/telemeta_default/base.html
telemeta/templates/telemeta_default/home.html
telemeta/templates/telemeta_default/profile_detail.html [new file with mode: 0644]
telemeta/urls.py
telemeta/web/base.py

index 7c568004cb6b52befc07d3bb27a4209e51a61639..266985c10ccdd0d315fe1063ac177844a19db554 100644 (file)
@@ -49,6 +49,7 @@ from django.utils.translation import ugettext_lazy as _
 import re
 from django.core.exceptions import ObjectDoesNotExist
 
+    
 class Duration(object):
     """Represent a time duration"""
     def __init__(self, *args, **kwargs):
index 0b2d863331cc85e3c0e4fe4334a4ab68c8bd2713..71ebc0cc4c5062224df8db125e2e16eff364f5bb 100644 (file)
@@ -35,9 +35,9 @@
 
 from django.contrib.auth.models import User
 from telemeta.models.core import *
-import django.db.models
 from django.core.exceptions import ObjectDoesNotExist
 from django.utils.translation import ugettext_lazy as _
+import django.db.models
 
 
 class Revision(ModelCore):
@@ -74,10 +74,13 @@ class Revision(ModelCore):
 class UserProfile(django.db.models.Model):
     "User profile extension"
     
-    user            = django.db.models.ForeignKey(User, unique=True)
+    user            = ForeignKey(User, unique=True)
     institution     = CharField(_('institution'))
     function        = CharField(_('function'))
     address         = TextField(_('address'))
     telephone       = CharField(_('function'))
     expiration_date = DateField(_('expiration_date'))
     
+    class Meta(MetaCore):
+        db_table = 'profiles'
+        
diff --git a/telemeta/templates/telemeta/profile_detail.html b/telemeta/templates/telemeta/profile_detail.html
new file mode 100644 (file)
index 0000000..4561152
--- /dev/null
@@ -0,0 +1 @@
+{% extends "telemeta_default/profile_detail.html" %}
index 50836abc9f19231560b0183d42e9c5f552b3855b..fe00eaedf7beb9a2038bc3e9f9b948e2303220ec 100644 (file)
@@ -47,7 +47,7 @@
 {% else %}
 {{ user.username }}.
 {% endif %}
-{% trans "Account" %} |
+<a href="{% url telemeta-profile-detail user.username %}">{% trans "Account" %}</a> |
 <a href="{% url telemeta-help %}">{% trans "Help" %}</a> | 
 <a href="{% url telemeta-logout %}">{% trans "Sign out" %}
 <img src="images/logout.png" style="vertical-align:middle" /></a>
index 3f8e2496f9763bf5dea923cb4ecc919b36e8a87c..afb2a37d4bb951c980426cc16c51c2d86311923b 100644 (file)
@@ -47,7 +47,8 @@
         {% endif %}
         </td>
         <td>{{ r.revision.element_type }}</td>
-        <td>{{ r.revision.user.username }}</td>
+        <td>{% if r.revision.user %}{{ r.revision.user.username }}{% endif %}</td>
+        
      </tr>
     {% endfor %}
     </table>
@@ -65,7 +66,7 @@
   <h2>{{ playlist.playlist.title }}</h2>
   <div style="float:right">
   <a href="{% url telemeta-playlist-csv-export playlist.playlist.public_id %}" class="component_icon button icon_csv">CSV</a>
-  <a href="#" id="{{playlist.playlist.public_id}}" onclick="playlist.remove(this.id);return false;" class="component_icon button icon_cancel"> {% trans "Delete" %}</a>
+  <a href="#" id="{{playlist.playlist.public_id}}" onclick="playlist.remove(this.id);return false;" class="component_icon button icon_cancel">{% trans "Delete" %}</a>
   </div>
   
   
                 {% endif %}
             </td>
             <td>
-            <a href="#" onclick="playlistUtils.removeResource('{{resource.public_id}}');return false;" class="component_icon button icon_cancel"> {% trans "Delete" %}</a>
+            <a href="#" onclick="playlistUtils.removeResource('{{resource.public_id}}');return false;" class="component_icon button icon_cancel"></a>
             </td>
         </tr>
     {% endfor %}
diff --git a/telemeta/templates/telemeta_default/profile_detail.html b/telemeta/templates/telemeta_default/profile_detail.html
new file mode 100644 (file)
index 0000000..742625d
--- /dev/null
@@ -0,0 +1,37 @@
+{% extends "telemeta/base.html" %}
+{% load i18n %}
+{% load telemeta_utils %}
+
+{% block head_title %}{% trans "User Profile" %} : {{ user.username }}{% endblock %}
+
+{% block submenu %}
+    <div>
+    {% block tools %}
+    {% if user.is_authenticated %}
+      {% trans "Edit" %}
+     {% endif %}
+    {% endblock tools %}
+    </div>
+{% endblock %}
+
+{% block content %}
+    <h3>{% trans "User profile" %} : {{ user.username }}</h3>
+    <div style="padding-top: 1em;">
+     <dl class="listing">
+      <dt>{% trans "First Name" %}</dt><dd>{{ usr.first_name }}</dd>
+      <dt>{% trans "Last Name" %}</dt><dd>{{ usr.last_name }}</dd>
+      <dt>{% trans "Email" %}</dt><dd>{{ usr.email }}</dd>
+      
+      <dt>{% trans "Institution" %}</dt><dd>{% if profile %}{{ profile.institution }}{% endif %}</dd>
+      <dt>{% trans "Function" %}</dt><dd>{% if profile %}{{ profile.function }}{% endif %}</dd>
+      <dt>{% trans "Address" %}</dt><dd>{% if profile %}{{ profile.address }}{% endif %}</dd>
+      <dt>{% trans "Telephone" %}</dt><dd>{% if profile %}{{ profile.telephone }}{% endif %}</dd>
+      <dt>{% trans "Expiration date" %}</dt><dd>{% if profile %}{{ profile.expiration_date }}{% endif %}</dd>
+      
+      <dt>{% trans "Is admin" %}</dt><dd>{{ usr.is_staff }}</dd>
+      <dt>{% trans "Is superuser" %}</dt><dd>{{ usr.is_superuser }}</dd>
+      <dt>{% trans "Last login" %}</dt><dd>{{ usr.last_login }}</dd>
+     </dl>
+    </div>
+{% endblock %}
+
index c554ed88896af0b4f6c0101fc1aa8e35c84648c9..7eb9475f2fa590f95ee19fa4b0286967e80cb196 100644 (file)
@@ -190,10 +190,13 @@ urlpatterns = patterns('',
     url(r'^oai/.*$', web_view.handle_oai_request, name="telemeta-oai"),
 
     # Authentication
-     url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'telemeta/login.html'},
+    url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'telemeta/login.html'},
         name="telemeta-login"),
     url(r'^logout/$', web_view.logout, name="telemeta-logout"),
     
+    # Profile
+    url(r'^accounts/(?P<username>[A-Za-z0-9._-]+)/profile/$', web_view.profile_detail, name="telemeta-profile-detail"),
+    
     # JSON RPC
     url(r'^json/browse/', 'jsonrpc.views.browse', name="jsonrpc_browser"), # for the graphical browser/web console only, omissible
     url(r'^json/$', jsonrpc_site.dispatch, name='jsonrpc_mountpoint'),
index ed39f634097a0c79b7292e86468bae4caa9a08b3..9b150278a51a88561fd1b906bbb8197d53b3ef36 100644 (file)
@@ -1011,3 +1011,12 @@ class WebView(object):
         description = 'Please login or contact the website administator to get private access.'
         messages.error(request, title)
         return render(request, 'telemeta/messages.html', {'description' : description})
+    
+    @method_decorator(login_required)
+    def profile_detail(self, request, username, template='telemeta/profile_detail.html'):
+        user = User.objects.get(username=username)
+        try:
+            profile = user.get_profile()
+        except:
+            profile = None
+        return render(request, template, {'profile' : profile, 'usr': user})