Files
edx-platform/lms/djangoapps/course_blocks/utils.py
Pooja Kulkarni 9ddb1cc074 Implement public cohort
This PR is based on #19284 and is part of the
series of work related to the proposal #18134.

This PR avoids the assignment of
anonymous/unenrolled users to any cohort when
course is public. Anonymous or unenrolled users
will only see content that does not have a
content group assigned.
The "View Course" link to the course outline
is shown on the course about page for a course
marked public/public outline.
It also makes course handouts available for
public courses (not for public_outline).
This PR also hides the different warnings and
messages asking the user to sign-in and enroll
in the course, when the course is marked public.
It modifies the default public_view text to
include the component display_name when
unenrolled access is not available.
2019-02-07 21:42:21 +05:30

37 lines
844 B
Python

"""
Common utilities for use along with the course blocks.
"""
import json
from courseware.models import StudentModule
def get_student_module_as_dict(user, course_key, block_key):
"""
Get the student module as a dict for the given user for the given block.
Arguments:
user (User)
course_key (CourseLocator)
block_key (BlockUsageLocator)
Returns:
StudentModule as a (possibly empty) dict.
"""
if not user.is_authenticated():
return {}
try:
student_module = StudentModule.objects.get(
student=user,
course_id=course_key,
module_state_key=block_key,
)
except StudentModule.DoesNotExist:
student_module = None
if student_module:
return json.loads(student_module.state)
else:
return {}