Skip to content

Commit 1cdf8fa

Browse files
committed
linting
1 parent 4605ae0 commit 1cdf8fa

File tree

12 files changed

+281
-187
lines changed

12 files changed

+281
-187
lines changed
Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
# Generated by Django 3.2.23 on 2024-01-21 00:14
22

3+
import django.db.models.deletion
34
from django.conf import settings
45
from django.db import migrations, models
5-
import django.db.models.deletion
66

77

88
class Migration(migrations.Migration):
99

1010
dependencies = [
1111
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12-
('courses', '0063_auto_20231212_1750'),
12+
("courses", "0063_auto_20231212_1750"),
1313
]
1414

1515
operations = [
1616
migrations.AlterField(
17-
model_name='section',
18-
name='activity',
19-
field=models.CharField(choices=[('', 'Undefined'), ('CLN', 'Clinic'), ('CRT', 'Clinical Rotation'), ('DAB', 'Dissertation Abroad'), ('DIS', 'Dissertation'), ('DPC', 'Doctoral Program Exchange'), ('FLD', 'Field Work'), ('HYB', 'Hybrid'), ('IND', 'Independent Study'), ('LAB', 'Lab'), ('LEC', 'Lecture'), ('MST', 'Masters Thesis'), ('ONL', 'Online'), ('PRC', 'Practicum'), ('REC', 'Recitation'), ('SEM', 'Seminar'), ('SRT', 'Senior Thesis'), ('STU', 'Studio')], db_index=True, help_text='The section activity, e.g. `LEC` for CIS-120-001 (2020A). Options and meanings: <table width=100%><tr><td>""</td><td>"Undefined"</td></tr><tr><td>"CLN"</td><td>"Clinic"</td></tr><tr><td>"CRT"</td><td>"Clinical Rotation"</td></tr><tr><td>"DAB"</td><td>"Dissertation Abroad"</td></tr><tr><td>"DIS"</td><td>"Dissertation"</td></tr><tr><td>"DPC"</td><td>"Doctoral Program Exchange"</td></tr><tr><td>"FLD"</td><td>"Field Work"</td></tr><tr><td>"HYB"</td><td>"Hybrid"</td></tr><tr><td>"IND"</td><td>"Independent Study"</td></tr><tr><td>"LAB"</td><td>"Lab"</td></tr><tr><td>"LEC"</td><td>"Lecture"</td></tr><tr><td>"MST"</td><td>"Masters Thesis"</td></tr><tr><td>"ONL"</td><td>"Online"</td></tr><tr><td>"PRC"</td><td>"Practicum"</td></tr><tr><td>"REC"</td><td>"Recitation"</td></tr><tr><td>"SEM"</td><td>"Seminar"</td></tr><tr><td>"SRT"</td><td>"Senior Thesis"</td></tr><tr><td>"STU"</td><td>"Studio"</td></tr></table>', max_length=50),
17+
model_name="section",
18+
name="activity",
19+
field=models.CharField(
20+
choices=[
21+
("", "Undefined"),
22+
("CLN", "Clinic"),
23+
("CRT", "Clinical Rotation"),
24+
("DAB", "Dissertation Abroad"),
25+
("DIS", "Dissertation"),
26+
("DPC", "Doctoral Program Exchange"),
27+
("FLD", "Field Work"),
28+
("HYB", "Hybrid"),
29+
("IND", "Independent Study"),
30+
("LAB", "Lab"),
31+
("LEC", "Lecture"),
32+
("MST", "Masters Thesis"),
33+
("ONL", "Online"),
34+
("PRC", "Practicum"),
35+
("REC", "Recitation"),
36+
("SEM", "Seminar"),
37+
("SRT", "Senior Thesis"),
38+
("STU", "Studio"),
39+
],
40+
db_index=True,
41+
help_text='The section activity, e.g. `LEC` for CIS-120-001 (2020A). Options and meanings: <table width=100%><tr><td>""</td><td>"Undefined"</td></tr><tr><td>"CLN"</td><td>"Clinic"</td></tr><tr><td>"CRT"</td><td>"Clinical Rotation"</td></tr><tr><td>"DAB"</td><td>"Dissertation Abroad"</td></tr><tr><td>"DIS"</td><td>"Dissertation"</td></tr><tr><td>"DPC"</td><td>"Doctoral Program Exchange"</td></tr><tr><td>"FLD"</td><td>"Field Work"</td></tr><tr><td>"HYB"</td><td>"Hybrid"</td></tr><tr><td>"IND"</td><td>"Independent Study"</td></tr><tr><td>"LAB"</td><td>"Lab"</td></tr><tr><td>"LEC"</td><td>"Lecture"</td></tr><tr><td>"MST"</td><td>"Masters Thesis"</td></tr><tr><td>"ONL"</td><td>"Online"</td></tr><tr><td>"PRC"</td><td>"Practicum"</td></tr><tr><td>"REC"</td><td>"Recitation"</td></tr><tr><td>"SEM"</td><td>"Seminar"</td></tr><tr><td>"SRT"</td><td>"Senior Thesis"</td></tr><tr><td>"STU"</td><td>"Studio"</td></tr></table>',
42+
max_length=50,
43+
),
2044
)
2145
]

