Пример #1
0
    def dispatch(self, request, *args, **kwargs):
        self.ass = get_object_or_404(Assignment, pk=kwargs['pk'])

        # Check whether submissions are allowed.
        if not self.ass.can_create_submission(user=request.user):
            raise PermissionDenied(
                "You are not allowed to create a submission for this assignment"
            )

        # get submission form according to the assignment type
        self.SubmissionForm = getSubmissionForm(self.ass)

        return super().dispatch(request, *args, **kwargs)
Пример #2
0
    def dispatch(self, request, *args, **kwargs):
        self.ass = get_object_or_404(Assignment, pk=kwargs['pk'])
        self.submission = request.user.authored.all().filter(
            assignment=self.ass).exclude(state=Submission.WITHDRAWN)

        if self.submission:
            self.submission = self.submission[0]
            logger.debug("Found existing submission: " + str(self.submission))
        else:
            logger.debug("No submission found for this user.")
            # Check whether new submissions are allowed.
            if not self.ass.can_create_submission(user=request.user):
                logger.warn("User is not allowed to create a new submission.")
                raise PermissionDenied(
                    "You are not allowed to create a submission for this assignment"
                )
            self.SubmissionForm = getSubmissionForm(self.ass)
        # continue with dispatching to get() / post() methods
        return super(TemplateView, self).dispatch(request, *args, **kwargs)