aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--feeds.py39
-rw-r--r--models.py54
2 files changed, 72 insertions, 21 deletions
diff --git a/feeds.py b/feeds.py
index 19c9e47..ff00066 100644
--- a/feeds.py
+++ b/feeds.py
@@ -28,7 +28,8 @@ from .models import Course, Group
from .templatetags.rooms import format_rooms
from .utils import get_current_or_next_week, get_week, group_courses
-ICAL_NAMES = ["uid", "summary", "description", "location", "start", "dtstart", "dtend", "dtstamp"]
+ICAL_NAMES = ["uid", "summary", "description", "location",
+ "start", "dtstart", "dtend", "dtstamp"]
class IcalFeedGenerator(SyndicationFeed):
@@ -57,7 +58,9 @@ class IcalFeed(Feed):
def get_object(self, request, year_slug, timetable_slug, group_slug):
try:
- group = Group.objects.get(timetable__year__slug=year_slug, timetable__slug=timetable_slug, slug=group_slug)
+ group = Group.objects.get(timetable__year__slug=year_slug,
+ timetable__slug=timetable_slug,
+ slug=group_slug)
except:
raise ObjectDoesNotExist
else:
@@ -87,16 +90,28 @@ class RSSFeed(Feed):
begin, end = get_week(year, week)
try:
- group = Group.objects.get(timetable__year__slug=year_slug, timetable__slug=timetable_slug, slug=group_slug)
+ group = Group.objects.get(timetable__year__slug=year_slug,
+ timetable__slug=timetable_slug,
+ slug=group_slug)
except:
raise ObjectDoesNotExist
else:
- updates = Course.objects.get_courses_for_group(group, begin__lt=end).annotate(year=ExtractYear("begin"), week=ExtractWeek("begin")).values("year", "week").annotate(Count("year", distinct=True), Max("last_update")).order_by("-year", "-week")[:5]
+ updates = Course.objects.get_courses_for_group(group,
+ begin__lt=end) \
+ .annotate(year=ExtractYear("begin"),
+ week=ExtractWeek("begin")) \
+ .values("year", "week") \
+ .annotate(Count("year", distinct=True),
+ Max("last_update")) \
+ .order_by("-year", "-week")[:5]
return group, updates
def link(self, obj):
group = obj[0]
- link = reverse("timetable", kwargs={"year_slug": group.timetable.year.slug, "timetable_slug": group.timetable.slug, "group_slug": group.slug})
+ link = reverse("timetable",
+ kwargs={"year_slug": group.timetable.year.slug,
+ "timetable_slug": group.timetable.slug,
+ "group_slug": group.slug})
return link
def title(self, obj):
@@ -115,7 +130,9 @@ class RSSFeed(Feed):
return item["description"]
def item_title(self, item):
- return "{0}, semaine {1} de {2}".format(item["group"], item["week"], item["year"])
+ return "{0}, semaine {1} de {2}".format(item["group"],
+ item["week"],
+ item["year"])
def item_updateddate(self, item):
return item["last_update__max"]
@@ -126,8 +143,14 @@ class RSSFeed(Feed):
for update in obj[1]:
start, end = get_week(update["year"], update["week"])
- courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end)
- context = {"group": group, "courses": group_courses(courses), "last_update": update["last_update__max"], "year": update["year"], "week": update["week"]}
+ courses = Course.objects.get_courses_for_group(group,
+ begin__gte=start,
+ begin__lt=end)
+ context = {"group": group,
+ "courses": group_courses(courses),
+ "last_update": update["last_update__max"],
+ "year": update["year"],
+ "week": update["week"]}
update["group"] = group
update["description"] = template.render(context)
diff --git a/models.py b/models.py
index b1d6d27..4be7ef5 100644
--- a/models.py
+++ b/models.py
@@ -48,7 +48,8 @@ class Year(SlugModel):
class Timetable(SlugModel):
- year = models.ForeignKey(Year, on_delete=models.CASCADE, verbose_name="année")
+ 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")
slug = models.SlugField(max_length=64, default="")
@@ -65,26 +66,36 @@ class Timetable(SlugModel):
class GroupManager(Manager):
def get_relevant_groups(self, *args, **criteria):
- return self.get_queryset().filter(*args, **criteria).annotate(children_count=Count("children")).filter(children_count=0)
+ return self.get_queryset().filter(*args, **criteria) \
+ .annotate(children_count=Count("children")) \
+ .filter(children_count=0)
class Group(models.Model):
objects = GroupManager()
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")
+ 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=128)
- subgroup = models.CharField(max_length=1, verbose_name="sous-groupe", null=True)
+ subgroup = models.CharField(max_length=1, verbose_name="sous-groupe",
+ null=True)
td = models.IntegerField(verbose_name="groupe de TD", null=True)
tp = models.IntegerField(verbose_name="groupe de TP", null=True)
- parent = models.ForeignKey("self", verbose_name="groupe parent", null=True, default=None, related_name="children")
+ parent = models.ForeignKey("self", verbose_name="groupe parent", null=True,
+ default=None, related_name="children")
slug = models.SlugField(max_length=64, default="")
def corresponds_to(self, timetable_id, mention, subgroup, td, tp):
- return self.timetable.id == timetable_id and self.mention.startswith(mention) and (self.subgroup == subgroup or self.subgroup is None) and (self.td == td or self.td is None or td is None) and (self.tp == tp or self.tp is None or tp is None)
+ return self.timetable.id == timetable_id and \
+ self.mention.startswith(mention) and \
+ (self.subgroup == subgroup or self.subgroup is None) and \
+ (self.td == td or self.td is None or td is None) and \
+ (self.tp == tp or self.tp is None or tp is None)
@property
def group_info(self):
@@ -104,7 +115,9 @@ class Group(models.Model):
class Meta:
index_together = ("mention", "subgroup", "td", "tp",)
- unique_together = (("name", "timetable",), ("celcat_name", "timetable",), ("slug", "timetable",),)
+ unique_together = (("name", "timetable",),
+ ("celcat_name", "timetable",),
+ ("slug", "timetable",),)
verbose_name = "groupe"
verbose_name_plural = "groupes"
@@ -124,18 +137,32 @@ class Room(models.Model):
class CourseManager(Manager):
def get_courses_for_group(self, group, **criteria):
- return self.get_queryset().filter(Q(groups__td__isnull=True) | Q(groups__td=group.td), Q(groups__tp__isnull=True) | Q(groups__tp=group.tp), Q(groups__subgroup__isnull=True) | Q(groups__subgroup=group.subgroup), groups__mention=group.mention, timetable=group.timetable, **criteria).order_by("begin")
+ return self.get_queryset() \
+ .filter(Q(groups__td__isnull=True) | Q(groups__td=group.td),
+ Q(groups__tp__isnull=True) | Q(groups__tp=group.tp),
+ Q(groups__subgroup__isnull=True) | \
+ Q(groups__subgroup=group.subgroup),
+ groups__mention=group.mention,
+ timetable=group.timetable, **criteria) \
+ .order_by("begin")
def get_weeks(self, **criteria):
- return self.get_queryset().filter(**criteria).order_by("groups__name", "year", "week").annotate(_=Count(("groups", "year", "week", "begin")), year=ExtractYear("begin"), week=ExtractWeek("begin"))
+ return self.get_queryset() \
+ .filter(**criteria) \
+ .order_by("groups__name", "year", "week") \
+ .annotate(_=Count(("groups", "year", "week", "begin")),
+ year=ExtractYear("begin"),
+ week=ExtractWeek("begin"))
class Course(models.Model):
objects = CourseManager()
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")
+ 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")
@@ -144,7 +171,8 @@ class Course(models.Model):
begin = models.DateTimeField(verbose_name="début du cours", db_index=True)
end = models.DateTimeField(verbose_name="fin du cours")
- last_update = models.DateTimeField(verbose_name="dernière mise à jour", default=timezone.now)
+ last_update = models.DateTimeField(verbose_name="dernière mise à jour",
+ default=timezone.now)
def __str__(self):
return self.name