def form_valid(self, form): values = form.field_values() try: services.update_registration(self.request.member, self.event, field_values=values) messages.success(self.request, _("Registration successfully saved.")) return redirect(self.event) except RegistrationError as e: messages.error(self.request, e) return self.render_to_response(self.get_context_data(form=form))
def form_valid(self, form): values = form.field_values() try: services.update_registration(registration=self.registration, field_values=values) messages.success(self.request, _("Registration successfully saved.")) if "_save" in self.request.POST: return redirect("admin:events_eventregistration_change", self.registration.pk) except RegistrationError as e: messages.error(self.request, e) return self.render_to_response(self.get_context_data(form=form))
def perform_update(self, serializer): registration = serializer.instance member = self.request.member if (member and member.has_perm("events.change_registration") and services.is_organiser(member, registration.event)): services.update_registration_by_organiser( registration, self.request.member, serializer.validated_data) services.update_registration(registration=registration, field_values=serializer.field_values()) serializer.information_fields = services.registration_fields( serializer.context["request"], registration=registration)
def perform_update(self, serializer): try: registration = serializer.instance member = self.request.member if (member and member.has_perm("events.change_registration") and services.is_organiser(member, registration.event)): services.update_registration_by_organiser( registration, self.request.member, serializer.validated_data) services.update_registration( registration=registration, field_values=serializer.field_values()) serializer.information_fields = services.registration_fields( serializer.context["request"], registration=registration) except RegistrationError as e: raise PermissionDenied(detail=e) from e except PaymentError as e: raise PermissionDenied(detail=e) from e
def test_update_registration_guest(self, perms_mock): self.event.registration_start = timezone.now() - timedelta(hours=2) self.event.registration_end = timezone.now() + timedelta(hours=1) perms_mock.return_value = { "create_registration": False, "cancel_registration": False, "update_registration": False, } with self.assertRaises(RegistrationError): services.update_registration(self.member, self.event, field_values=None) registration = EventRegistration.objects.create(event=self.event, name="test",) services.update_registration(event=self.event, name="test", field_values=None) perms_mock.return_value["update_registration"] = True field1 = RegistrationInformationField.objects.create( type=RegistrationInformationField.INTEGER_FIELD, event=self.event, required=False, ) field2 = RegistrationInformationField.objects.create( type=RegistrationInformationField.BOOLEAN_FIELD, event=self.event, required=False, ) field3 = RegistrationInformationField.objects.create( type=RegistrationInformationField.TEXT_FIELD, event=self.event, required=False, ) fields = [ ("info_field_{}".format(field1.id), None), ("info_field_{}".format(field2.id), None), ("info_field_{}".format(field3.id), None), ] services.update_registration(name="test", event=self.event, field_values=fields) self.assertEqual(field1.get_value_for(registration), 0) self.assertEqual(field2.get_value_for(registration), False) self.assertEqual(field3.get_value_for(registration), "") fields = [ ("info_field_{}".format(field1.id), 2), ("info_field_{}".format(field2.id), True), ("info_field_{}".format(field3.id), "text"), ] services.update_registration(name="test", event=self.event, field_values=fields) self.assertEqual(field1.get_value_for(registration), 2) self.assertEqual(field2.get_value_for(registration), True) self.assertEqual(field3.get_value_for(registration), "text") field1.delete() field2.delete() field3.delete()