Skip to content

Commit

Permalink
Merge pull request #89 from planetterp/gened-schema
Browse files Browse the repository at this point in the history
Course schema changes to support new gened format
  • Loading branch information
tybug authored Feb 20, 2023
2 parents a3321a7 + 9344932 commit 4fe3fa0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
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)

def __str__(self):
return self.name

Expand Down

0 comments on commit 4fe3fa0

Please sign in to comment.