]> git.parisson.com Git - teleforma.git/commitdiff
begin xls training user export
authoryomguy <yomguy@parisson.com>
Tue, 10 Apr 2012 23:37:24 +0000 (01:37 +0200)
committeryomguy <yomguy@parisson.com>
Tue, 10 Apr 2012 23:37:24 +0000 (01:37 +0200)
teleforma/htdocs/css/teleforma_black.css
teleforma/templates/telemeta/inc/user_list.html
teleforma/urls.py
teleforma/views.py

index 5abbab571588c7dbf03c3db89cd7590b0e76003f..be5dcfacba11ae72c68ea859f57e0cf9e8a6b72c 100644 (file)
@@ -760,7 +760,7 @@ dl.dublincore dd.caption {
 
 /* Pagination */
 .pagination {
-    margin-top: .7em;
+    margin-top: 0em;
     margin-bottom: .3em;
     padding: .3em 0;
     font-size: 1em;
@@ -1389,7 +1389,7 @@ input,textarea{
     -moz-border-radius: 8px 0px 0px 0px;
     -webkit-border-radius: 8px 0px 0px 0px;
     border-radius: 8px 0px 0px 0px;
-    padding: 0em 0.8em 0.3em 0em;
+    padding: 0em 0.8em 0.8em 0em;
     font-weight: bold;
     font-size: 1.2em;
     }
@@ -1499,4 +1499,3 @@ input,textarea{
     font-size: 0.8em;
     font-weight: normal;
     }
-
index d03386d6423ecdcaf53cd6f6138ecbdc934c6adc..1b11c1a4cc84dd80ea3398209df4b3f3b5d0d0fa 100644 (file)
@@ -3,7 +3,7 @@
 {% load teleforma_tags %}
 
 {% if is_paginated %}
-<div class="pagination">
+<div class="pagination" id="user_pagination">
 {% if page_obj.has_previous %}
 <a href="{% url teleforma-users %}?page={{ page_obj.previous_page_number }}">< {% trans "Previous" %}</a>
 {% endif %}
index 48b774174e409405b7d10feb40accdf8b724be35..b8bcf520d7eede359cf35203fa20d274cad76386 100644 (file)
@@ -62,6 +62,7 @@ urlpatterns = patterns('',
     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"),
+    url(r'^all_users/by_trainings/(\w+)/export/$', user_export.export_training, name="teleforma-training-users-export"),
 
 # CSS+Images (FIXME: for developement only)
     url(r'^teleforma/css/(?P<path>.*)$', 'django.views.static.serve',
index 298151e3f9e8cf90c7e1eab04d040d6a5d8b94a7..236cd218aaca4b480659557601ea237291a1781a 100755 (executable)
@@ -140,11 +140,29 @@ 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 __init__(self):
+        self.first_row = 1
+        self.book = Workbook()
+        self.sheet = self.book.add_sheet('Etudiants')
+        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")
 
     def export_user(self, count, user):
         student = Student.objects.filter(user=user)
@@ -176,26 +194,22 @@ class UsersXLSExport(object):
 
     @method_decorator(permission_required('is_superuser'))
     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
+
+    @method_decorator(permission_required('is_superuser'))
+    def export_training(self, request, id):
+        users = User.objects.all().select_related(depth=2)
+        trainings = Training.objects.filter(id=id)
+        users = User.objects.filter(student__training__in=trainings)
 
         count = self.first_row
         for user in users: