]> git.parisson.com Git - teleforma.git/commitdiff
fix user list
authoryomguy <yomguy@parisson.com>
Sun, 8 Apr 2012 01:23:34 +0000 (03:23 +0200)
committeryomguy <yomguy@parisson.com>
Sun, 8 Apr 2012 01:23:34 +0000 (03:23 +0200)
teleforma/management/commands/teleforma-import-users.py
teleforma/models.py
teleforma/templates/telemeta/base.html
teleforma/templates/telemeta/inc/user_list.html
teleforma/templates/telemeta/users.html [new file with mode: 0644]
teleforma/urls.py
teleforma/views.py

index aac7ae976200de822158dc7650795b384f162a4e..ae2a5d087dd0b595d2cf70aaa515178dcf42a9c6 100644 (file)
@@ -1,6 +1,8 @@
 from optparse import make_option
 from django.conf import settings
 from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+from django.template.defaultfilters import slugify
 from telemeta.models import *
 from telemeta.util.unaccent import unaccent
 from teleforma.models import *
@@ -8,16 +10,50 @@ import logging
 import codecs
 import xlrd
 
-
 class Command(BaseCommand):
     help = "Import users from a XLS file (see an example in example/data/"
     args = "path"
     first_row = 2
+    admin_email = 'webmaster@parisson.com'
 
     def import_user(self, row):
-        last_name = row[0].value
-        first_name = row[1].value
-        print first_name, last_name
+        last_name   = row[0].value
+        first_name  = row[1].value
+        email       = row[9].value
+        #FIXME:
+        email       = self.admin_email
+        username = slugify(first_name)[0] + '.' + slugify(last_name)
+
+        #FIXME: not for prod
+        user = User.objects.get(username=username)
+        user.delete()
+
+        user, created = User.objects.get_or_create(username=username, first_name=first_name,
+                                     last_name=last_name, email=email)
+
+
+        if created:
+            student = Student.objects.filter(user=user)
+            if not student:
+                student = Student(user=user)
+            student.iej, c = IEJ.objects.get_or_create(name=row[2].value)
+            student.training, c = Training.objects.get_or_create(code=row[3].value)
+            student.procedure, c = Procedure.objects.get_or_create(code=row[4].value)
+            student.written_speciality, c = Speciality.objects.get_or_create(code=row[5].value)
+            student.oral_speciality, c = Speciality.objects.get_or_create(code=row[6].value)
+            student.oral_1, c = Oral.objects.get_or_create(code=row[7].value)
+            student.oral_2, c = Oral.objects.get_or_create(code=row[8].value)
+            student.category, c = Category.objects.get_or_create(name=row[15].value)
+            address     = row[10].value
+            p_code      = row[11].value
+            city        = row[12].value
+            tel         = row[13].value
+            date        = row[14].value
+
+            student.save()
+            print 'imported: ' + first_name + ' ' + last_name + ' ' + username
+
+
 
     def handle(self, *args, **options):
         file = args[0]
@@ -27,7 +63,6 @@ class Command(BaseCommand):
         for i in range(self.first_row, len(col)):
             self.import_user(sheet.row(i))
 
-        print "Done, imported %s users" % str(i)
 
 
 
index e8832803e926f9dcbe683a2955b7d770b40ec176..c645b6f198cae2c0086f6eecf8a248e7ef175377 100755 (executable)
@@ -274,6 +274,7 @@ class IEJ(Model):
         db_table = app_label + '_' + 'iej'
         verbose_name = _('IEJ')
         verbose_name_plural = _('IEJ')
+        ordering = ['name']
 
 
 class Training(Model):
@@ -287,7 +288,7 @@ class Training(Model):
 
 
     def __unicode__(self):
-        return self.name
+        return self.code
 
     class Meta:
         db_table = app_label + '_' + 'training'
@@ -300,7 +301,7 @@ class Procedure(Model):
     code           = CharField(_('code'), max_length=255)
 
     def __unicode__(self):
-        return self.name
+        return self.code
 
     class Meta:
         db_table = app_label + '_' + 'procedure'
@@ -313,7 +314,7 @@ class Speciality(Model):
     code           = CharField(_('code'), max_length=255)
 
     def __unicode__(self):
-        return self.name
+        return self.code
 
     class Meta:
         db_table = app_label + '_' + 'speciality'
@@ -326,7 +327,7 @@ class Oral(Model):
     code           = CharField(_('code'), max_length=255)
 
     def __unicode__(self):
-        return self.name
+        return self.code
 
     class Meta:
         db_table = app_label + '_' + 'oral'
index edf7fc28678145f00c67644f5747a5a58a7187d6..8c61487b7b4e8c8cd09a96a494744158e5198fe8 100644 (file)
@@ -70,7 +70,7 @@ alt="Telemeta Powered"/>-->
  {% if user.is_authenticated %}
  <li><a href="/messages" class="green">{% trans "Messages" %}{% if postman_unread_count %} ({{ postman_unread_count }}){% endif %}</a></li>
 
- <li><a href="{% url telemeta-users %}" class="yellow">{% trans "Users" %}</a></li>
+ <li><a href="{% url teleforma-users %}" class="yellow">{% trans "Users" %}</a></li>
 
  <li><a href="{% url telemeta-search-criteria %}" class="orange">{% trans "Advanced search" %}</a></li>
 
