Пример #1
0
class SupportView(UserProfileView):
    access_mode = ACCESS.ANONYMOUS
    template_name = "userprofile/support.html"
    extra_context = {
        'brand_name': settings_text('BRAND_NAME'),
        'brand_name_long': settings_text('BRAND_NAME_LONG'),
        'brand_institution_name': settings_text('BRAND_INSTITUTION_NAME'),
    }

    def get_common_objects(self):
        super().get_common_objects()
        lang = "_" + get_language().lower()
        key = make_template_fragment_key('support_channels', [lang])
        support_channels = cache.get(key)

        if not support_channels:
            template_name = "support_channels{}.html"
            template = try_get_template(template_name.format(lang))

            if not template and len(lang) > 3:
                template = try_get_template(template_name.format(lang[:3]))
            if not template:
                template = try_get_template(template_name.format(''))
            if not template:
                logger.error("The support page is missing")

            support_channels = template.render() if template else _(
                "No support page. Please notify administration!")

            cache.set(key, support_channels)

        self.support_channels = support_channels
        self.note("support_channels")
Пример #2
0
def tags_context(profile, tags):
    return {
        'external': profile.is_external,
        'internal_user_label': settings_text('INTERNAL_USER_LABEL'),
        'external_user_label': settings_text('EXTERNAL_USER_LABEL'),
        'tags': tags,
    }
Пример #3
0
    def get_common_objects(self) -> None:
        super().get_common_objects()

        students = self.instance.students.all()
        group = self.request.GET.get("group")
        if group == "internal":
            students = [s for s in students if not s.is_external]
        elif group == "external":
            students = [s for s in students if s.is_external]

        point_limits = self.design.point_limits
        pad_points = self.design.pad_points
        student_grades = []
        for profile in students:
            points = CachedPoints(self.instance, profile.user, self.content,
                                  self.is_course_staff)
            student_grades.append((
                profile,
                calculate_grade(points.total(), point_limits, pad_points),
            ))
        self.student_grades = student_grades
        self.group = group
        self.internal_user_label = settings_text('INTERNAL_USER_LABEL')
        self.external_user_label = settings_text('EXTERNAL_USER_LABEL')
        self.note('student_grades', 'group', 'internal_user_label',
                  'external_user_label')
Пример #4
0
 def get_common_objects(self):
     super().get_common_objects()
     self.tags = list(self.instance.usertags.all())
     self.internal_user_label = settings_text('INTERNAL_USER_LABEL')
     self.external_user_label = settings_text('EXTERNAL_USER_LABEL')
     self.note(
         'tags', 'internal_user_label', 'external_user_label',
     )
Пример #5
0
 def get_common_objects(self):
     super().get_common_objects()
     self.tags = list(self.instance.usertags.all())
     self.internal_user_label = settings_text('INTERNAL_USER_LABEL')
     self.external_user_label = settings_text('EXTERNAL_USER_LABEL')
     self.note(
         'tags', 'internal_user_label', 'external_user_label',
     )
Пример #6
0
 def get_common_objects(self):
     super().get_common_objects()
     self.participants = json.dumps(CachedStudents(self.instance).students())
     self.tags = list(self.instance.usertags.all())
     self.internal_user_label = settings_text('INTERNAL_USER_LABEL')
     self.external_user_label = settings_text('EXTERNAL_USER_LABEL')
     self.note(
         'participants', 'tags',
         'internal_user_label', 'external_user_label',
     )
Пример #7
0
def tags_context(profile, tags, instance):
    return {
        'user_id': profile.user_id,
        'external': profile.is_external,
        'internal_user_label': settings_text('INTERNAL_USER_LABEL'),
        'external_user_label': settings_text('EXTERNAL_USER_LABEL'),
        'tags': tags,
        'tag_ids': [tag.id for tag in tags],
        'instance': instance,
    }
Пример #8
0
 def get_common_objects(self):
     super().get_common_objects()
     self.tags = [USERTAG_INTERNAL, USERTAG_EXTERNAL]
     self.tags.extend(self.instance.usertags.all())
     self.participants = json.dumps(self._get_students_with_tags())
     self.internal_user_label = settings_text('INTERNAL_USER_LABEL')
     self.external_user_label = settings_text('EXTERNAL_USER_LABEL')
     self.note(
         'participants',
         'tags',
         'internal_user_label',
         'external_user_label',
     )
Пример #9
0
 def get_common_objects(self):
     super().get_common_objects()
     self.participants = json.dumps(
         CachedStudents(self.instance).students())
     self.tags = list(self.instance.usertags.all())
     self.internal_user_label = settings_text('INTERNAL_USER_LABEL')
     self.external_user_label = settings_text('EXTERNAL_USER_LABEL')
     self.note(
         'participants',
         'tags',
         'internal_user_label',
         'external_user_label',
     )
