aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--admin.py4
-rw-r--r--management/commands/_private.py11
-rw-r--r--models.py6
3 files changed, 13 insertions, 8 deletions
diff --git a/admin.py b/admin.py
index 95b4fd7..509ed42 100644
--- a/admin.py
+++ b/admin.py
@@ -17,11 +17,11 @@ class LastUpdateAdmin(admin.ModelAdmin):
@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
fieldsets = (
- (None, {"fields": ("name", "timetable",)}),
+ (None, {"fields": ("name", "celcat_name", "timetable",)}),
("Groupes", {"fields": ("mention", "subgroup", "td", "tp",)}),)
list_display = ("name", "timetable",)
list_filter = ("timetable__name",)
- readonly_fields = ("mention", "subgroup", "td", "tp",)
+ readonly_fields = ("celcat_name", "mention", "subgroup", "td", "tp",)
@admin.register(Subscription)
diff --git a/management/commands/_private.py b/management/commands/_private.py
index f5a3ebc..3ff9316 100644
--- a/management/commands/_private.py
+++ b/management/commands/_private.py
@@ -29,14 +29,14 @@ def delete_courses_in_week(timetable, year, week):
Course.objects.filter(begin__gte=start, begin__lt=end,
timetable=timetable).delete()
-def get_from_db_or_create(cls, name, timetable=None):
- obj = cls.objects.all().filter(name=name)
+def get_from_db_or_create(cls, timetable=None, **kwargs):
+ obj = cls.objects.all().filter(**kwargs)
if timetable is not None:
obj = obj.filter(timetable=timetable)
obj = obj.first()
if obj is None:
- obj = cls(name=name)
+ obj = cls(**kwargs)
obj.timetable = timetable
obj.save()
@@ -61,7 +61,8 @@ def get_events(soup, weeks, year, week, timetable):
end = add_time(date, datetime.datetime.strptime(
event.endtime.text, "%H:%M"))
- groups = [get_from_db_or_create(Group, item.text, timetable)
+ groups = [get_from_db_or_create(Group, timetable,
+ celcat_name=item.text)
for item in event.resources.group.find_all("item")]
if event.notes is not None:
@@ -79,7 +80,7 @@ def get_events(soup, weeks, year, week, timetable):
type_ = event.category.text
if event.resources.room is not None:
- rooms = [get_from_db_or_create(Room, item.text)
+ rooms = [get_from_db_or_create(Room, name=item.text)
for item in event.resources.room.find_all("item")]
yield title, type_, groups, rooms, notes, begin, end
diff --git a/models.py b/models.py
index a2d4281..536c3b8 100644
--- a/models.py
+++ b/models.py
@@ -39,6 +39,7 @@ class LastUpdate(models.Model):
class Group(models.Model):
name = models.CharField(max_length=255, verbose_name="nom")
+ celcat_name = models.CharField(max_length=255, verbose_name="nom dans Celcat")
timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE, verbose_name="emploi du temps")
mention = models.CharField(max_length=32)
@@ -69,13 +70,16 @@ class Group(models.Model):
except:
print("Malformed name: {0}. Ignoring".format(self.name))
finally:
+ if self.name is None:
+ self.name = self.celcat_name
+
self.slug = slugify(self.name)
super(Group, self).save()
class Meta:
index_together = ("mention", "subgroup", "td", "tp",)
- unique_together = ("name", "timetable",)
+ unique_together = (("name", "timetable",), ("celcat_name", "timetable",),)
verbose_name = "groupe"
verbose_name_plural = "groupes"