diff --git a/common/settings.py b/common/settings.py index 0c3f46b..bd9556b 100644 --- a/common/settings.py +++ b/common/settings.py @@ -117,6 +117,7 @@ INSTALLED_APPS = ( 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', + 'tabimport', 'stages', ) diff --git a/common/urls.py b/common/urls.py index 304c87f..b8ff1e3 100644 --- a/common/urls.py +++ b/common/urls.py @@ -14,6 +14,7 @@ urlpatterns = patterns('', # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/', include(admin.site.urls)), + url(r'^data-import/', include('tabimport.urls')), url(r'^attribution/$', views.AttributionView.as_view(), name='attribution'), url(r'^stages/export/$', 'stages.views.stages_export', name='stages_export'), diff --git a/requirements.txt b/requirements.txt index 90c01e7..34b1f99 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ Django >= 1.4.2 south -e git+https://github.com/claudep/tabimport.git#egg=tabimport openpyxl +xlrd diff --git a/stages/models.py b/stages/models.py index 54877e6..edcab6c 100644 --- a/stages/models.py +++ b/stages/models.py @@ -4,6 +4,14 @@ from __future__ import unicode_literals from django.db import models +def is_int(s): + try: + int(s) + return True + except ValueError: + return False + + class Section(models.Model): """ Filières """ name = models.CharField(max_length=20) @@ -44,6 +52,19 @@ class Student(models.Model): def __unicode__(self): return '%s %s' % (self.last_name, self.first_name) + @classmethod + def prepare_import(cls, values): + ''' Hook for tabimport, before new object get created ''' + if 'klass' in values: + try: + k = Klass.objects.get(name=values['klass']) + except Klass.DoesNotExist: + raise Exception("La classe '%s' n'existe pas encore" % values['klass']) + values['klass'] = k + if 'city' in values and is_int(values['city'][:4]): + values['pcode'], _, values['city'] = values['city'].partition(' ') + return values + class Referent(models.Model): first_name = models.CharField(max_length=40, verbose_name='Prénom') diff --git a/templates/admin/index.html b/templates/admin/index.html index 9ed840a..4f501b5 100644 --- a/templates/admin/index.html +++ b/templates/admin/index.html @@ -48,6 +48,7 @@ {% endfor %} {% else %} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..3c2a9b7 --- /dev/null +++ b/templates/base.html @@ -0,0 +1 @@ +{% extends "admin/base_site.html" %}