Skip to content

Commit

Permalink
adding archived to the api
Browse files Browse the repository at this point in the history
  • Loading branch information
annagav committed Aug 23, 2024
1 parent c2cc7c3 commit 46332fb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
5 changes: 5 additions & 0 deletions courses/serializers/v1/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class Meta:

class BaseCourseRunSerializer(serializers.ModelSerializer):
"""Minimal CourseRun model serializer"""
is_archived = serializers.SerializerMethodField()

def get_is_archived(self, instance):
return instance.is_enrollable and instance.enrollment_end is None and instance.is_past

class Meta:
model = models.CourseRun
Expand All @@ -51,6 +55,7 @@ class Meta:
"upgrade_deadline",
"is_upgradable",
"is_enrollable",
"is_archived",
"is_self_paced",
"run_tag",
"id",
Expand Down
2 changes: 2 additions & 0 deletions courses/serializers/v1/courses_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def test_serialize_course_run():
"approved_flexible_price_exists": False,
"live": True,
"is_self_paced": course_run.is_self_paced,
"is_archived": False,
"certificate_available_date": drf_datetime(
course_run.certificate_available_date
),
Expand Down Expand Up @@ -172,6 +173,7 @@ def test_serialize_course_run_with_course():
"is_upgradable": course_run.is_upgradable,
"is_enrollable": course_run.is_enrollable,
"is_self_paced": False,
"is_archived": False,
"id": course_run.id,
"products": BaseProductSerializer(course_run.products, many=True).data,
"approved_flexible_price_exists": False,
Expand Down
22 changes: 11 additions & 11 deletions frontend/public/src/components/CourseInfoBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
parseDateString,
formatPrettyShortDate
} from "../lib/util"
import { getFirstRelevantRun, isRunArchived } from "../lib/courseApi"
import { getFirstRelevantRun } from "../lib/courseApi"
import moment from "moment-timezone"

