]> git.parisson.com Git - teleforma.git/commitdiff
add XLS user list export button
authoryomguy <yomguy@parisson.com>
Tue, 10 Apr 2012 23:00:00 +0000 (01:00 +0200)
committeryomguy <yomguy@parisson.com>
Tue, 10 Apr 2012 23:00:00 +0000 (01:00 +0200)
example/data/CRFPA.txt [new file with mode: 0644]
teleforma/management/commands/teleforma-export-users.py
teleforma/templates/telemeta/users.html
teleforma/urls.py
teleforma/views.py

diff --git a/example/data/CRFPA.txt b/example/data/CRFPA.txt
new file mode 100644 (file)
index 0000000..da10933
--- /dev/null
@@ -0,0 +1,22 @@
+Droit_administratif
+Droit_des_obligations
+Droit_commercial_des_affaires
+Droit_communautaire_et_européen
+Droit_de_la_famille_et_des_personnes
+Droit_du_travail
+Droit_fiscal
+Droit_international_privé
+Droit_patrimonial
+Droit_public_des_activités_économiques
+Droit_pénal
+Droit_Libertés_publiques
+Note_de_synthèse
+Procédure_administrative_et_contentieuse
+Procédure_civile
+Procédures_collectives_et_sûretés
+Procédure_pénale
+Oral-Procédures_communautaires
+Oral-Voies_d'ex
+Oral-Comptabilité_privée
+Oral-Finances_publiques
+Conférence-actualisation-septembre
index 57997a1a94a8c527860267bb145dc180386f6f11..5ada83dff0751f8d43c3f5b6e57319c9ee7ff3de 100644 (file)
@@ -45,8 +45,7 @@ class Command(BaseCommand):
 
             print 'exported: ' + user.first_name + ' ' + user.last_name + ' ' + user.username
 
-    def handle(self, *args, **options):
-        file = args[0]
+    def export(self):
         self.book = Workbook()
         self.sheet = self.book.add_sheet('Etudiants')
         users = User.objects.all()
@@ -66,12 +65,19 @@ class Command(BaseCommand):
         row.write(12, 'VILLE')
         row.write(13, 'TEL')
         row.write(14, "Date d'inscription")
-        row.write(15, unicode("Categorie"))
+        row.write(15, "Categorie")
 
         count = self.first_row
         for user in users:
             self.export_user(count, user)
             count += 1
-        self.book.save(file)
+
+        self.book.save(self.file)
+
+    def handle(self, *args, **options):
+        self.file = args[0]
+        self.export()
+
+
 
 
index 0de0536b95434e4d35dda36b3868904a464c2b6a..110fe9dde4f84a3c096d0afb84fb04ae3161f243 100644 (file)
@@ -4,11 +4,10 @@
 
 {% block head_title %}{% trans "Users" %} - {{ block.super }}{% endblock %}
 
-
 {% block title %}
-
 {% endblock %}
 
+
 {% block content %}
 <div id="module-set-left" style="width: 20%">
 <div class="module">
@@ -26,6 +25,9 @@
 </div>
 
 <div class="desk_course">
+<div style="float:right;">
+<a href="{% url teleforma-users-xls-export %}" class="component_icon button icon_csv">XLS Export</a>
+</div>
 <div class="course_title">{% trans "Users" %}</div>
  {% if users %}
   {% include "telemeta/inc/user_list.html" %}
index 6ede556d97379bacc18bc3c585daa0c3e05c66ba..48b774174e409405b7d10feb40accdf8b724be35 100644 (file)
@@ -42,6 +42,7 @@ from jsonrpc import jsonrpc_site
 import jqchat.views
 
 htdocs_forma = os.path.dirname(__file__) + '/htdocs'
+user_export = UsersXLSExport()
 
 urlpatterns = patterns('',
 
@@ -60,6 +61,7 @@ urlpatterns = patterns('',
     # Users
     url(r'^all_users/$', UsersView.as_view(), name="teleforma-users"),
     url(r'^all_users/by_trainings/(\w+)$', UsersTrainingView.as_view(), name="teleforma-training-users"),
+    url(r'^all_users/export/$', user_export.export, name="teleforma-users-xls-export"),
 
 # CSS+Images (FIXME: for developement only)
     url(r'^teleforma/css/(?P<path>.*)$', 'django.views.static.serve',
index 89b487135b93840d2da4c01ad3f352dd66165404..557703ea6612c0bfb7e70ab29008442d0b29d91f 100755 (executable)
@@ -29,6 +29,7 @@ from django.core.paginator import Paginator
 from teleforma.models import *
 from telemeta.views.base import *
 from jqchat.models import *
+from xlwt import Workbook
 
 
 
@@ -139,3 +140,67 @@ class UsersTrainingView(UsersView):
         trainings = Training.objects.filter(id=self.args[0])
         return User.objects.filter(student__training__in=trainings)
 
+class UsersXLSExport(object):
+
+    first_row = 1
+    admin_email = 'webmaster@parisson.com'
+
+    def export_user(self, count, user):
+        student = Student.objects.filter(user=user)
+        if student:
+            student = Student.objects.get(user=user)
+            row = self.sheet.row(count)
+            row.write(0, user.last_name)
+            row.write(1, user.first_name)
+            row.write(9, user.email)
+            row.write(2, unicode(student.iej))
+            row.write(3, unicode(student.training.code))
+            row.write(4, unicode(student.procedure))
+            row.write(5, unicode(student.written_speciality))
+            row.write(6, unicode(student.oral_speciality))
+            row.write(7, unicode(student.oral_1))
+            row.write(8, unicode(student.oral_2))
+            row.write(15, unicode(student.category))
+
+            profile = Profile.objects.filter(user=user)
+            if profile:
+                profile = Profile.objects.get(user=user)
+                row.write(10, profile.address)
+                row.write(11, profile.postal_code)
+                row.write(12, profile.city)
+                row.write(13, profile.telephone)
+                row.write(14, profile.date_added.strftime("%d/%m/%Y"))
+
+            print 'exported: ' + user.first_name + ' ' + user.last_name + ' ' + user.username
+
+    def export(self, request):
+        self.book = Workbook()
+        self.sheet = self.book.add_sheet('Etudiants')
+        users = User.objects.all()
+        row = self.sheet.row(0)
+        row.write(0, 'NOM')
+        row.write(1, 'PRENOM')
+        row.write(2, 'IEJ')
+        row.write(3, 'FORMATION')
+        row.write(4, 'PROC')
+        row.write(5, 'Ecrit Spe')
+        row.write(6, unicode('Oral Spe'))
+        row.write(7, 'ORAL 1')
+        row.write(8, 'ORAL 2')
+        row.write(9, 'MAIL')
+        row.write(10, 'ADRESSE')
+        row.write(11, 'CP')
+        row.write(12, 'VILLE')
+        row.write(13, 'TEL')
+        row.write(14, "Date d'inscription")
+        row.write(15, "Categorie")
+
+        count = self.first_row
+        for user in users:
+            self.export_user(count, user)
+            count += 1
+
+        response = HttpResponse(mimetype="application/vnd.ms-excel")
+        response['Content-Disposition'] = 'attachment; filename=users.xls'
+        self.book.save(response)
+        return response