Exemple #1
0
    def process_request(self, request):
        """
        Add a user's tags to the tracking event context.
        """
        match = COURSE_REGEX.match(request.path)
        course_key = None
        if match:
            course_key = match.group("course_id")
            try:
                course_key = CourseKey.from_string(course_key)
            except InvalidKeyError:
                course_key = None

        context = {}

        if course_key:
            try:
                context["course_id"] = course_key.to_deprecated_string()
            except AttributeError:
                context["course_id"] = unicode(course_key)

            if request.user.is_authenticated():
                context["course_user_tags"] = dict(
                    UserCourseTag.objects.filter(user=request.user.pk, course_id=course_key).values_list("key", "value")
                )
            else:
                context["course_user_tags"] = {}

        tracker.get_tracker().enter_context(self.CONTEXT_NAME, context)
Exemple #2
0
    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
Exemple #3
0
    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
Exemple #4
0
def course_context_from_url(url):
    """
    Extracts the course_id from the given `url` and passes it on to
    `course_context_from_course_id()`.
    """
    url = url or ''

    match = COURSE_REGEX.match(url)
    course_id = ''
    if match:
        course_id = match.group('course_id') or ''

    return course_context_from_course_id(course_id)
def course_context_from_url(url):
    """
    Extracts the course_id from the given `url` and passes it on to
    `course_context_from_course_id()`.
    """
    url = url or ''

    match = COURSE_REGEX.match(url)
    course_id = ''
    if match:
        course_id = match.group('course_id') or ''

    return course_context_from_course_id(course_id)
Exemple #6
0
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 = SlashSeparatedCourseKey.from_deprecated_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)