]> git.parisson.com Git - teleforma.git/commitdiff
add XLS course import, fix admin student fields
authoryomguy <yomguy@parisson.com>
Sat, 12 May 2012 14:14:50 +0000 (16:14 +0200)
committeryomguy <yomguy@parisson.com>
Sat, 12 May 2012 14:14:50 +0000 (16:14 +0200)
teleforma/admin.py
teleforma/management/commands/teleforma-import-courses-xls.py [new file with mode: 0644]
teleforma/models.py

index 50fdf875dc379c07da0ae585231da79a7a61bc37..2ea8f24ce80b3372abe3ba06edcac49620634cbc 100644 (file)
@@ -11,7 +11,8 @@ admin.site.unregister(User)
 
 class StudentProfileInline(admin.StackedInline):
     model = Student
-
+    filter_horizontal = ['synthesis_note', 'obligation', 'procedure', 'oral_speciality',
+                         'written_speciality', 'oral_1', 'oral_2']
 
 class ProfessorProfileInline(admin.StackedInline):
     model = Professor
diff --git a/teleforma/management/commands/teleforma-import-courses-xls.py b/teleforma/management/commands/teleforma-import-courses-xls.py
new file mode 100644 (file)
index 0000000..96e5026
--- /dev/null
@@ -0,0 +1,44 @@
+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 *
+import logging
+import codecs
+import xlrd
+import datetime
+
+
+class Command(BaseCommand):
+    help = "Import courses from a XLS file (see an example in example/data/"
+    args = "organization path"
+    first_row = 2
+    admin_email = 'webmaster@parisson.com'
+
+    def handle(self, *args, **options):
+        organization = args[0]
+        path = args[1]
+        self.book = xlrd.open_workbook(path)
+        sheet = self.book.sheet_by_index(0)
+        col = sheet.col(0)
+
+        types = CourseType.objects.all()
+        department = os.path.splitext(os.path.basename(path))[0]
+        organization, created = Organization.objects.get_or_create(name=organization)
+        department, created = Department.objects.get_or_create(name=department,
+                                                               organization=organization)
+
+        for i in range(self.first_row, len(col)):
+            for type in types:
+                course, created = Course.objects.get_or_create(title=sheet.row(i)[0].value,
+                                                               code=sheet.row(i)[1].value,
+                                                               number=int(sheet.row(i)[2].value),
+                                                               department=department,
+                                                               type=type )
+
+                if created:
+                    print 'imported: ' + course.title
+
index 038379d2d45dd69d636265896125371d808968fb..1bfc8ed2561096519d1282ca064367083a8d9fe3 100755 (executable)
@@ -140,7 +140,7 @@ class Course(Model):
     class Meta:
         db_table = app_label + '_' + 'course'
         verbose_name = _('course')
-        ordering = ['title']
+        ordering = ['number']
 
 
 class Professor(Model):