Ejemplo n.º 1
0
    def get(self, request, *args, **kwargs):
        if self.lesson.id not in self.request.session['user_lessons']:
            raise PermissionDenied  # return a forbidden response
            return request

        abs_filename = os.path.join(
            os.path.join(settings.STACKS_ROOT, self.slide.asset), 'html5.html')

        ActivityLog(
            user=self.request.user, action='access', message=self.slide.id).save()
        return sendfile(request, abs_filename)
Ejemplo n.º 2
0
 def get(self, request, *args, **kwargs):
     msg_detail = self.get_object().lesson.title
     msg = '<a href="%s">%s</a>' % (self.request.path,
                                    self.get_object().title)
     ActivityLog(user=self.request.user,
                 action='access-worksheet',
                 message=msg,
                 message_detail=msg_detail).save()
     return HttpResponseRedirect(
         reverse('question_response',
                 args=(self.kwargs['crs_slug'], self.get_object().id, 1)))
Ejemplo n.º 3
0
    def dispatch(self, *args, **kwargs):
        self.slide = self.get_object()
        self.lesson = self.slide.lesson
        msg_detail = self.lesson.title
        msg = '<a href="%s">%s</a>' % (self.request.path, self.slide.title)
        
        try:
            ActivityLog(
                user=self.request.user, action='access-presentation', message=msg, message_detail=msg_detail).save()
        except:
            raise PermissionDenied  # return a forbidden response

        return super(slide_view, self).dispatch(*args, **kwargs)
Ejemplo n.º 4
0
    def get(self, request, *args, **kwargs):
        course = Course.objects.get(slug=self.kwargs['crs_slug'])
        is_instructor = 'instructor' in get_perms(self.request.user, course)
        is_student = 'access' in get_perms(self.request.user, course)
        """ User has previously completed or is staff. No viewing restrictions enforced. """
        if self.request.user.is_staff or is_instructor or self.completion_status.count(
        ):

            if not self.next_question:
                """ No more questions. Show student user the worksheet completion page. """
                if is_student and not is_instructor:
                    user_ws_status = UserWorksheetStatus.objects.filter(
                        user=self.request.user).get(
                            completed_worksheet=self.worksheet)
                    return HttpResponseRedirect(
                        reverse('worksheet_completed',
                                args=(self.kwargs['crs_slug'],
                                      user_ws_status.id)))

                return HttpResponseRedirect(
                    reverse('worksheet_user_report',
                            args=(self.kwargs['crs_slug'], self.worksheet.id,
                                  self.request.user.id)))

            return super(QuestionResponseView,
                         self).get(request, *args, **kwargs)
        """ User is not staff but viewing restrictions are not enforced if response not required. """
        if self.next_question:
            if not self.next_question['question'].response_required:
                return super(QuestionResponseView,
                             self).get(request, *args, **kwargs)
        """ Viewing restrictions enforced. """
        self.next_question = self.worksheet.get_next_question(
            self.request.user)
        """ If user's response queue is empty, user has completed worksheet, write completion status.
            Send user to worksheet report.
        """
        if not self.next_question:
            if not self.completion_status:
                user_ws_status = UserWorksheetStatus(
                    user=self.request.user,
                    completed_worksheet=self.worksheet,
                    score=self.worksheet.get_user_score(self.request.user))
                user_ws_status.save()
                self.completion_status = True

                logpath = reverse('worksheet_report',
                                  args=(
                                      self.kwargs['crs_slug'],
                                      self.worksheet.id,
                                  ))

                msg = '<a href="%s">%s</a>' % (logpath, self.worksheet.title)
                msg_detail = self.worksheet.lesson.title
                logged = ActivityLog(user=self.request.user,
                                     action='completed-worksheet',
                                     message=msg,
                                     message_detail=msg_detail)
                logged.save()
                """ Create notification for instructor(s) that the user has completed the worksheet """
                for i in course.instructor_list():
                    notification = Notification(
                        user_to_notify=i,
                        context='worksheet',
                        event=self.worksheet.notify_text(
                            crs_slug=course.slug, user=self.request.user))
                    notification.save()
                """ Send email to instructor(s) that the user has completed the worksheet. """
                SendWorksheetNotificationEmailToInstructors(
                    self.request, course, self.worksheet)

                return HttpResponseRedirect(
                    reverse('worksheet_completed',
                            args=(self.kwargs['crs_slug'], user_ws_status.id)))
        """
        Request parameter <j> is potentially overidden by next unanswered question
        in user's response queue.
        """
        if str(self.next_question['index']) != self.kwargs['j']:
            return HttpResponseRedirect(
                reverse('question_response',
                        args=(self.kwargs['crs_slug'], self.worksheet.id,
                              self.next_question['index'])))

        return super(QuestionResponseView, self).get(request, *args, **kwargs)
Ejemplo n.º 5
0
def log_credential_edit(user, credential):
    logs = ActivityLog(type=CREDENTIAL_EDITING,
                       logged_user=user,
                       credential=credential)
    logs.save()
Ejemplo n.º 6
0
def log_credential_delete(user, credential):
    logs = ActivityLog(type=CREDENTIAL_DELETE,
                       logged_user=user,
                       credential=credential)
    logs.save()
Ejemplo n.º 7
0
def log_credential_creation(user, credential):
    logs = ActivityLog(type=CREDENTIAL_CREATION,
                       logged_user=user,
                       credential=credential)
    logs.save()
Ejemplo n.º 8
0
def log_password_access(user, credential):
    logs = ActivityLog(type=PASSWORD_ACCESS,
                       logged_user=user,
                       credential=credential)
    logs.save()
Ejemplo n.º 9
0
def log_logout(user):
    logs = ActivityLog(
        type=ACCOUNT_LOGOUT,
        logged_user=user,
    )
    logs.save()
Ejemplo n.º 10
0
def log_login(user):
    logs = ActivityLog(
        type=ACCOUNT_LOGIN,
        logged_user=user,
    )
    logs.save()
Ejemplo n.º 11
0
def log_login(user):
    logs = ActivityLog(
        type='login',
        logged_user=user,
    )
    logs.save()