Utilities

General utilities.

codePost Utilities

Utilities involving the codePost SDK.

@codepost_powertools.utils.codepost_utils.with_course

Decorates a function to fetch a course before calling.

This decorator will fetch a Course if necessary to call the decorated function.

func(course: CourseArg, *args, **kwargs) -> RT
# becomes
func(course: Course | None, *args, **kwargs) -> RT

If the retrieval is unsuccessful, course will be passed as None, which the function should handle itself.

New in version 0.1.0.

@codepost_powertools.utils.codepost_utils.with_course_and_assignment

Decorates a function to fetch a course and assignment before calling.

This decorator will fetch a Course and Assignment if necessary to call the decorated function.

func(
  course: CourseArg, assignment: AssignmentArg,
  *args, **kwargs
) -> RT
# becomes
func(
  course: Course | None, assignment: Assignment | None,
  *args, **kwargs
) -> RT

If any retrievals are unsuccessful, course and assignment will both be passed as None, which the function should handle itself.

New in version 0.1.0.

codepost_powertools.utils.codepost_utils.get_course(name, period, *, log=False)

Gets a codePost course.

If there are multiple courses with the same name and period, the first one found is returned.

Parameters:
  • name (str) – The course name.

  • period (str) – The course period.

  • log (bool) – Whether to show log messages.

Returns:

The course.

Return type:

SuccessOrNone [Course]

Raises:

ValueError – If no course is found.

New in version 0.1.0.

codepost_powertools.utils.codepost_utils.course_str(course, *, delim=' ')

Returns a str representation of a course.

Parameters:
  • course (Course) – The course.

  • delim (str) – A delimiting string between the name and the period.

Returns:

A string representation of the course.

Return type:

str

New in version 0.1.0.

codepost_powertools.utils.codepost_utils.get_course_roster(course, *, log=False)

Gets the roster for the given course.

Parameters:
  • course (CourseArg) – The course.

  • log (bool) – Whether to show log messages.

Returns:

The roster.

Return type:

SuccessOrNone [Roster]

New in version 0.1.0.

codepost_powertools.utils.codepost_utils.get_assignment(course, assignment_name, *, log=False)

Gets a codePost assignment from a course.

If there are multiple assignments with the same name, the first one found is returned.

Parameters:
  • course (CourseArg) – The course.

  • assignment_name (str) – The assignment name.

  • log (bool) – Whether to show log messages.

Returns:

The assignment.

Return type:

SuccessOrNone [Assignment]

Raises:

ValueError – If the assignment is not found.

New in version 0.1.0.