mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 11:12:18 +01:00 
			
		
		
		
	Make the payment group button work
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
		@@ -28,9 +28,9 @@
 | 
				
			|||||||
                        You want finally that each member pays its own registration? Then click on the button:
 | 
					                        You want finally that each member pays its own registration? Then click on the button:
 | 
				
			||||||
                    {% endblocktrans %}
 | 
					                    {% endblocktrans %}
 | 
				
			||||||
                    <div class="text-center">
 | 
					                    <div class="text-center">
 | 
				
			||||||
                        <button class="btn btn-warning">
 | 
					                        <a href="{% url 'registration:update_payment_group_mode' pk=payment.pk %}" class="btn btn-warning">
 | 
				
			||||||
                            <i class="fas fa-user"></i> {% trans "Back to single payments" %}
 | 
					                            <i class="fas fa-user"></i> {% trans "Back to single payments" %}
 | 
				
			||||||
                        </button>
 | 
					                        </a>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                {% else %}
 | 
					                {% else %}
 | 
				
			||||||
                    {% blocktrans trimmed %}
 | 
					                    {% blocktrans trimmed %}
 | 
				
			||||||
@@ -38,9 +38,9 @@
 | 
				
			|||||||
                        or your school will pay for all registrations? Then click on the button:
 | 
					                        or your school will pay for all registrations? Then click on the button:
 | 
				
			||||||
                    {% endblocktrans %}
 | 
					                    {% endblocktrans %}
 | 
				
			||||||
                    <div class="text-center">
 | 
					                    <div class="text-center">
 | 
				
			||||||
                        <button class="btn btn-warning">
 | 
					                        <a href="{% url 'registration:update_payment_group_mode' pk=payment.pk %}" class="btn btn-warning">
 | 
				
			||||||
                            <i class="fas fa-users"></i> {% trans "Group the payments of my team" %}
 | 
					                            <i class="fas fa-users"></i> {% trans "Group the payments of my team" %}
 | 
				
			||||||
                        </button>
 | 
					                        </a>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                {% endif %}
 | 
					                {% endif %}
 | 
				
			||||||
            </p>
 | 
					            </p>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@ from django.urls import path
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from .views import AddOrganizerView, AdultPhotoAuthorizationTemplateView, ChildPhotoAuthorizationTemplateView, \
 | 
					from .views import AddOrganizerView, AdultPhotoAuthorizationTemplateView, ChildPhotoAuthorizationTemplateView, \
 | 
				
			||||||
    InstructionsTemplateView, MyAccountDetailView, ParentalAuthorizationTemplateView, PaymentUpdateView, \
 | 
					    InstructionsTemplateView, MyAccountDetailView, ParentalAuthorizationTemplateView, PaymentUpdateView, \
 | 
				
			||||||
 | 
					    PaymentUpdateGroupView, \
 | 
				
			||||||
    ResetAdminView, SignupView, UserDetailView, UserImpersonateView, UserListView, UserResendValidationEmailView, \
 | 
					    ResetAdminView, SignupView, UserDetailView, UserImpersonateView, UserListView, UserResendValidationEmailView, \
 | 
				
			||||||
    UserUpdateView, UserUploadHealthSheetView, UserUploadParentalAuthorizationView, UserUploadPhotoAuthorizationView, \
 | 
					    UserUpdateView, UserUploadHealthSheetView, UserUploadParentalAuthorizationView, UserUploadPhotoAuthorizationView, \
 | 
				
			||||||
    UserUploadVaccineSheetView, UserValidateView, UserValidationEmailSentView
 | 
					    UserUploadVaccineSheetView, UserValidateView, UserValidationEmailSentView
 | 
				
			||||||
