From: yomguy Date: Sat, 12 May 2012 14:14:50 +0000 (+0200) Subject: add XLS course import, fix admin student fields X-Git-Tag: 0.4~3 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=19ce70258f467fd0f260c1717eaba23d20f031e1;p=teleforma.git add XLS course import, fix admin student fields --- diff --git a/teleforma/admin.py b/teleforma/admin.py index 50fdf875..2ea8f24c 100644 --- a/teleforma/admin.py +++ b/teleforma/admin.py @@ -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 index 00000000..96e5026e --- /dev/null +++ b/teleforma/management/commands/teleforma-import-courses-xls.py @@ -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 + diff --git a/teleforma/models.py b/teleforma/models.py index 038379d2..1bfc8ed2 100755 --- a/teleforma/models.py +++ b/teleforma/models.py @@ -140,7 +140,7 @@ class Course(Model): class Meta: db_table = app_label + '_' + 'course' verbose_name = _('course') - ordering = ['title'] + ordering = ['number'] class Professor(Model):