Exemplo n.º 1
0
def ajax_user(request, event_id):
    """Ajax query for user validation
    The parameters are email and memberid and pricing.
    The user that matches the given email/memberid will be checked
    if he/she can still register in the event with the given pricing.
    """
    event = get_object_or_404(Event, pk=event_id)

    if not get_setting('module', 'events', 'anonymousmemberpricing'):
        raise Http404

    memberid = request.GET.get('memberid', None)
    email = request.GET.get('email', None)
    pricingid = request.GET.get('pricingid', None)

    pricing = get_object_or_404(RegConfPricing, pk=pricingid)

    user = AnonymousUser()

    allow_memberid = get_setting('module', 'events', 'memberidpricing')
    if memberid and allow_memberid:  # memberid takes priority over email
        membership = Membership.objects.first(member_number=memberid)
        if hasattr(membership, 'user'):
            user = membership.user
    elif email:
        users = User.objects.filter(email=email)
        if users:
            user = users[0]

    data = json.dumps(None)
    #check if already registered
    if not (user.is_anonymous or pricing.allow_anonymous):
        used = Registrant.objects.filter(user=user)
        if used:
            if not (pricing.allow_anonymous or user.profile.is_superuser):
                data = json.dumps({"error": "REG"})
            else:
                data = json.dumps({"message": "REG"})

    #check if can use
    can_use = can_use_pricing(event, user, pricing)
    if not can_use:
        if not get_setting('module', 'events', 'sharedpricing'):
            data = json.dumps({"error": "INVALID"})
        else:
            data = json.dumps({"error": "SHARED"})

    return HttpResponse(data, content_type="text/plain")
Exemplo n.º 2
0
def ajax_user(request, event_id):
    """Ajax query for user validation
    The parameters are email and memberid and pricing.
    The user that matches the given email/memberid will be checked
    if he/she can still register in the event with the given pricing.
    """
    event = get_object_or_404(Event, pk=event_id)

    if not get_setting('module', 'events', 'anonymousmemberpricing'):
        raise Http404

    memberid = request.GET.get('memberid', None)
    email = request.GET.get('email', None)
    pricingid = request.GET.get('pricingid', None)

    pricing = get_object_or_404(RegConfPricing, pk=pricingid)

    user = AnonymousUser()

    allow_memberid = get_setting('module', 'events', 'memberidpricing')
    if memberid and allow_memberid:# memberid takes priority over email
        membership = Membership.objects.first(member_number=memberid)
        if hasattr(membership, 'user'):
            user = membership.user
    elif email:
        users = User.objects.filter(email=email)
        if users:
            user = users[0]

    data = json.dumps(None)
    #check if already registered
    if not (user.is_anonymous() or pricing.allow_anonymous):
        used = Registrant.objects.filter(user=user)
        if used:
            if not (pricing.allow_anonymous or user.profile.is_superuser):
                data = json.dumps({"error":"REG"})
            else:
                data = json.dumps({"message":"REG"})

    #check if can use
    can_use = can_use_pricing(event, user, pricing)
    if not can_use:
        if not get_setting('module', 'events', 'sharedpricing'):
            data = json.dumps({"error":"INVALID"})
        else:
            data = json.dumps({"error":"SHARED"})

    return HttpResponse(data, content_type="text/plain")
Exemplo n.º 3
0
    def clean(self):
        """
        Validate the set of registrants for all the pricings used.
        """

        if self.total_form_count()<1:
            raise forms.ValidationError(_('You must register at least 1 registrant per registration'))

        # organize pricing dict
        self.set_pricing_groups()

        # validate the reg quantity for each pricing
        for pricing in self.pricings.keys():
            # the registrant length must be divisible by the pricing's quantity
            if len(self.pricings[pricing]) % pricing.quantity != 0:
                raise forms.ValidationError(_("Please enter a valid number of registrants."))


        errors = []
        users = []

        # mark all validated prices is shared pricing
        shared_pricing = get_setting('module', 'events', 'sharedpricing')
        if shared_pricing:
            for pricing in self.pricings.keys():
                for i in range(0, len(self.pricings[pricing])):
                    form = self.pricings[pricing][i]
                    if i % pricing.quantity == 0:
                        user = form.get_user()
                        if can_use_pricing(self.event, user, pricing):
                            self.enabled_pricings.append(pricing)

        # if all quantities are valid, update each form's corresponding price
        for pricing in self.pricings.keys():
            for i in range(0, len(self.pricings[pricing])):
                form = self.pricings[pricing][i]
                if i % pricing.quantity == 0:
                    price = pricing.price

                    # first form of each set must be authorized for the pricing
                    user = form.get_user()
                    # take note of each invalid price but continue setting prices

                    if shared_pricing:
                        if pricing not in self.enabled_pricings:
                            errors.append(forms.ValidationError(_("%(user)s is not authorized to use %(pricing)s" % {'user': user, 'pricing': pricing})))
                    else:
                        if not can_use_pricing(self.event, user, pricing):
                            errors.append(forms.ValidationError(_("%(user)s is not authorized to use %(pricing)s" % {'user': user, 'pricing': pricing})))

                    if not user.is_anonymous():
                        # check if this user has already been used before
                        if user.pk in users:
                            errors.append(forms.ValidationError(_("%s can only be registered once per registration" % user)))
                        else:
                            # mark this pricing pair used
                            users.append(user.pk)
                else:
                    price = Decimal('0.00')

                # associate the price with the form
                form.set_price(price)

                # update the total price
                self.total_price += price

        # raise any errors found
        for error in errors:
            raise error