diff options
author | Alban Gruin | 2017-01-19 21:43:34 +0100 |
---|---|---|
committer | Alban Gruin | 2017-01-19 21:43:34 +0100 |
commit | d70781860ba63d457b63a977a2d403ad9aa160b9 (patch) | |
tree | 55c04cd28fa07368ff3c3df893fbbab2d6c473b7 | |
parent | eea8dd99b859943d441e36b4958ce7bf61a27e8f (diff) |
Ajout d'un champ "notes" aux cours.
Il apparement possible qu'un cours n'ai pas de nom, ni de salle bien définie, ou que ces informations
soient stockées dans un champ "notes".
Le traitement d'un évenement celcat peut être interrompu seulement si aucun groupe n'est renseigné.
Si aucun nom n'est renseigné, il est remplacé par le contenu de la note.
-rw-r--r-- | admin.py | 3 | ||||
-rw-r--r-- | management/commands/_private.py | 16 | ||||
-rw-r--r-- | management/commands/timetables.py | 17 | ||||
-rw-r--r-- | models.py | 9 |
4 files changed, 33 insertions, 12 deletions
@@ -27,7 +27,8 @@ class RoomAdmin(admin.ModelAdmin): class CourseAdmin(admin.ModelAdmin): fieldsets = ( (None, {"fields": ("name", "type", "timetable", "groups", "rooms",)}), - ("Horaires", {"fields": ("begin", "end",)}),) + ("Horaires", {"fields": ("begin", "end",)}), + ("Remarques", {"fields": ("notes",)}),) list_display = ("name", "type", "timetable", "begin", "end",) list_filter = ("type", "timetable__name", "groups",) ordering = ("begin",) diff --git a/management/commands/_private.py b/management/commands/_private.py index 4e84363..7b71fc6 100644 --- a/management/commands/_private.py +++ b/management/commands/_private.py @@ -43,27 +43,31 @@ def get_events(soup, weeks, week, timetable): type_ = None groups = None rooms = None + notes = None if weeks[event.rawweeks.text].number != week: continue if event.resources.module is not None: - title = event.resources.module.text + title = event.resources.module.item.text - if event.category is not None and title is not None: + if event.category is not None: type_ = event.category.text - if event.resources.group is not None and type_ is not None: + if event.resources.group is not None: groups = [get_from_db_or_create(Group, item.text, timetable) for item in event.resources.group.find_all("item")] - if event.resources.room is not None and groups is not None: - rooms = [get_from_db_or_create(Room, item.text) for item in event.resources.room.find_all("item")] + if event.resources.room is not None: + rooms = [get_from_db_or_create(Room, item.text) for item in event.resources.room.find_all("item")] + + if event.notes is not None: + notes = event.notes.text date = weeks[event.rawweeks.text].get_day(int(event.day.text)) begin = add_time(date, datetime.datetime.strptime(event.starttime.text, "%H:%M")) end = add_time(date, datetime.datetime.strptime(event.endtime.text, "%H:%M")) - yield title, type_, groups, rooms, begin, end + yield title, type_, groups, rooms, notes, begin, end def get_weeks(soup): weeks = {} diff --git a/management/commands/timetables.py b/management/commands/timetables.py index 50382ed..81e5a7d 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -38,10 +38,21 @@ class Command(BaseCommand): soup = get_xml(timetable.url) weeks = get_weeks(soup) - for name, type_, groups, rooms, begin, end in get_events(soup, weeks, week, timetable): - course = Course.objects.create(name=name, type=type_, timetable=timetable, begin=begin, end=end) + for name, type_, groups, rooms, notes, begin, end in get_events(soup, weeks, week, timetable): + course = Course.objects.create(timetable=timetable, begin=begin, end=end) + + if name is not None: + course.name = name + course.notes = notes + elif notes is not None: + course.name = notes + else: + course.name = "Aucune information" + course.groups.add(*groups) - course.rooms.add(*rooms) + if rooms is not None: + course.rooms.add(*rooms) + course.save() self.stdout.write(self.style.SUCCESS("Done.")) @@ -1,4 +1,5 @@ from django.db import models +from django.utils.text import slugify class Timetable(models.Model): @@ -24,6 +25,8 @@ class Group(models.Model): td = models.IntegerField(verbose_name="groupe de TD", null=True, db_index=True) tp = models.IntegerField(verbose_name="groupe de TP", null=True, db_index=True) + slug = models.SlugField(max_length=64, unique=True, default="") + def __str__(self): return self.name @@ -42,6 +45,7 @@ class Group(models.Model): except: print("Malformed name: {0}. Ignoring".format(self.name)) finally: + self.slug = slugify(self.name) super(Group, self).save() @@ -64,9 +68,10 @@ class Room(models.Model): class Course(models.Model): - name = models.CharField(max_length=255, verbose_name="nom") - type_ = models.CharField(name="type", max_length=255, verbose_name="type de cours") + name = models.CharField(max_length=255, verbose_name="nom", null=True) + type_ = models.CharField(name="type", max_length=255, verbose_name="type de cours", null=True) timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE, verbose_name="emploi du temps") + notes = models.TextField(verbose_name="remarques", blank=True, null=True) groups = models.ManyToManyField(Group, verbose_name="groupes") rooms = models.ManyToManyField(Room, verbose_name="salles") |