backend/courses/migrations/0066_merge_20240426_0627.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
class Migration(migrations.Migration):
77

88
dependencies = [
9-
('courses', '0064_auto_20240120_1914'),
10-
('courses', '0065_topic_historical_probabilities_fall_and_more'),
9+
("courses", "0064_auto_20240120_1914"),
10+
("courses", "0065_topic_historical_probabilities_fall_and_more"),
1111
]
1212

13-
operations = [
14-
]
13+
operations = []
Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,82 @@
11
# Generated by Django 3.2.23 on 2024-04-26 10:27
22

3+
import django.db.models.deletion
34
from django.conf import settings
45
from django.db import migrations, models
5-
import django.db.models.deletion
66

77

88
class Migration(migrations.Migration):
99

1010
dependencies = [
1111
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12-
('courses', '0066_merge_20240426_0627'),
12+
("courses", "0066_merge_20240426_0627"),
1313
]
1414

1515
operations = [
1616
migrations.CreateModel(
17-
name='Comment',
17+
name="Comment",
1818
fields=[
19-
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20-
('text', models.TextField()),
21-
('created_at', models.DateTimeField(auto_now_add=True)),
22-
('modified_at', models.DateTimeField(auto_now=True)),
23-
('path', models.TextField(db_index=True)),
24-
('author', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='comments', to=settings.AUTH_USER_MODEL)),
25-
('base', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='courses.comment')),
26-
('downvotes', models.ManyToManyField(help_text='The number of downvotes a comment gets.', related_name='downvotes', to=settings.AUTH_USER_MODEL)),
27-
('parent', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='children', to='courses.comment')),
28-
('section', models.ForeignKey(help_text='\nThe section with which a comment is associated. Section was chosen instead of topics for\nhosting comments because topics are SOFT STATE and are recomputed regularly.\n', null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.section')),
29-
('upvotes', models.ManyToManyField(help_text='The number of upvotes a comment gets.', related_name='upvotes', to=settings.AUTH_USER_MODEL)),
19+
(
20+
"id",
21+
models.AutoField(
22+
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
23+
),
24+
),
25+
("text", models.TextField()),
26+
("created_at", models.DateTimeField(auto_now_add=True)),
27+
("modified_at", models.DateTimeField(auto_now=True)),
28+
("path", models.TextField(db_index=True)),
29+
(
30+
"author",
31+
models.ForeignKey(
32+
null=True,
33+
on_delete=django.db.models.deletion.SET_NULL,
34+
related_name="comments",
35+
to=settings.AUTH_USER_MODEL,
36+
),
37+
),
38+
(
39+
"base",
40+
models.ForeignKey(
41+
null=True,
42+
on_delete=django.db.models.deletion.SET_NULL,
43+
to="courses.comment",
44+
),
45+
),
46+
(
47+
"downvotes",
48+
models.ManyToManyField(
49+
help_text="The number of downvotes a comment gets.",
50+
related_name="downvotes",
51+
to=settings.AUTH_USER_MODEL,
52+
),
53+
),
54+
(
55+
"parent",
56+
models.ForeignKey(
57+
null=True,
58+
on_delete=django.db.models.deletion.SET_NULL,
59+
related_name="children",
60+
to="courses.comment",
61+
),
62+
),
63+
(
64+
"section",
65+
models.ForeignKey(
66+
help_text="\nThe section with which a comment is associated. Section was chosen instead of topics for\nhosting comments because topics are SOFT STATE and are recomputed regularly.\n",
67+
null=True,
68+
on_delete=django.db.models.deletion.CASCADE,
69+
to="courses.section",
70+
),
71+
),
72+
(
73+
"upvotes",
74+
models.ManyToManyField(
75+
help_text="The number of upvotes a comment gets.",
76+
related_name="upvotes",
77+
to=settings.AUTH_USER_MODEL,
78+
),
79+
),
3080
],
3181
),
3282
]