Пример #10
0
def login(request):
    """
    Wraps the default login view in Django. Additionally redirects already
    authenticated users automatically to the target.
    """
    if request.user.is_authenticated():
        redirect_to = request.POST.get(REDIRECT_FIELD_NAME,
                                       request.GET.get(REDIRECT_FIELD_NAME, ''))
        if not is_safe_url(url=redirect_to, host=request.get_host()):
            redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
        return HttpResponseRedirect(redirect_to)

    return django_login(
        request,
        template_name="userprofile/login.html",
        extra_context={
            'shibboleth_login': '******' in settings.INSTALLED_APPS,
            'mooc_login': '******' in settings.INSTALLED_APPS,
            'login_title_text': settings_text('LOGIN_TITLE_TEXT'),
            'login_body_text': settings_text('LOGIN_BODY_TEXT'),
            'login_button_text': settings_text('LOGIN_BUTTON_TEXT'),
            'shibboleth_title_text': settings_text('SHIBBOLETH_TITLE_TEXT'),
            'shibboleth_body_text': settings_text('SHIBBOLETH_BODY_TEXT'),
            'shibboleth_button_text': settings_text('SHIBBOLETH_BUTTON_TEXT'),
            'mooc_title_text': settings_text('MOOC_TITLE_TEXT'),
            'mooc_body_text': settings_text('MOOC_BODY_TEXT'),
        }
    )
Пример #11
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     # The following template context parameters can not be defined in
     # the class variable extra_context because they require that Django
     # translations are active. That is, there must be an HTTP request so
     # that the language can be defined. There is no request in the code
     # in the class level, but there is a request when this method is called
     # (self.request).
     context.update({
         'shibboleth_title_text':
         settings_text('SHIBBOLETH_TITLE_TEXT'),
         'shibboleth_body_text':
         settings_text('SHIBBOLETH_BODY_TEXT'),
         'shibboleth_button_text':
         settings_text('SHIBBOLETH_BUTTON_TEXT'),
         'haka_title_text':
         settings_text('HAKA_TITLE_TEXT'),
         'haka_body_text':
         settings_text('HAKA_BODY_TEXT'),
         'haka_button_text':
         settings_text('HAKA_BUTTON_TEXT'),
         'mooc_title_text':
         settings_text('MOOC_TITLE_TEXT'),
         'mooc_body_text':
         settings_text('MOOC_BODY_TEXT'),
     })
     return context
Пример #12
0
def login(request):
    """
    Wraps the default login view in Django. Additionally redirects already
    authenticated users automatically to the target.
    """
    if request.user.is_authenticated():
        redirect_to = request.POST.get(REDIRECT_FIELD_NAME,
                                       request.GET.get(REDIRECT_FIELD_NAME, ''))
        if not is_safe_url(url=redirect_to, host=request.get_host()):
            redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
        return HttpResponseRedirect(redirect_to)

    return django_login(
        request,
        template_name="userprofile/login.html",
        extra_context={
            'shibboleth_login': '******' in settings.INSTALLED_APPS,
            'mooc_login': '******' in settings.INSTALLED_APPS,
            'login_title_text': settings_text(request, 'LOGIN_TITLE_TEXT'),
            'login_body_text': settings_text(request, 'LOGIN_BODY_TEXT'),
            'login_button_text': settings_text(request, 'LOGIN_BUTTON_TEXT'),
            'shibboleth_title_text': settings_text(request, 'SHIBBOLETH_TITLE_TEXT'),
            'shibboleth_body_text': settings_text(request, 'SHIBBOLETH_BODY_TEXT'),
            'shibboleth_button_text': settings_text(request, 'SHIBBOLETH_BUTTON_TEXT'),
            'mooc_title_text': settings_text(request, 'MOOC_TITLE_TEXT'),
            'mooc_body_text': settings_text(request, 'MOOC_BODY_TEXT'),
        }
    )
Пример #13
0
 def get_common_objects(self):
     super().get_common_objects()
     self.welcome_text = settings_text('WELCOME_TEXT')
     self.internal_user_label = settings_text('INTERNAL_USER_LABEL')
     self.external_user_label = settings_text('EXTERNAL_USER_LABEL')
     self.instances = []
     prio2 = []
     treshold = timezone.now() - datetime.timedelta(days=10)
     for instance in CourseInstance.objects.get_visible(self.request.user)\
             .filter(ending_time__gte=timezone.now()):
         if instance.starting_time > treshold:
             self.instances += [instance]
         else:
             prio2 += [instance]
     self.instances += prio2
     self.note("welcome_text", "internal_user_label", "external_user_label", "instances")
