mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-10-31 22:24:30 +01:00 
			
		
		
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			cb5f597547
			...
			8515153be7
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 8515153be7 | ||
|  | 5a865efd18 | ||
|  | a55eea7c10 | 
| @@ -3,9 +3,9 @@ | ||||
|  | ||||
| import os | ||||
|  | ||||
| import requests | ||||
| from django.contrib.auth.models import User | ||||
| from django.core.management import BaseCommand | ||||
| import requests | ||||
|  | ||||
|  | ||||
| class Command(BaseCommand): | ||||
|   | ||||
| @@ -13,6 +13,7 @@ from django.http import Http404, HttpResponse | ||||
| from django.shortcuts import redirect | ||||
| from django.template.loader import render_to_string | ||||
| from django.urls import reverse_lazy | ||||
| from django.utils import timezone | ||||
| from django.utils.translation import gettext_lazy as _ | ||||
| from django.views.generic import CreateView, DetailView, FormView, RedirectView, TemplateView, UpdateView | ||||
| from django.views.generic.edit import FormMixin, ProcessFormView | ||||
| @@ -505,10 +506,17 @@ class SolutionUploadView(LoginRequiredMixin, FormView): | ||||
|         It is discriminating whenever the team is selected for the final tournament or not. | ||||
|         """ | ||||
|         form_sol = form.instance | ||||
|         # Drop previous solution if existing | ||||
|         for sol in Solution.objects.filter(participation=self.participation, | ||||
|         sol_qs = Solution.objects.filter(participation=self.participation, | ||||
|                                          problem=form_sol.problem, | ||||
|                                            final_solution=self.participation.final).all(): | ||||
|                                          final_solution=self.participation.final) | ||||
|  | ||||
|         tournament = Tournament.final_tournament() if self.participation.final else self.participation.final | ||||
|         if timezone.now() > tournament.solution_limit and sol_qs.exists(): | ||||
|             form.add_error(None, _("You can't upload a solution after the deadline.")) | ||||
|             return self.form_invalid(form) | ||||
|  | ||||
|         # Drop previous solution if existing | ||||
|         for sol in sol_qs.all(): | ||||
|             sol.file.delete() | ||||
|             sol.delete() | ||||
|         form_sol.participation = self.participation | ||||
| @@ -677,10 +685,18 @@ class SynthesisUploadView(LoginRequiredMixin, FormView): | ||||
|         It is discriminating whenever the team is selected for the final tournament or not. | ||||
|         """ | ||||
|         form_syn = form.instance | ||||
|         # Drop previous solution if existing | ||||
|         for syn in Synthesis.objects.filter(participation=self.participation, | ||||
|         syn_qs = Synthesis.objects.filter(participation=self.participation, | ||||
|                                           passage=self.passage, | ||||
|                                             type=form_syn.type).all(): | ||||
|                                           type=form_syn.type).all() | ||||
|  | ||||
|         deadline = self.passage.pool.tournament.syntheses_first_phase_limit if self.passage.pool.round == 1 \ | ||||
|             else self.passage.pool.tournament.syntheses_second_phase_limit | ||||
|         if syn_qs.exists() and timezone.now() > deadline: | ||||
|             form.add_error(None, _("You can't upload a synthesis after the deadline.")) | ||||
|             return self.form_invalid(form) | ||||
|  | ||||
|         # Drop previous solution if existing | ||||
|         for syn in syn_qs.all(): | ||||
|             syn.file.delete() | ||||
|             syn.delete() | ||||
|         form_syn.participation = self.participation | ||||
|   | ||||
| @@ -14,6 +14,7 @@ from django.http import FileResponse, Http404 | ||||
| from django.shortcuts import redirect, resolve_url | ||||
| from django.template.loader import render_to_string | ||||
| from django.urls import reverse_lazy | ||||
| from django.utils import timezone | ||||
| from django.utils.crypto import get_random_string | ||||
| from django.utils.http import urlsafe_base64_decode | ||||
| from django.utils.translation import gettext_lazy as _ | ||||
| @@ -507,17 +508,21 @@ class SolutionView(LoginRequiredMixin, View): | ||||
|             raise Http404 | ||||
|         solution = Solution.objects.get(file__endswith=filename) | ||||
|         user = request.user | ||||
|         passage_participant_qs = Passage.objects.filter(Q(defender=user.registration.team.participation) | ||||
|                                                         | Q(opponent=user.registration.team.participation) | ||||
|                                                         | Q(reporter=user.registration.team.participation), | ||||
|                                                         defender=solution.participation, | ||||
|                                                         solution_number=solution.problem) | ||||
|         if not (user.registration.is_admin or user.registration.is_volunteer | ||||
|                 and Passage.objects.filter(Q(pool__juries=user.registration) | ||||
|                                            | Q(pool__tournament__in=user.registration.organized_tournaments.all()), | ||||
|                                            defender=solution.participation, | ||||
|                                            solution_number=solution.problem).exists() | ||||
|                 or user.registration.participates and user.registration.team | ||||
|                 and Passage.objects.filter(Q(defender=user.registration.team.participation) | ||||
|                                            | Q(opponent=user.registration.team.participation) | ||||
|                                            | Q(reporter=user.registration.team.participation), | ||||
|                                            defender=solution.participation, | ||||
|                                            solution_number=solution.problem).exists()): | ||||
|                 and (solution.participation.team == user.registration.team or | ||||
|                      any(passage.pool.round == 1 | ||||
|                          or timezone.now() >= passage.pool.tournament.solutions_available_second_phase | ||||
|                          for passage in passage_participant_qs.all()))): | ||||
|             raise PermissionDenied | ||||
|         # Guess mime type of the file | ||||
|         mime = Magic(mime=True) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user