Exemple #1
0
 def __init__(self, instance=None, data=empty, **kwargs):
     super().__init__(instance, data, **kwargs)
     try:
         if instance:
             self.information_fields = services.registration_fields(
                 kwargs["context"]["request"], registration=instance
             )
     except RegistrationError:
         pass
Exemple #2
0
    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)
Exemple #3
0
    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
Exemple #4
0
 def get_form_kwargs(self):
     kwargs = super().get_form_kwargs()
     kwargs["fields"] = services.registration_fields(
         self.request, registration=self.registration)
     return kwargs
Exemple #5
0
    def test_registration_fields(self, perms_mock):
        perms_mock.return_value = {
            "create_registration": False,
            "cancel_registration": False,
            "update_registration": False,
        }

        mock_request = HttpRequest()
        mock_request.member = self.member

        with self.assertRaises(RegistrationError):
            services.registration_fields(mock_request, self.member, self.event)

        registration = EventRegistration.objects.create(
            event=self.event, member=self.member,
        )

        with self.assertRaises(RegistrationError):
            services.registration_fields(mock_request, self.member, self.event)
        with self.assertRaises(RegistrationError):
            services.registration_fields(mock_request, registration=registration)

        perms_mock.return_value["update_registration"] = True

        RegistrationInformationField.objects.create(
            id=1,
            name_en="1",
            name_nl="1",
            type=RegistrationInformationField.INTEGER_FIELD,
            event=self.event,
            required=False,
        )

        RegistrationInformationField.objects.create(
            id=2,
            name_en="2",
            name_nl="2",
            type=RegistrationInformationField.BOOLEAN_FIELD,
            event=self.event,
            required=True,
        )

        RegistrationInformationField.objects.create(
            id=3,
            name_nl="3",
            name_en="3",
            type=RegistrationInformationField.TEXT_FIELD,
            event=self.event,
            required=False,
        )
        # set order
        self.event.set_registrationinformationfield_order([1, 2, 3])

        fields_list = [
            services.registration_fields(mock_request, self.member, self.event),
            services.registration_fields(mock_request, registration=registration),
        ]

        for fields in fields_list:
            self.assertEqual(
                fields["info_field_1"],
                {
                    "type": "integer",
                    "label": "1",
                    "description": None,
                    "value": None,
                    "required": False,
                },
            )

            self.assertEqual(
                fields["info_field_2"],
                {
                    "type": "boolean",
                    "label": "2",
                    "description": None,
                    "value": None,
                    "required": True,
                },
            )

            self.assertEqual(
                fields["info_field_3"],
                {
                    "type": "text",
                    "label": "3",
                    "description": None,
                    "value": None,
                    "required": False,
                },
            )

            self.assertEqual(len(fields), 3)
            # Test that the ordering is correct
            labels = [field["label"] for field in fields.values()]
            self.assertEqual(labels, sorted(labels))
Exemple #6
0
 def get_form_kwargs(self):
     kwargs = super().get_form_kwargs()
     kwargs["fields"] = services.registration_fields(
         self.request, self.request.member, self.event)
     return kwargs