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