]> git.parisson.com Git - teleforma.git/commitdiff
fix first user list import fir the PB
authoryomguy <yomguy@parisson.com>
Fri, 27 Apr 2012 19:53:20 +0000 (21:53 +0200)
committeryomguy <yomguy@parisson.com>
Fri, 27 Apr 2012 19:53:20 +0000 (21:53 +0200)
teleforma/management/commands/teleforma-import-users.py
teleforma/models.py
teleforma/views.py

index 69ab6ddfeab85e35ea8f5f2c7cbb4900820235f8..08a783fb27edb9b159f67f658f927600a5faa853 100644 (file)
@@ -9,6 +9,7 @@ from teleforma.models import *
 import logging
 import codecs
 import xlrd
+import datetime
 
 class Command(BaseCommand):
     help = "Import users from a XLS file (see an example in example/data/"
@@ -21,16 +22,19 @@ class Command(BaseCommand):
         first_name  = row[1].value
         email       = row[9].value
         #FIXME:
-        email       = self.admin_email
+        #email       = self.admin_email
         username = slugify(first_name)[0] + '.' + slugify(last_name)
+        username = username[:30]
+        date = row[14].value
+        date_joined = datetime.datetime(*xlrd.xldate_as_tuple(date, self.book.datemode))
 
         #FIXME: not for prod
-        #user = User.objects.get(username=username)
-        #user.delete()
+        user = User.objects.filter(username=username)
+        if user:
+            user[0].delete()
 
         user, created = User.objects.get_or_create(username=username, first_name=first_name,
-                                     last_name=last_name, email=email)
-
+                                     last_name=last_name, email=email, date_joined = date_joined)
 
         if created:
             student = Student.objects.filter(user=user)
@@ -43,7 +47,7 @@ class Command(BaseCommand):
             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)
+            student.category, c = Category.objects.get_or_create(name='Estivale')
             profile, created = Profile.objects.get_or_create(user=user)
             profile.address = row[10].value
             profile.postal_code = int(row[11].value)
@@ -55,8 +59,8 @@ class Command(BaseCommand):
 
     def handle(self, *args, **options):
         file = args[0]
-        book = xlrd.open_workbook(file)
-        sheet = book.sheet_by_index(0)
+        self.book = xlrd.open_workbook(file)
+        sheet = self.book.sheet_by_index(0)
         col = sheet.col(0)
         for i in range(self.first_row, len(col)):
             self.import_user(sheet.row(i))
index a3722cb8901253d3183e915ee61c579c537968cc..6938a6fa9ca5457e88fd81029ef0871b4d098e6a 100755 (executable)
@@ -461,7 +461,6 @@ class Profile(models.Model):
     country         = CharField(_('Country'), max_length=255, blank=True)
     language        = CharField(_('Language'), max_length=255, blank=True)
     telephone       = CharField(_('Telephone'), max_length=255, blank=True)
-    date_added      = DateTimeField(_('date added'), auto_now_add=True)
     expiration_date = DateField(_('Expiration_date'), blank=True, null=True)
     init_password   = BooleanField(_('Password initialization'))
 
index dfa681d15967e3ff11dd27e9fd320527f30f6b5e..9e8c9bd7e552f2a6f5a927f36ef9c075224f029b 100755 (executable)
@@ -117,9 +117,11 @@ class CoursesView(ListView):
     model = Course
     template_name='teleforma/courses.html'
 
+    def get_queryset(self):
+        return get_courses(self.request.user)
+
     def get_context_data(self, **kwargs):
         context = super(CoursesView, self).get_context_data(**kwargs)
-        context['object_list'] = get_courses(self.request.user)
         context['notes'] = Note.objects.filter(author=self.request.user)
         context['room'] = get_room(name='site')
         return context
@@ -304,7 +306,7 @@ class UsersXLSExport(object):
                 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"))
+                row.write(14, user.date_joined.strftime("%d/%m/%Y"))
             return counter + 1
         else:
             return counter