index 7a4ca94947306b68ac6361dda09acb2d81219e86..525b80ad92304a993fa9916b4f30fb6dd0b4cada 100644 (file)
@@ -2,12 +2,28 @@
 {% load telemeta_utils %}
 {% load teleforma_tags %}
 
+{% if is_paginated %}
+<div class="pagination">
+<span class="page-links">
+{% if page_obj.has_previous %}
+<a href="{% url teleforma-users %}?page={{ page_obj.previous_page_number }}" class="component_icon button icon_previous">{% trans "Previous" %}</a>
+{% endif %}
+<span class="page-current">
+{% trans "Page" %} {{ page_obj.number }} {%trans "of" %} {{ page_obj.paginator.num_pages }}.
+</span>
+{% if page_obj.has_next %}
+<a href="{% url teleforma-users %}?page={{ page_obj.next_page_number }}" class="component_icon button icon_next">{% trans "Next" %}</a>
+{% endif %}
+</span>
+</div>
+{% endif %}
+
 <div id="users">
   <table class="listing" width="100%">
    <thead>
-    <tr><th>{% trans "User"%}</th>
+   <tr><th>{% trans "Last Name"%}</th>
     <th>{% trans "First Name"%}</th>
-    <th>{% trans "Last Name"%}</th>
+    <th>{% trans "User"%}</th>
     <th>{% trans "Training"%}</th>
     <th>{% trans "IEJ"%}</th>
     <th>{% trans "Procedure"%}</th>
     <th>{% trans "Written spe"%}</th>
     <th>{% trans "Oral 1"%}</th>
     <th>{% trans "Oral 2"%}</th>
-    <th>{% trans "Synthesis note"%}</th>
+    <th>{% trans "Synthesis"%}</th>
     <th>{% trans "Messages"%}</th>
     </tr>
     </thead>
     <tbody id="spacing">
     {% for user in users %}
     <tr>
-     <td><a href="{% url telemeta-profile-detail user.username %}">{{user.username}}</a></td>
-     <td>{{ user.first_name }}</td>
      <td>{{ user.last_name }}</td>
+     <td>{{ user.first_name }}</td>
+     <td><a href="{% url telemeta-profile-detail user.username %}">{{user.username}}</a></td>
+
      {% if user.student.get %}
       {% with user.student.get as student %}
-        <td>{{ student.training }}</td>
-        <td>{{ student.iej }}</td>
-        <td>{{ student.procedure }}</td>
-        <td>{{ student.oral_speciality }}</td>
-        <td>{{ student.written_speciality }}</td>
-        <td>{{ student.oral_1 }}</td>
-        <td>{{ student.oral_2 }}</td>
+        <td>{{ student.training.code }}</td>
+        <td>{{ student.iej.name }}</td>
+        <td>{{ student.procedure.code }}</td>
+        <td>{{ student.oral_speciality.code }}</td>
+        <td>{{ student.written_speciality.code }}</td>
+        <td>{{ student.oral_1.code }}</td>
+        <td>{{ student.oral_2.code }}</td>
         <td></td>
      {% endwith %}
     {% elif user.professor.get %}
diff --git a/teleforma/templates/telemeta/users.html b/teleforma/templates/telemeta/users.html
new file mode 100644 (file)
index 0000000..ff5bde5
--- /dev/null
@@ -0,0 +1,17 @@
+{% extends "telemeta/base.html" %}
+{% load i18n %}
+{% load telemeta_utils %}
+
+{% block head_title %}{% trans "Users" %} - {{ block.super }}{% endblock %}
+
+{% block title %}
+ <img src="{% url telemeta-images "user_red.png" %}" alt="user" style="vertical-align:middle" /> {% trans "Users" %}
+{% endblock %}
+
+{% block content %}
+ {% if users %}
+  {% include "telemeta/inc/user_list.html" %}
+ {% else %}
+    <p class="help">{% trans "No users" %}</p>
+ {% endif %}
+{% endblock %}
index 2f028eb61cdc2a0172ecff6262001f7bf2bbb4ce..503410b1d76f819afb908817206e4c6a6352f72d 100644 (file)
@@ -57,6 +57,7 @@ urlpatterns = patterns('',
     # Postman
     url(r'^messages/', include('postman.urls')),
 
+    url(r'^all_users/$', UsersView.as_view(), name="teleforma-users"),
 
 # CSS+Images (FIXME: for developement only)
     url(r'^teleforma/css/(?P<path>.*)$', 'django.views.static.serve',
index da0a5c35ceb3fc4122561fed1a193bafd4a46994..9e3bf748707093fbfe17a4eab4a279078ac4fcda 100755 (executable)
@@ -24,6 +24,7 @@ from django.utils.translation import ugettext
 from django.contrib.auth.forms import UserChangeForm
 from django.core.exceptions import ObjectDoesNotExist
 from django.contrib.syndication.views import Feed
+from django.core.paginator import Paginator
 
 from teleforma.models import *
 from telemeta.views.base import *
@@ -116,3 +117,12 @@ class MediaView(DetailView):
         context['room'] = media.course.chat_room
         return context
 
+class UsersView(ListView):
+
+    model = User
+    template_name='telemeta/users.html'
+    context_object_name = 'users'
+    paginate_by = 12
+
+    def get_queryset(self):
+        return User.objects.all().order_by('last_name')