import type { BaseCourseRun } from "../flow/courseTypes"
Expand All @@ -26,12 +26,11 @@ type CourseInfoBoxProps = {
* If the run is under the toggle "More Dates" the format is inline and month
* is shortened to 3 letters.
* @param {EnrollmentFlaggedCourseRun} run
* @param {boolean} isArchived if the course ended, but still enrollable
* @param {boolean} isMoreDates true if this run is going to show up under the More Dates toggle
* */

const getCourseDates = (run, isArchived = false, isMoreDates = false) => {
if (isArchived) {
const getCourseDates = (run, isMoreDates = false) => {
if (run.is_archived) {
return (
<>
<span>Course content available anytime</span>
Expand Down Expand Up @@ -164,15 +163,14 @@ export default class CourseInfoBox extends React.PureComponent<CourseInfoBoxProp
const course = courses[0]
const run = getFirstRelevantRun(course, course.courseruns)
const product = run && run.products.length > 0 && run.products[0]
const isArchived = isRunArchived(run)

const startDates = []
const moreEnrollableCourseRuns = enrollableCourseRuns.length > 1
if (moreEnrollableCourseRuns) {
enrollableCourseRuns.forEach((courseRun, index) => {
if (courseRun.id !== run.id) {
startDates.push(
<li key={index}>{getCourseDates(courseRun, isArchived, true)}</li>
<li key={index}>{getCourseDates(courseRun, true)}</li>
)
}
})
Expand All @@ -190,7 +188,9 @@ export default class CourseInfoBox extends React.PureComponent<CourseInfoBoxProp
return (
<>
<div className="enrollment-info-box componentized">
{!run || isArchived ? this.warningMessage(isArchived) : null}
{!run || run.is_archived ?
this.warningMessage(run.is_archived) :
null}
{run ? (
<div className="row d-flex course-timing-message">
<div className="enrollment-info-icon">
Expand All @@ -204,10 +204,10 @@ export default class CourseInfoBox extends React.PureComponent<CourseInfoBoxProp
aria-level="3"
role="heading"
>
{getCourseDates(run, isArchived)}
{getCourseDates(run)}
</div>

{!isArchived && moreEnrollableCourseRuns ? (
{!run.is_archived && moreEnrollableCourseRuns ? (
<>
<button
className="info-link more-info more-dates"
Expand Down Expand Up @@ -244,7 +244,7 @@ export default class CourseInfoBox extends React.PureComponent<CourseInfoBoxProp
role="heading"
>
<b>Course Format: </b>
{isArchived || run.is_self_paced ? (
{run.is_archived || run.is_self_paced ? (
<>
Self-paced
<button
Expand Down Expand Up @@ -307,7 +307,7 @@ export default class CourseInfoBox extends React.PureComponent<CourseInfoBoxProp
<b>Price: </b> <span>Free</span> to Learn
</div>
<div className="enrollment-info-text course-certificate-message">
{run && product && !isArchived ? (
{run && product && !run.is_archived ? (
<>
<span>Certificate Track: </span>
{formatLocalePrice(getFlexiblePriceForProduct(product))}
Expand Down
6 changes: 3 additions & 3 deletions frontend/public/src/components/CourseProductDetailEnroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {

import { formatPrettyDate, emptyOrNil } from "../lib/util"
import moment from "moment-timezone"
import { getFirstRelevantRun, isRunArchived } from "../lib/courseApi"
import { getFirstRelevantRun } from "../lib/courseApi"
import { getCookie } from "../lib/api"
import users, { currentUserSelector } from "../lib/queries/users"
import {
Expand Down Expand Up @@ -419,7 +419,7 @@ export class CourseProductDetailEnroll extends React.Component<
)}`}
className="btn btn-primary btn-enrollment-button btn-lg btn-gradient-red-to-blue highlight"
>
{isRunArchived(run) ? "Access Course Materials" : "Enroll Now"}
{run.is_archived ? "Access Course Materials" : "Enroll Now"}
</a>
</h2>
)
Expand Down Expand Up @@ -469,7 +469,7 @@ export class CourseProductDetailEnroll extends React.Component<
className="btn btn-primary btn-enrollment-button btn-gradient-red-to-blue highlight enroll-now"
disabled={!run.is_enrollable}
>
{isRunArchived(run) ? "Access Course Materials" : "Enroll Now"}
{run.is_archived ? "Access Course Materials" : "Enroll Now"}
</button>
</form>
)}
Expand Down
1 change: 1 addition & 0 deletions frontend/public/src/flow/courseTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type BaseCourseRun = {
upgrade_deadline: ?string,
certificate_available_date: ?string,
is_upgradable: boolean,
is_archived: boolean,
is_enrollable: boolean,
is_self_paced: boolean,
courseware_url: ?string,
Expand Down
8 changes: 0 additions & 8 deletions frontend/public/src/lib/courseApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
notNil,
parseDateString,
formatPrettyDateTimeAmPmTz,
emptyOrNil
} from "./util"

import { NODETYPE_OPERATOR, NODETYPE_COURSE, NODEOPER_ALL } from "../constants"
Expand Down Expand Up @@ -210,13 +209,6 @@ export const learnerProgramIsCompleted = (learnerRecord: LearnerRecord) => {

return requirementsDone && electivesDone
}
export const isRunArchived = (run: CourseRunDetail) => {
return run ?
moment().isAfter(run.end_date) &&
(moment().isBefore(run.enrollment_end) ||
emptyOrNil(run.enrollment_end)) :
false
}

export const getFirstRelevantRun = (
course: CourseDetail,
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export const getStartDateText = (
if (moment(courseRun.start_date).isAfter(moment())) {
return `Starts: ${formatPrettyDate(parseDateString(courseRun.start_date))}`
} else {
if (courseRun.is_self_paced) {
if (courseRun.is_self_paced || courseRun.is_archived) {
return "Start Anytime"
} else {
return `Started: ${formatPrettyDate(
Expand Down

0 comments on commit 46332fb

Please sign in to comment.