Files
edx-platform/lms/djangoapps/program_enrollments/constants.py
Kyle McCormick da08357d89 Revert "Revert "Create Python API for program_enrollments: Part IV"" (#21759)
This reverts commit a67b9f70a16a0f16a842aad84754b245a2480b5f,
reinstating commit cf78660ed35712f9bb7c112f70411179070d7382.
The original commit was reverted because I thought I found
bugs in it while verifying it on Stage, but it turns out that
it was simply misconfigured Stage data that causing errors.

The original commit's message has has been copied below:

This commit completes the program_enrollments LMS app
Python API for the time being. It does the following:
* Add bulk-lookup of users by external key in api/reading.py
* Add bulk-writing of program enrollments in api/writing.py
* Move grade-reading to api/grades.py
* Refactor api/linking.py to use api/writing.py
* Refactor signals.py to use api/linking.py
* Update rest_api/v1/views.py to utilize all these changes
* Update linking management command and support tool to use API
* Remove outdated tests from test_models.py
* Misc. cleanup

EDUCATOR-4321
2019-09-24 10:49:54 -04:00

116 lines
3.2 KiB
Python

"""
Constants used throughout the program_enrollments app and exposed to other
in-process apps through api.py.
"""
from __future__ import absolute_import, unicode_literals
class ProgramEnrollmentStatuses(object):
"""
Status that a user may have enrolled in a program.
TODO: Define the semantics of each of these (EDUCATOR-4958)
"""
ENROLLED = 'enrolled'
PENDING = 'pending'
SUSPENDED = 'suspended'
CANCELED = 'canceled'
__ACTIVE__ = (ENROLLED, PENDING)
__ALL__ = (ENROLLED, PENDING, SUSPENDED, CANCELED)
# Note: Any changes to this value will trigger a migration on
# ProgramEnrollment!
__MODEL_CHOICES__ = (
(status, status) for status in __ALL__
)
class ProgramCourseEnrollmentStatuses(object):
"""
Status that a user may have enrolled in a course.
TODO: Consider whether we need these (EDUCATOR-4958)
"""
ACTIVE = 'active'
INACTIVE = 'inactive'
__ALL__ = (ACTIVE, INACTIVE)
# Note: Any changes to this value will trigger a migration on
# ProgramCourseEnrollment!
__MODEL_CHOICES__ = (
(status, status) for status in __ALL__
)
class _EnrollmentErrorStatuses(object):
"""
Error statuses common to program and program-course enrollments responses.
"""
# Same student key supplied more than once.
DUPLICATED = 'duplicated'
# Requested target status is invalid
INVALID_STATUS = "invalid-status"
# In the case of a POST request, the enrollment already exists.
CONFLICT = "conflict"
# Although the request is syntactically valid,
# the change being made is not supported.
# For example, it may be illegal to change a user's status back to A
# after changing it to B, where A and B are two hypothetical enrollment
# statuses.
ILLEGAL_OPERATION = "illegal-operation"
# Could not modify program enrollment or create program-course
# enrollment because the student is not enrolled in the program in the
# first place.
NOT_IN_PROGRAM = "not-in-program"
# Something unexpected went wrong.
# If API users are seeing this, we need to investigate.
INTERNAL_ERROR = "internal-error"
__ALL__ = (
DUPLICATED,
INVALID_STATUS,
CONFLICT,
ILLEGAL_OPERATION,
NOT_IN_PROGRAM,
INTERNAL_ERROR,
)
class ProgramOperationStatuses(
ProgramEnrollmentStatuses,
_EnrollmentErrorStatuses,
):
"""
Valid program enrollment operation statuses.
Combines error statuses and OK statuses.
"""
__OK__ = ProgramEnrollmentStatuses.__ALL__
__ERRORS__ = _EnrollmentErrorStatuses.__ALL__
__ALL__ = __OK__ + __ERRORS__
class ProgramCourseOperationStatuses(
ProgramCourseEnrollmentStatuses,
_EnrollmentErrorStatuses,
):
"""
Valid program-course enrollment operation statuses.
Combines error statuses and OK statuses.
"""
# Could not modify program-course enrollment because the user
# is not enrolled in the course in the first place.
NOT_FOUND = "not-found"
__OK__ = ProgramCourseEnrollmentStatuses.__ALL__
__ERRORS__ = (NOT_FOUND,) + _EnrollmentErrorStatuses.__ALL__
__ALL__ = __OK__ + __ERRORS__