Skip to content

Commit

Permalink
Merge pull request #621 from pennlabs/aag/fixes
Browse files Browse the repository at this point in the history
PDP Fixes
  • Loading branch information
AaDalal authored Apr 7, 2024
2 parents 2528051 + 1be2fb8 commit d668040
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 29 deletions.
3 changes: 2 additions & 1 deletion backend/degree/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ class Meta:

class DockedCourseSerializer(serializers.ModelSerializer):
id = serializers.ReadOnlyField(help_text="The id of the docked course")
person = serializers.HiddenField(default=serializers.CurrentUserDefault())

class Meta:
model = DockedCourse
fields = ["full_code", "id"]
fields = ["full_code", "id", "person"]
31 changes: 16 additions & 15 deletions backend/degree/utils/parse_degreeworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,30 @@ def parse_coursearray(courseArray) -> Q:
case ("@", "@", end) | ("PSEUDO@", "@", end):
assert end is None
logging.info("ignoring @ course")
pass
case discipline, "@", end:
assert end is None
course_q &= Q(department__code=discipline)
case "@", number, None:
assert "@" not in number
course_q &= Q(code=number)
case discipline, number, None:
if number.isdigit():
if "@" not in number:
course_q &= Q(full_code=f"{discipline}-{number}")
elif number[:-1].isdigit() and number[-1] == "@":
course_q &= Q(full_code__startswith=f"{discipline}-{number[:-1]}")
else:
logging.warn(f"Non-integer course number: {number}")
case "@", number, end:
assert "@" not in number and "@" not in end
course_q &= Q(
code__gte=number.strip(),
code__lte=end.strip(),
)
case discipline, number, end:
if number.isdigit() and end.isdigit():
course_q &= Q(
department__code=discipline,
code__gte=number.strip(),
code__lte=end.strip(),
)
else:
logging.warn(
f"Non-integer course number or numberEnd: "
f"(number) {number} (numberEnd) {end}"
)
assert "@" not in number and "@" not in end
course_q &= Q(
department__code=discipline,
code__gte=number.strip(),
code__lte=end.strip(),
)

connector = "AND" # the connector to the next element; and by default
if "withArray" in course:
Expand Down
1 change: 0 additions & 1 deletion backend/degree/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ def create(self, request, *args, **kwargs):
if request.data.get("full_code") is None:
raise ValidationError({"full_code": "This field is required."})
self.kwargs["full_code"] = request.data["full_code"]
self.kwargs["person"] = self.request.user
try:
return self.partial_update(request, *args, **kwargs)
except Http404:
Expand Down
9 changes: 4 additions & 5 deletions backend/tests/degree/test_degreeworks_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ def test_course_range(self):
{"discipline": "BIBB", "number": "2000", "numberEnd": "2999"},
]
expected = Q(department__code="BIBB", code__gte="2000", code__lte="2999")
print("****TS")
print(expected, parse_degreeworks.parse_coursearray(course_array))
self.assertEqual(expected, parse_degreeworks.parse_coursearray(course_array))

Expand All @@ -223,16 +222,16 @@ def test_empty_course(self):

def test_non_int_course(self):
course_array = [
{"discipline": "CIS", "number": "not-a-number"},
{"discipline": "CIS", "number": "4999A"},
]
expected = Q()
expected = Q(full_code="CIS-4999A")
self.assertEqual(expected, parse_degreeworks.parse_coursearray(course_array))

def test_non_int_course_range(self):
course_array = [
{"discipline": "CIS", "number": "not-a-number", "numberEnd": "also-not-a-number"},
{"discipline": "CIS", "number": "4999A", "numberEnd": "4999B"},
]
expected = Q()
expected = Q(department__code="CIS", code__gte="4999A", code__lte="4999B")
self.assertEqual(expected, parse_degreeworks.parse_coursearray(course_array))


Expand Down
8 changes: 5 additions & 3 deletions frontend/degree-plan/components/Requirements/QObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const interpolate = <T,>(arr: T[], separator: T) =>
)


type ConditionKey = "full_code" | "semester" | "attributes__code__in" | "department__code" | "full_code__startswith" | "code__gte" | "code__lte" | "department__code__in"
type ConditionKey = "full_code" | "semester" | "attributes__code__in" | "department__code" | "full_code__startswith" | "code__gte" | "code__lte" | "department__code__in" | "code"
interface Condition {
type: 'LEAF';
key: ConditionKey;
Expand Down Expand Up @@ -129,6 +129,8 @@ const SearchConditionInner = ({ q }: SearchConditionInnerProps) => {
display.push(<div>course number &lt;= {compoundCondition['code__lte']}</div>);
} else if ('code__gte' in compoundCondition) {
display.push(<div>course number &gt;= {compoundCondition['code__gte']}</div>);
} else if ('code' in compoundCondition) {
display.push(<div>course number = {compoundCondition['code']}</div>)
}
if ('department__code__in' in compoundCondition) {
const departments = compoundCondition['department__code__in'] as string[];
Expand Down Expand Up @@ -163,7 +165,7 @@ const SearchConditionInner = ({ q }: SearchConditionInnerProps) => {
}

return (
<Row>
<Row $wrap>
{interpolate(display, <CourseOptionsSeparator>{q.type}</CourseOptionsSeparator>)}
</Row>
)
Expand Down Expand Up @@ -195,7 +197,7 @@ const SearchCondition = ({ ruleId, ruleQuery, fulfillments, ruleIsSatisfied, q,
}
setSearchPanelOpen(true);
setSearchFulfillments(fulfillments)
}}>
}}>
<i className="fas fa-search fa-sm"/>
</DarkGrayIcon>
{fulfillments.map(fulfillment => (
Expand Down
6 changes: 3 additions & 3 deletions frontend/degree-plan/pages/OnboardingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ const OnboardingPage = ({
/** Filter major options based on selected schools/degrees */
const majorOptions =
degrees
?.filter((d) => schools.map((s) => s.value).includes(d.degree))
?.filter((d) => d.year == startingYear?.value && schools.map((s) => s.value).includes(d.degree))
.map((degree) => ({
value: degree,
label: createMajorLabel(degree),
}))
.sort((a, b) => a.label.localeCompare(b.label)) || [];
.sort((a, b) => a.label.localeCompare(b.label));
return majorOptions;
}, [schools]);
}, [schools, startingYear]);

const handleAddDegrees = () => {
createDegreeplan({ name: name })
Expand Down
5 changes: 5 additions & 0 deletions frontend/degree-plan/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import { inter } from "@/fonts";
import type { AppProps } from "next/app";
import React from "react";
import { Theme } from "@radix-ui/themes";
import Head from "next/head";

function App({ Component, pageProps }: AppProps) {
return (
<main className={inter.className}>
<Head>
<title>Penn Degree Plan</title>
<meta name="description" content="Penn Degree Plan by Penn Labs" />
</Head>
<Component {...pageProps} />
</main>
);
Expand Down
1 change: 0 additions & 1 deletion frontend/degree-plan/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export default function Document() {
return (
<Html lang="en" style={{backgroundColor:'#F7F9FC'}}>
<Head>
<meta name="description" content="Penn Degree Plan by Penn Labs" />
<link
rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"
Expand Down

0 comments on commit d668040

Please sign in to comment.