Пример #14
0
 def get_common_objects(self):
     super().get_common_objects()
     self.welcome_text = settings_text('WELCOME_TEXT')
     self.internal_user_label = settings_text('INTERNAL_USER_LABEL')
     self.external_user_label = settings_text('EXTERNAL_USER_LABEL')
     self.instances = []
     prio2 = []
     treshold = timezone.now() - datetime.timedelta(days=10)
     for instance in CourseInstance.objects.get_visible(self.request.user)\
             .filter(ending_time__gte=timezone.now()):
         if instance.starting_time > treshold:
             self.instances += [instance]
         else:
             prio2 += [instance]
     self.instances += prio2
     self.note("welcome_text", "internal_user_label", "external_user_label", "instances")
Пример #15
0
class CustomLoginView(LoginView):
    """This login view class extends the default Django login class and
    overrides some of the default settings. Namely, the template and its context."""

    template_name = "userprofile/login.html"
    redirect_authenticated_user = True
    # Redirecting authenticated users enables "social media fingerprinting"
    # unless images are hosted on a different domain from the Django app.
    extra_context = {
        'shibboleth_login': '******' in settings.INSTALLED_APPS,
        'mooc_login': '******' in settings.INSTALLED_APPS,
        'brand_name': settings_text('BRAND_NAME'),
    }

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        # The following template context parameters can not be defined in
        # the class variable extra_context because they require that Django
        # translations are active. That is, there must be an HTTP request so
        # that the language can be defined. There is no request in the code
        # in the class level, but there is a request when this method is called
        # (self.request).
        context.update({
            'shibboleth_title_text':
            settings_text('SHIBBOLETH_TITLE_TEXT'),
            'shibboleth_body_text':
            settings_text('SHIBBOLETH_BODY_TEXT'),
            'shibboleth_button_text':
            settings_text('SHIBBOLETH_BUTTON_TEXT'),
            'mooc_title_text':
            settings_text('MOOC_TITLE_TEXT'),
            'mooc_body_text':
            settings_text('MOOC_BODY_TEXT'),
        })
        return context
Пример #16
0
    def get_common_objects(self):
        super().get_common_objects()
        self.welcome_text = settings_text('WELCOME_TEXT')
        self.internal_user_label = settings_text('INTERNAL_USER_LABEL')
        self.external_user_label = settings_text('EXTERNAL_USER_LABEL')
        my_instances = []
        all_instances = []
        end_threshold = timezone.now() - datetime.timedelta(days=30)
        user = self.request.user
        is_logged_in = False

        if user and user.is_authenticated:
            is_logged_in = True
            for instance in (CourseInstance.objects.filter(
                    course__teachers=user.userprofile,
                    ending_time__gte=end_threshold).all()):
                my_instances.append(instance)

            for instance in user.userprofile.assisting_courses.all().filter(
                    ending_time__gte=end_threshold):
                if instance not in my_instances:
                    my_instances.append(instance)

            for instance in user.userprofile.enrolled.all().filter(
                    ending_time__gte=end_threshold,
                    visible_to_students=True,
            ):
                if instance not in my_instances:
                    my_instances.append(instance)

        all_instances = CourseInstance.objects.get_visible(user).filter(
            ending_time__gte=end_threshold)
        all_instances = [c for c in all_instances if c not in my_instances]

        self.all_instances = all_instances
        self.my_instances = my_instances
        self.is_logged_in = is_logged_in

        self.note(
            "welcome_text",
            "internal_user_label",
            "external_user_label",
            "my_instances",
            "all_instances",
            "is_logged_in",
        )
Пример #17
0
class ProfileView(UserProfileView):
    template_name = "userprofile/profile.html"
    extra_context = {
        'brand_name': settings_text('BRAND_NAME'),
    }

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['is_google'] = (self.request.user.social_auth.filter(
            provider="google-oauth2").exists()
                                if settings.SOCIAL_AUTH else False)

        return context
Пример #18
0
 def enrollment_audience_check(self, request, course, user):
     audience = course.enrollment_audience
     external = user.userprofile.is_external
     EA = course.ENROLLMENT_AUDIENCE
     institution_name = settings_text('BRAND_INSTITUTION_NAME')
     if audience == EA.INTERNAL_USERS and external:
         self.error_msg(
             format_lazy(
                 _('COURSE_ENROLLMENT_AUDIENCE_ERROR_ONLY_INTERNAL -- {institution}'
                   ),
                 institution=institution_name,
             ))
         return False
     elif audience == EA.EXTERNAL_USERS and not external:
         self.error_msg(
             format_lazy(
                 _('COURSE_ENROLLMENT_AUDIENCE_ERROR_ONLY_EXTERNAL -- {institution}'
                   ),
                 institution=institution_name,
             ))
         return False
     return True
Пример #19
0
def brand_institution_name():
    return mark_safe(settings_text('BRAND_INSTITUTION_NAME'))
Пример #20
0
 def get_common_objects(self):
     super().get_common_objects()
     self.policy_text = settings_text('PRIVACY_POLICY_TEXT')
     self.note("policy_text")
Пример #21
0
 def get_common_objects(self):
     super().get_common_objects()
     self.policy_text = settings_text('PRIVACY_POLICY_TEXT')
     self.note("policy_text")