backend/courses/models.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from PennCourses.settings.base import FIRST_BANNER_SEM, PRE_NGSS_PERMIT_REQ_RESTRICTION_CODES
1616
from review.annotations import review_averages
1717

18+
1819
User = get_user_model()
1920

2021

@@ -1540,6 +1541,7 @@ def __str__(self):
15401541
f"Friendship(Sender: {self.sender}, Recipient: {self.recipient}, Status: {self.status})"
15411542
)
15421543

1544+
15431545
class Comment(models.Model):
15441546
"""
15451547
A single comment associated with a topic to be displayed on PCR. Comments support replies
@@ -1555,20 +1557,15 @@ class Comment(models.Model):
15551557
created_at = models.DateTimeField(auto_now_add=True)
15561558
modified_at = models.DateTimeField(auto_now=True)
15571559
author = models.ForeignKey(
1558-
get_user_model(),
1559-
on_delete = models.SET_NULL,
1560-
null=True,
1561-
related_name="comments"
1560+
get_user_model(), on_delete=models.SET_NULL, null=True, related_name="comments"
15621561
)
15631562
upvotes = models.ManyToManyField(
1564-
get_user_model(),
1565-
related_name="upvotes",
1566-
help_text="The number of upvotes a comment gets."
1563+
get_user_model(), related_name="upvotes", help_text="The number of upvotes a comment gets."
15671564
)
15681565
downvotes = models.ManyToManyField(
15691566
get_user_model(),
15701567
related_name="downvotes",
1571-
help_text="The number of downvotes a comment gets."
1568+
help_text="The number of downvotes a comment gets.",
15721569
)
15731570
section = models.ForeignKey(
15741571
Section,
@@ -1579,25 +1576,22 @@ class Comment(models.Model):
15791576
hosting comments because topics are SOFT STATE and are recomputed regularly.
15801577
"""
15811578
),
1582-
null=True
1579+
null=True,
15831580
)
15841581

15851582
base = models.ForeignKey(
15861583
"self",
1587-
on_delete=models.SET_NULL, # redundant due to special deletion conditions
1584+
on_delete=models.SET_NULL, # redundant due to special deletion conditions
15881585
null=True,
15891586
)
15901587
parent = models.ForeignKey(
1591-
"self",
1592-
on_delete=models.SET_NULL, # similarly redundant
1593-
null=True,
1594-
related_name="children"
1588+
"self", on_delete=models.SET_NULL, null=True, related_name="children" # similarly redundant
15951589
)
15961590
path = models.TextField(db_index=True)
15971591

15981592
def level(self):
1599-
return len(self.path.split('.'))
1600-
1593+
return len(self.path.split("."))
1594+
16011595
def delete(self, **kwargs):
16021596
if Comment.objects.filter(parent_id=self).exists():
16031597
self.text = "This comment has been removed."
@@ -1607,5 +1601,6 @@ def delete(self, **kwargs):
16071601
self.save()
16081602
else:
16091603
super().delete(**kwargs)
1604+
16101605
def __str__(self):
1611-
return f"{self.author}: {self.text}"
1606+
return f"{self.author}: {self.text}"

backend/courses/serializers.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from courses.models import (
77
Attribute,
8+
Comment,
89
Course,
910
Friendship,
1011
Instructor,
@@ -14,7 +15,6 @@
1415
Section,
1516
StatusUpdate,
1617
UserProfile,
17-
Comment
1818
)
1919
from plan.management.commands.recommendcourses import cosine_similarity
2020

@@ -477,6 +477,7 @@ class FriendshipRequestSerializer(serializers.Serializer):
477477
def to_representation(self, instance):
478478
return super().to_representation(instance)
479479

480+
480481
class CommentSerializer(serializers.ModelSerializer):
481482
author_name = serializers.CharField(source="author.username", read_only=True)
482483
votes = serializers.SerializerMethodField()
@@ -485,19 +486,33 @@ class CommentSerializer(serializers.ModelSerializer):
485486
parent = serializers.SerializerMethodField()
486487

487488
def get_votes(self, obj):
488-
return len(obj.upvotes.values_list('id')) - len(obj.downvotes.values_list('id'))
489+
return len(obj.upvotes.values_list("id")) - len(obj.downvotes.values_list("id"))
490+
489491
def get_base(self, obj):
490492
if obj.base is None:
491493
return None
492494
return obj.base.id
495+
493496
def get_parent(self, obj):
494497
if obj.parent is None:
495498
return None
496499
return obj.parent.id
497500

