def process_request(self, request): """ Add a course_id to user request session. """ if request.user.is_authenticated: match = COURSE_REGEX.match(request.build_absolute_uri()) course_id = None if match: course_id = match.group('course_id') if course_id and course_id != request.session.get('course_id'): request.session['course_id'] = course_id
def course_context_from_url(url): """ Extracts the course_context from the given `url` and passes it on to `course_context_from_course_id()`. """ url = url or '' match = COURSE_REGEX.match(url) course_id = None if match: course_id_string = match.group('course_id') try: course_id = CourseKey.from_string(course_id_string) except InvalidKeyError: log.warning('unable to parse course_id "{course_id}"'.format( course_id=course_id_string), exc_info=True) return course_context_from_course_id(course_id)
def course_context_from_url(url): """ Extracts the course_context from the given `url` and passes it on to `course_context_from_course_id()`. """ url = url or '' match = COURSE_REGEX.match(url) course_id = None if match: course_id_string = match.group('course_id') try: course_id = CourseKey.from_string(course_id_string) except InvalidKeyError: log.warning( 'unable to parse course_id "{course_id}"'.format( course_id=course_id_string ), exc_info=True ) return course_context_from_course_id(course_id)
def course_context_from_url(url, course_id_string=None): """ If course_id_string string is not present, extracts it from the given `url`. Either way, then passes it on to `course_context_from_course_id()`. """ url = url or '' course_id = None if not course_id_string: match = COURSE_REGEX.match(url) if match: course_id_string = match.group('course_id') if not course_id_string: log.debug('no course_id found in "{url}"'.format(url=str(url)[0:256]), exc_info=True) else: try: course_id = CourseKey.from_string(course_id_string) except InvalidKeyError: log.warning('unable to parse course_id "{course_id}"'.format( course_id=str(course_id_string)[0:256]), exc_info=True) return course_context_from_course_id(course_id)