Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Course schema changes to support new gened format #89

Merged
merged 3 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions home/migrations/0007_course_geneds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.4 on 2023-02-07 17:50

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.JSONField(null=True),
),
]
17 changes: 15 additions & 2 deletions home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = JSONField(null=True)
professors = ManyToManyField("Professor", blank=True,
through="ProfessorCourse")

Expand Down Expand Up @@ -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 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)

Comment on lines +222 to +234
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this change would have fit better in #91.

def __str__(self):
return self.name

Expand Down