498501
class Meta:
499502
model = Comment
500-
fields = ['id', 'text', 'created_at', 'modified_at', 'author_name', 'votes', 'section', 'base', 'parent', 'path']
503+
fields = [
504+
"id",
505+
"text",
506+
"created_at",
507+
"modified_at",
508+
"author_name",
509+
"votes",
510+
"section",
511+
"base",
512+
"parent",
513+
"path",
514+
]
515+
501516

502517
class CommentListSerializer(serializers.ModelSerializer):
503518
author_name = serializers.CharField(source="author.username", read_only=True)
@@ -509,16 +524,31 @@ class CommentListSerializer(serializers.ModelSerializer):
509524
user_downvoted = serializers.BooleanField()
510525

511526
def get_votes(self, obj):
512-
return len(obj.upvotes.values_list('id')) - len(obj.downvotes.values_list('id'))
527+
return len(obj.upvotes.values_list("id")) - len(obj.downvotes.values_list("id"))
528+
513529
def get_base(self, obj):
514530
if obj.base is None:
515531
return None
516532
return obj.base.id
533+
517534
def get_parent(self, obj):
518535
if obj.parent is None:
519536
return None
520537
return obj.parent.id
521538

522539
class Meta:
523540
model = Comment
524-
fields = ['id', 'text', 'created_at', 'modified_at', 'author_name', 'votes', 'section', 'base', 'parent', 'path', 'user_upvoted', 'user_downvoted']
541+
fields = [
542+
"id",
543+
"text",
544+
"created_at",
545+
"modified_at",
546+
"author_name",
547+
"votes",
548+
"section",
549+
"base",
550+
"parent",
551+
"path",
552+
"user_upvoted",
553+
"user_downvoted",
554+
]

backend/courses/util.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,30 +723,34 @@ def get_semesters(semesters: str = None) -> list[str]:
723723
raise ValueError(f"Provided semester {s} was not found in the db.")
724724
return sorted(semesters)
725725

726+
726727
def get_section_from_course_instructor_semester(course_code, professors, semester):
727728
"""
728729
Attempts to return a course section that matches the given parameters.
729730
ValueError is raised if the section does not exist.
730731
"""
731-
732+
732733
course_candidate = Course.objects.filter(full_code=course_code).first()
733734
if not course_candidate:
734735
raise ValueError(f"No course exists with code ({course_code})")
735736
course_topic = course_candidate.topic
736737
if not course_topic:
737738
raise ValueError(f"No topic exists for course with code ({course_code})")
738739
course_topic_parent = course_topic.most_recent.full_code
739-
sections = Section.objects.prefetch_related('instructors').filter(
740-
course__topic__most_recent__full_code = course_topic_parent,
741-
course__semester = semester
740+
sections = Section.objects.prefetch_related("instructors").filter(
741+
course__topic__most_recent__full_code=course_topic_parent, course__semester=semester
742742
)
743743
professors_query = Q(instructors__name=professors[0])
744744
for professor in professors[1:]:
745745
professors_query &= Q(instructors__name=professor)
746746
matching_sections = sections.filter(professors_query).distinct()
747747
if matching_sections.count() == 1:
748748
return matching_sections.first()
749-
raise ValueError(f"No section exists with course code ({course_code}), professor ({professors[0]}), semester ({semester})")
749+
raise ValueError(
750+
f"""No section exists with course code ({course_code}), professor ({professors[0]}),
751+
semester ({semester})"""
752+
)
753+
750754

751755
def historical_semester_probability(current_semester: str, semesters: list[str]):
752756
"""

backend/review/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
12
from django.db import models
23
from django.db.models import Avg, Q
3-
from django.contrib.auth import get_user_model
4-
from textwrap import dedent
4+
55

66
class Review(models.Model):
77
"""
@@ -119,4 +119,4 @@ class Meta:
119119
unique_together = (("review", "field"),)
120120

121121
def __str__(self):
122-
return f"#{self.review.pk} - {self.field}: {self.average}"
122+
return f"#{self.review.pk} - {self.field}: {self.average}"

backend/review/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ class ReviewSerializer(serializers.ModelSerializer):
1717

1818
class Meta:
1919
model = Review
20-
fields = ("section", "instructor")
20+
fields = ("section", "instructor")

0 commit comments

Comments
 (0)