@@ -37,6 +38,8 @@ urlpatterns = [
 | 
				
			|||||||
    path("user/<int:pk>/upload-parental-authorization/", UserUploadParentalAuthorizationView.as_view(),
 | 
					    path("user/<int:pk>/upload-parental-authorization/", UserUploadParentalAuthorizationView.as_view(),
 | 
				
			||||||
         name="upload_user_parental_authorization"),
 | 
					         name="upload_user_parental_authorization"),
 | 
				
			||||||
    path("update-payment/<int:pk>/", PaymentUpdateView.as_view(), name="update_payment"),
 | 
					    path("update-payment/<int:pk>/", PaymentUpdateView.as_view(), name="update_payment"),
 | 
				
			||||||
 | 
					    path("update-payment/<int:pk>/toggle-group-mode/", PaymentUpdateGroupView.as_view(),
 | 
				
			||||||
 | 
					         name="update_payment_group_mode"),
 | 
				
			||||||
    path("user/<int:pk>/impersonate/", UserImpersonateView.as_view(), name="user_impersonate"),
 | 
					    path("user/<int:pk>/impersonate/", UserImpersonateView.as_view(), name="user_impersonate"),
 | 
				
			||||||
    path("user/list/", UserListView.as_view(), name="user_list"),
 | 
					    path("user/list/", UserListView.as_view(), name="user_list"),
 | 
				
			||||||
    path("reset-admin/", ResetAdminView.as_view(), name="reset_admin"),
 | 
					    path("reset-admin/", ResetAdminView.as_view(), name="reset_admin"),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -460,9 +460,10 @@ class PaymentUpdateView(LoginRequiredMixin, UpdateView):
 | 
				
			|||||||
                                                    data=self.request.POST or None,
 | 
					                                                    data=self.request.POST or None,
 | 
				
			||||||
                                                    instance=self.object)
 | 
					                                                    instance=self.object)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        context['scholarship_form'] = PaymentForm(payment_type='scholarship',
 | 
					        if not self.object.grouped:
 | 
				
			||||||
                                                  data=self.request.POST or None,
 | 
					            context['scholarship_form'] = PaymentForm(payment_type='scholarship',
 | 
				
			||||||
                                                  instance=self.object)
 | 
					                                                      data=self.request.POST or None,
 | 
				
			||||||
 | 
					                                                      instance=self.object)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        context['other_form'] = PaymentForm(payment_type='other',
 | 
					        context['other_form'] = PaymentForm(payment_type='other',
 | 
				
			||||||
                                            data=self.request.POST or None,
 | 
					                                            data=self.request.POST or None,
 | 
				
			||||||
@@ -481,6 +482,54 @@ class PaymentUpdateView(LoginRequiredMixin, UpdateView):
 | 
				
			|||||||
        return reverse_lazy("registration:user_detail", args=(self.object.registrations.first().user.pk,))
 | 
					        return reverse_lazy("registration:user_detail", args=(self.object.registrations.first().user.pk,))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PaymentUpdateGroupView(LoginRequiredMixin, DetailView):
 | 
				
			||||||
 | 
					    model = Payment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def dispatch(self, request, *args, **kwargs):
 | 
				
			||||||
 | 
					        if not self.request.user.is_authenticated or \
 | 
				
			||||||
 | 
					                not self.request.user.registration.is_admin \
 | 
				
			||||||
 | 
					                and (self.request.user.registration not in self.get_object().registrations.all()
 | 
				
			||||||
 | 
					                     or self.get_object().valid is not False):
 | 
				
			||||||
 | 
					            return self.handle_no_permission()
 | 
				
			||||||
 | 
					        return super().dispatch(request, *args, **kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get(self, request, *args, **kwargs):
 | 
				
			||||||
 | 
					        payment = self.get_object()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if payment.valid is not False:
 | 
				
			||||||
 | 
					            raise PermissionDenied(_("This payment is already valid or pending validation."))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if payment.grouped:
 | 
				
			||||||
 | 
					            registrations = list(payment.registrations.all())
 | 
				
			||||||
 | 
					            first_reg = registrations[0]
 | 
				
			||||||
 | 
					            payment.registrations.set([first_reg])
 | 
				
			||||||
 | 
					            payment.grouped = False
 | 
				
			||||||
 | 
					            tournament = first_reg.team.participation.tournament if not payment.final else Tournament.final_tournament()
 | 
				
			||||||
 | 
					            payment.amount = tournament.price
 | 
				
			||||||
 | 
					            payment.save()
 | 
				
			||||||
 | 
					            for registration in registrations[1:]:
 | 
				
			||||||
 | 
					                p = Payment.objects.create(type=payment.type,
 | 
				
			||||||
 | 
					                                           grouped=False,
 | 
				
			||||||
 | 
					                                           final=payment.final,
 | 
				
			||||||
 | 
					                                           amount=tournament.price,
 | 
				
			||||||
 | 
					                                           receipt=payment.receipt,
 | 
				
			||||||
 | 
					                                           additional_information=payment.additional_information)
 | 
				
			||||||
 | 
					                p.registrations.set([registration])
 | 
				
			||||||
 | 
					                p.save()
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            reg = payment.registrations.get()
 | 
				
			||||||
 | 
					            tournament = reg.team.participation.tournament if not payment.final else Tournament.final_tournament()
 | 
				
			||||||
 | 
					            for student in reg.team.students.all():
 | 
				
			||||||
 | 
					                if student != reg:
 | 
				
			||||||
 | 
					                    Payment.objects.filter(registrations=student, final=payment.final).delete()
 | 
				
			||||||
 | 
					                payment.registrations.add(student)
 | 
				
			||||||
 | 
					            payment.amount = tournament.price * reg.team.students.count()
 | 
				
			||||||
 | 
					            payment.grouped = True
 | 
				
			||||||
 | 
					            payment.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return redirect(reverse_lazy("registration:update_payment", args=(payment.pk,)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PhotoAuthorizationView(LoginRequiredMixin, View):
 | 
					class PhotoAuthorizationView(LoginRequiredMixin, View):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Display the sent photo authorization.
 | 
					    Display the sent photo authorization.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user