Example #1
0
File: views.py Project: webkom/lego
    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        event_id = self.kwargs.get("event_pk", None)
        event = Event.objects.get(id=event_id)
        if event.use_captcha and not verify_captcha(
                serializer.data.get("captcha_response", None)):
            raise ValidationError({"error": "Bad captcha"})

        current_user = request.user

        with transaction.atomic():
            registration = Registration.objects.get_or_create(
                event_id=event_id,
                user_id=current_user.id,
                defaults={
                    "updated_by": current_user,
                    "created_by": current_user
                },
            )[0]
            feedback = serializer.data.get("feedback", "")
            if registration.event.feedback_required and not feedback:
                raise ValidationError({"error": "Feedback is required"})
            registration.status = constants.PENDING_REGISTER
            registration.feedback = feedback
            registration.save(current_user=current_user)
            transaction.on_commit(
                lambda: async_register.delay(registration.id))
        registration.refresh_from_db()
        registration_serializer = RegistrationReadSerializer(
            registration, context={"user": registration.user})
        return Response(data=registration_serializer.data,
                        status=status.HTTP_202_ACCEPTED)
Example #2
0
class EventReadAuthUserDetailedSerializer(EventReadUserDetailedSerializer):
    pools = PoolReadAuthSerializer(many=True)
    waiting_registrations = RegistrationReadSerializer(many=True)

    class Meta(EventReadUserDetailedSerializer.Meta):
        fields = EventReadUserDetailedSerializer.Meta.fields + (
            'waiting_registrations', )
Example #3
0
 def destroy(self, request, *args, **kwargs):
     with transaction.atomic():
         instance = self.get_object()
         instance.status = constants.PENDING_UNREGISTER
         instance.save()
         transaction.on_commit(lambda: async_unregister.delay(instance.id))
     serializer = RegistrationReadSerializer(instance)
     return Response(data=serializer.data, status=status.HTTP_202_ACCEPTED)
Example #4
0
 def get_registrations(self, obj):
     queryset = obj.registrations.all()
     if obj.event.is_priced:
         return RegistrationPaymentReadSerializer(queryset,
                                                  context=self.context,
                                                  many=True).data
     return RegistrationReadSerializer(queryset,
                                       context=self.context,
                                       many=True).data
Example #5
0
class EventReadAuthUserDetailedSerializer(EventReadUserDetailedSerializer):
    pools = PoolReadAuthSerializer(many=True)
    waiting_registrations = RegistrationReadSerializer(many=True)
    unanswered_surveys = serializers.SerializerMethodField()

    class Meta(EventReadUserDetailedSerializer.Meta):
        fields = EventReadUserDetailedSerializer.Meta.fields + (
            'waiting_registrations', 'unanswered_surveys')

    def get_unanswered_surveys(self, obj):
        request = self.context.get('request', None)
        return request.user.unanswered_surveys()
Example #6
0
    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        event_id = self.kwargs.get('event_pk', None)
        event = Event.objects.get(id=event_id)
        if event.use_captcha and not verify_captcha(serializer.data.get('captcha_response', None)):
            raise ValidationError({'error': 'Bad captcha'})

        user_id = request.user.id

        with transaction.atomic():
            registration = Registration.objects.get_or_create(event_id=event_id, user_id=user_id)[0]
            feedback = serializer.data.get('feedback', '')
            if registration.event.feedback_required and not feedback:
                raise ValidationError({'error': 'Feedback is required'})
            registration.status = constants.PENDING_REGISTER
            registration.feedback = feedback
            registration.save(update_fields=['status', 'feedback'])
            transaction.on_commit(lambda: async_register.delay(registration.id))
        registration_serializer = RegistrationReadSerializer(
            registration, context={'user': registration.user}
        )
        return Response(data=registration_serializer.data, status=status.HTTP_202_ACCEPTED)
Example #7
0
 def get_user_reg(self, event):
     return RegistrationReadSerializer(event.user_reg[0]).data