Ejemplo n.º 1
0
 def get_context_data(self, **kwargs):
     c = super().get_context_data(**kwargs)
     c['competition'] = self.competition
     c['bucket'] = self.bucket
     if not self.competition.has_permission(self.request.user):
         raise PermissionDenied()
     return c
Ejemplo n.º 2
0
    def post(self, *args, **kwargs):
        bucket = self.get_object()
        url = bucket.get_url()

        if not bucket.get_competition().has_permission(self.request.user):
            raise PermissionDenied()

        if 'vote' not in self.request.POST: return redirect(url)
        value = self.request.POST['vote']

        try:
            value = int(value)
        except ValueError:
            return redirect(url)

        try:
            vote = bucket.vote_set.get(user=self.request.user)
            vote.value = value
            vote.save()
        except Vote.DoesNotExist:
            vote = bucket.vote_set.create(user=self.request.user, value=value)

        if vote.value == 0:
            vote.delete()

        return redirect(url)
Ejemplo n.º 3
0
 def get_object(self, *args, **kwargs):
     obj = super().get_object(*args, **kwargs)
     if not obj.competition.has_permission(
             self.request.user) or obj.author != self.request.user:
         raise PermissionDenied()
     self.competition = obj.competition
     self.problem = obj
     return obj
Ejemplo n.º 4
0
 def get_object(self, *args, **kwargs):
     obj = super().get_object(*args, **kwargs)
     self.competition = obj.bucket.get_competition()
     if not self.competition.has_permission(
             self.request.user) or obj.user != self.request.user:
         raise PermissionDenied()
     self.bucket = obj.bucket
     return obj
Ejemplo n.º 5
0
    def get_object(self, *args, **kwargs):
        self.solution = super().get_object(*args, **kwargs)
        self.problem = get_object_or_404(Problem, slug=self.kwargs['slug'])
        self.competition = self.problem.get_competition()
        if not self.competition.has_permission(
                self.request.user
        ) or self.problem != self.solution.problem or self.request.user != self.problem.author:
            raise PermissionDenied()

        return self.solution
Ejemplo n.º 6
0
    def get_form_class(self):
        self.problem = get_object_or_404(Problem, slug=self.kwargs['slug'])
        self.competition = self.problem.get_competition()
        if not self.competition.has_permission(
                self.request.user) or self.problem != self.get_object(
                ).problem or (self.request.user != self.get_object().author
                              and self.request.user != self.problem.author):
            raise PermissionDenied()

        return SolutionForm(self)
Ejemplo n.º 7
0
 def get_queryset(self):
     self.problem = get_object_or_404(Problem, slug=self.kwargs['slug'])
     if not self.problem.get_competition().has_permission(
             self.request.user):
         raise PermissionDenied()
     return self.problem.get_solutions()
Ejemplo n.º 8
0
	def get_queryset(self):
		self.competition = get_object_or_404(Competition, slug=self.kwargs['slug'])
		if self.competition.has_permission(self.request.user):
			return self.competition.news_set.order_by('-time')
		else:
			raise PermissionDenied()
Ejemplo n.º 9
0
	def get_object(self, *args, **kwargs):
		obj = super().get_object(*args, **kwargs)
		if not obj.has_permission(self.request.user):
			raise PermissionDenied()
		return obj