From b8859eb55c8c29cbbbc255ca6b7c4266e340c381 Mon Sep 17 00:00:00 2001 From: nsandler1 Date: Mon, 6 Feb 2023 13:39:30 -0500 Subject: [PATCH 1/3] add geneds field to course model --- home/migrations/0007_course_geneds.py | 18 ++++++++++++++++++ home/models.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 home/migrations/0007_course_geneds.py diff --git a/home/migrations/0007_course_geneds.py b/home/migrations/0007_course_geneds.py new file mode 100644 index 00000000..c1f22cde --- /dev/null +++ b/home/migrations/0007_course_geneds.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.4 on 2023-02-06 20:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0006_delete_auditlog'), + ] + + operations = [ + migrations.AddField( + model_name='course', + name='geneds', + field=models.TextField(null=True), + ), + ] diff --git a/home/models.py b/home/models.py index f1c99c0a..59c82528 100644 --- a/home/models.py +++ b/home/models.py @@ -190,7 +190,7 @@ class Course(Model): # indices?). Since recency changes so infrequently, we'll cache it and # update it manually with a custom management command (`updaterecency`). is_recent = BooleanField(default=False) - + geneds = TextField(null=True) professors = ManyToManyField("Professor", blank=True, through="ProfessorCourse") From 03cf7ba6d6d74bd1bc799a98d157d328eaae2de8 Mon Sep 17 00:00:00 2001 From: nsandler1 Date: Mon, 6 Feb 2023 23:57:00 -0500 Subject: [PATCH 2/3] create function to print gened string --- home/models.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/home/models.py b/home/models.py index 59c82528..5ee96f8d 100644 --- a/home/models.py +++ b/home/models.py @@ -219,6 +219,19 @@ def average_gpa(self): def get_absolute_url(self): return reverse("course", kwargs={"name": self.name}) + def gened_str(self): + gened_str = [] + for item in list(self.geneds): + add_parens = len(item) > 1 and len(self.geneds) > 1 + and_str = "(" if add_parens else "" + and_str += " and ".join(item) + and_str += ")" if add_parens else "" + + # special umdio case. EX: https://api.umd.io/v1/courses/CHEM131 + and_str = and_str.replace("|", " if taken with ") + gened_str.append(and_str) + return " or ".join(gened_str) + def __str__(self): return self.name From 934493280b7ec76a4d7c629732402b642fc14fe9 Mon Sep 17 00:00:00 2001 From: nsandler1 Date: Tue, 7 Feb 2023 12:54:31 -0500 Subject: [PATCH 3/3] update schema --- home/migrations/0007_course_geneds.py | 4 ++-- home/models.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/home/migrations/0007_course_geneds.py b/home/migrations/0007_course_geneds.py index c1f22cde..03602fac 100644 --- a/home/migrations/0007_course_geneds.py +++ b/home/migrations/0007_course_geneds.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.4 on 2023-02-06 20:47 +# Generated by Django 3.2.4 on 2023-02-07 17:50 from django.db import migrations, models @@ -13,6 +13,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='course', name='geneds', - field=models.TextField(null=True), + field=models.JSONField(null=True), ), ] diff --git a/home/models.py b/home/models.py index 5ee96f8d..5da200a2 100644 --- a/home/models.py +++ b/home/models.py @@ -9,7 +9,7 @@ from django.db.models import (Model, CharField, DateTimeField, TextField, IntegerField, BooleanField, ForeignKey, PositiveIntegerField, EmailField, CASCADE, ManyToManyField, SlugField, TextChoices, FloatField, Manager, - QuerySet, Sum, UniqueConstraint, Index, Count) + QuerySet, Sum, UniqueConstraint, Index, Count, JSONField) from fuzzywuzzy import fuzz @@ -190,7 +190,7 @@ class Course(Model): # indices?). Since recency changes so infrequently, we'll cache it and # update it manually with a custom management command (`updaterecency`). is_recent = BooleanField(default=False) - geneds = TextField(null=True) + geneds = JSONField(null=True) professors = ManyToManyField("Professor", blank=True, through="ProfessorCourse") @@ -221,7 +221,7 @@ def get_absolute_url(self): def gened_str(self): gened_str = [] - for item in list(self.geneds): + for item in self.geneds: add_parens = len(item) > 1 and len(self.geneds) > 1 and_str = "(" if add_parens else "" and_str += " and ".join(item)