From c5d409e7c38cd5dd5686ce2311928587796349f9 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Tue, 12 Sep 2017 21:32:35 +0200 Subject: Lecture du contenu de la réponse avec r.content et non r.text pour limiter les problèmes --- management/commands/_private.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/management/commands/_private.py b/management/commands/_private.py index 17896c4..2b57599 100644 --- a/management/commands/_private.py +++ b/management/commands/_private.py @@ -159,5 +159,5 @@ def get_xml(url): r = requests.get(url) r.encoding = "utf8" - soup = BeautifulSoup(r.text, "html.parser") + soup = BeautifulSoup(r.content, "html.parser") return soup -- cgit v1.2.1 From c0f19d41c8dfb6d499defcfc63c273bbc8918584 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sat, 9 Sep 2017 19:37:12 +0200 Subject: Génération automatique d’un slug pour les modèles Year et Timetable --- admin.py | 1 + models.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/admin.py b/admin.py index 2fc0e78..48930e0 100644 --- a/admin.py +++ b/admin.py @@ -21,6 +21,7 @@ from .models import Timetable, LastUpdate, Group, Room, Course, Year class YearAdmin(admin.ModelAdmin): prepopulated_fields = {"slug": ("name",)} list_display = ("name",) + ordering = ("name",) @admin.register(Timetable) diff --git a/models.py b/models.py index 6bb9733..c263510 100644 --- a/models.py +++ b/models.py @@ -21,7 +21,19 @@ from django.utils.text import slugify from .utils import parse_group -class Year(models.Model): +class SlugModel(models.Model): + def save(self): + if not self.slug: + self.slug = slugify(self.name) + + super(SlugModel, self).save() + + + class Meta: + abstract = True + + +class Year(SlugModel): name = models.CharField(max_length=16, verbose_name="année") slug = models.SlugField(max_length=16, unique=True, default="") @@ -34,7 +46,7 @@ class Year(models.Model): verbose_name_plural = "années" -class Timetable(models.Model): +class Timetable(SlugModel): year = models.ForeignKey(Year, on_delete=models.CASCADE, verbose_name="année") name = models.CharField(max_length=64, verbose_name="nom") url = models.URLField(max_length=255, verbose_name="URL") -- cgit v1.2.1 From 445bfdcde5309645ac4d6f5c1d565530e6dbfeed Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sat, 9 Sep 2017 21:07:09 +0200 Subject: Tri du modèle Timetable --- admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/admin.py b/admin.py index 48930e0..fff2c19 100644 --- a/admin.py +++ b/admin.py @@ -29,6 +29,7 @@ class TimetableAdmin(admin.ModelAdmin): prepopulated_fields = {"slug": ("name",)} list_display = ("name", "year", "url",) list_filter = ("year__name",) + ordering = ("year", "name",) @admin.register(LastUpdate) -- cgit v1.2.1 From 32bd236f2c53bc8dfd515018a7ae0ec06f65c115 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sun, 10 Sep 2017 11:54:38 +0200 Subject: La consolidation a lieu pour le parent d’un groupe mais aussi ses enfants --- management/commands/_private.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/management/commands/_private.py b/management/commands/_private.py index 2b57599..c140f51 100644 --- a/management/commands/_private.py +++ b/management/commands/_private.py @@ -45,19 +45,34 @@ def add_time(date, time): def consolidate_group(group): group_content_key = ("mention", "subgroup", "td", "tp") group_content_list = group.group_info[1:] - group_content = dict(zip(group_content_key, group_content_list)) - for i in range(len(group_content_list))[::-1]: - del group_content[group_content_key[i]] - group_content[group_content_key[i] + "__isnull"] = True + if group.subgroup is not None: + group_content = dict(zip(group_content_key, group_content_list)) - if group_content_list[i] is not None: - break + for i in range(len(group_content_list))[::-1]: + del group_content[group_content_key[i]] + group_content[group_content_key[i] + "__isnull"] = True - if "subgroup" in group_content: - group.parent = Group.objects.filter(**group_content).first() + if group_content_list[i] is not None: + break + + group.parent = Group.objects.filter(timetable=group.timetable, + **group_content).first() group.save() + if group.tp is None: + group_content = dict(zip(group_content_key, group_content_list)) + last_is_none = False + + for i, key in enumerate(group_content_key): + if group_content_list[i] is None or last_is_none: + del group_content[key] + group_content[key + "__isnull"] = last_is_none + last_is_none = True + + Group.objects.filter(timetable=group.timetable, parent__isnull=True, + **group_content).update(parent=group) + def consolidate_groups(groups): for group in groups: if group.parent == None: -- cgit v1.2.1 From 5a391f46fafee98b653f9c64219ad17844f7e340 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sun, 10 Sep 2017 11:59:32 +0200 Subject: Filtrage des cours et des groupes par l’emploi du temps et non par son nom --- admin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/admin.py b/admin.py index fff2c19..16e34f3 100644 --- a/admin.py +++ b/admin.py @@ -44,7 +44,8 @@ class GroupAdmin(admin.ModelAdmin): (None, {"fields": ("name", "celcat_name", "timetable",)}), ("Groupes", {"fields": ("mention", "subgroup", "td", "tp", "parent",)}),) list_display = ("name", "timetable",) - list_filter = ("timetable__name",) + list_filter = ("timetable",) + ordering = ("timetable",) readonly_fields = ("celcat_name", "mention", "subgroup", "td", "tp",) @@ -60,5 +61,5 @@ class CourseAdmin(admin.ModelAdmin): ("Horaires", {"fields": ("begin", "end",)}), ("Remarques", {"fields": ("notes",)}),) list_display = ("name", "type", "timetable", "begin", "end",) - list_filter = ("type", "timetable__name", "groups",) + list_filter = ("type", "timetable", "groups",) ordering = ("begin",) -- cgit v1.2.1 From 5490a366c2acba45cc617a825904ba95eeb6b374 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Tue, 12 Sep 2017 21:42:52 +0200 Subject: Ajout d’une page contact. L’adresse email est brouillée. --- templates/contact.html | 9 +++++++++ templates/index.html | 2 +- templatetags/email.py | 24 ++++++++++++++++++++++++ urls.py | 1 + views.py | 4 ++++ 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 templates/contact.html create mode 100644 templatetags/email.py diff --git a/templates/contact.html b/templates/contact.html new file mode 100644 index 0000000..1359a16 --- /dev/null +++ b/templates/contact.html @@ -0,0 +1,9 @@ +{% extends "index.html" %} +{% load email %} + +{% block title %}Contacter – {% endblock %} + +{% block body %} +
Pour contacter l’administrateur du service, envoyez un mail à l’adresse suivante :
{{ email|format_email }}.