aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--admin.py4
-rw-r--r--management/parsers/ups2018.py9
-rw-r--r--models.py13
3 files changed, 23 insertions, 3 deletions
diff --git a/admin.py b/admin.py
index c40a148..5350aad 100644
--- a/admin.py
+++ b/admin.py
@@ -14,7 +14,7 @@
# along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>.
from django.contrib import admin
-from .models import Course, Group, Room, Source, Timetable, Year
+from .models import Course, Group, Module, Room, Source, Timetable, Year
def make_hidden(modeladmin, request, queryset):
@@ -62,7 +62,7 @@ class GroupAdmin(admin.ModelAdmin):
actions = (make_hidden, make_visible,)
-@admin.register(Room)
+@admin.register(Room, Module)
class RoomAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("name",)}
list_display = ("name",)
diff --git a/management/parsers/ups2018.py b/management/parsers/ups2018.py
index e3afbe5..afbfc4b 100644
--- a/management/parsers/ups2018.py
+++ b/management/parsers/ups2018.py
@@ -26,7 +26,7 @@ from django.utils import timezone
import lxml.html
import requests
-from ...models import Course, Group, Room
+from ...models import Course, Group, Module, Room
from ...utils import get_current_week, get_week
from .abstractparser import AbstractParser, ParserError
@@ -137,6 +137,13 @@ class Parser(AbstractParser):
# par un dictionnaire classique.
names = OrderedDict.fromkeys(data[i - 1].split(';'))
course.name = ", ".join(names.keys())
+
+ module_names = [t for t in event["tag"]
+ if len(t) > 0 and
+ any(n.startswith(t) for n in names.keys())]
+ if len(module_names) > 0:
+ module, _ = Module.objects.get_or_create(name=module_names[0])
+ course.module = module
else:
course.name = "Sans nom"
if i - 2 >= min_i:
diff --git a/models.py b/models.py
index b1a6a1e..b59f2d8 100644
--- a/models.py
+++ b/models.py
@@ -200,6 +200,18 @@ class Room(SlugModel):
verbose_name_plural = "salles"
+class Module(SlugModel):
+ name = models.CharField(max_length=255, unique=True, verbose_name="nom")
+ slug = models.SlugField(max_length=64, default="", unique=True)
+
+ def __str__(self):
+ return self.name
+
+ class Meta:
+ verbose_name = "module"
+ verbose_name_plural = "modules"
+
+
class CourseManager(Manager):
def get_courses(self, obj, **criteria):
qs = self.get_queryset()
@@ -247,6 +259,7 @@ class Course(models.Model):
default=timezone.now)
celcat_id = models.IntegerField(verbose_name="ID Celcat", null=True)
+ module = models.ForeignKey(Module, on_delete=models.SET_NULL, null=True)
def __str__(self):
return self.name