Exemple #1
0
def user(request, token):
    """
    view che logga automaticamente un utente (se il token è valido) e lo
    ridirige alla pagine dei tickets
    """
    u = get_object_or_404(amodels.User, token=token)
    log.info('autologin (via token url) for "%s"', u.user)
    if not u.user.is_active:
        u.user.is_active = True
        u.user.save()
        log.info('"%s" activated', u.user)
    user = auth.authenticate(uid=u.user.id)
    auth.login(request, user)
    return HttpResponseRedirectSeeOther(reverse('p3-tickets'))
Exemple #2
0
def sprint_submission(request):
    if request.method == 'POST':
        form = p3forms.FormSprint(data=request.POST)
        if form.is_valid():
            s = form.save(commit=False)
            s.user = request.user.assopy_user
            s.conference_id = settings.CONFERENCE_CONFERENCE
            s.save()
            messages.info(request,
                          'Your sprint has been submitted, thank you!')
            return HttpResponseRedirectSeeOther(
                reverse('p3-sprint-submission'))

    else:
        form = p3forms.FormSprint()
    return {
        'form': form,
    }
Exemple #3
0
def cart(request):
    u = None
    if request.user.is_authenticated():
        try:
            u = request.user.assopy_user
        except AttributeError:
            pass
    at = 'p'

    # user-cart is needed for the confirmation page with invoce data,
    # I want to be suer that the only way to set it is when there is
    # a valid POST request
    request.session.pop('user-cart', None)
    if request.method == 'POST':
        if not request.user.is_authenticated():
            return HttpResponseRedirectSeeOther(reverse('p3-cart'))
        form = p3forms.P3FormTickets(data=request.POST, user=u)
        if form.is_valid():
            request.session['user-cart'] = form.cleaned_data
            return redirect('p3-billing')
    else:
        form = p3forms.P3FormTickets(initial={
            'order_type':
            'deductible' if at == 'c' else 'non-deductible',
        },
                                     user=u)
    fares = {}
    for f in form.available_fares():
        if not f.code.startswith('_'):
            fares[f.code] = f
    fares_ordered = sorted(fares.values(), key=lambda x: x.name)
    ctx = {
        'form': form,
        'fares': fares,
        'fares_ordered': fares_ordered,
        'account_type': at,
    }
    return render(request, 'p3/cart.html', ctx)
Exemple #4
0
def cart(request):
    u = None
    if request.user.is_authenticated():
        try:
            u = request.user.assopy_user
        except AttributeError:
            pass
    at = 'p'

    # user-cart serve alla pagina di conferma con i dati di fatturazione,
    # voglio essere sicuro che l'unico modo per impostarlo sia quando viene
    # fatta una POST valida
    request.session.pop('user-cart', None)
    if request.method == 'POST':
        if not request.user.is_authenticated():
            return HttpResponseRedirectSeeOther(reverse('p3-cart'))
        form = p3forms.P3FormTickets(data=request.POST, user=u)
        if form.is_valid():
            request.session['user-cart'] = form.cleaned_data
            return redirect('p3-billing')
    else:
        form = p3forms.P3FormTickets(initial={
            'order_type':
            'deductible' if at == 'c' else 'non-deductible',
        },
                                     user=u)
    fares = {}
    for f in form.available_fares():
        if not f.code.startswith('_'):
            fares[f.code] = f
    fares_ordered = sorted(fares.values(), key=lambda x: x.name)
    ctx = {
        'form': form,
        'fares': fares,
        'fares_ordered': fares_ordered,
        'account_type': at,
    }
    return render(request, 'p3/cart.html', ctx)
Exemple #5
0
def billing(request):
    try:
        tickets = request.session['user-cart']['tickets']
    except KeyError:
        # the session is missing the user-cart key, instead of raising a
        # 500 error I'm sending back the user to the cart.
        return redirect('p3-cart')

    recipient = 'p'
    conference_recipients = set()
    for fare, foo in tickets:
        if fare.recipient_type == 'c':
            recipient = 'c'
        if fare.ticket_type == 'conference':
            # you cannot buy tickets for different entity types (user/company)
            conference_recipients.add('c' if fare.recipient_type ==
                                      'c' else 'p')
    if len(conference_recipients) > 1:
        raise ValueError('mismatched fares: %s' % ','.join(x[0].code
                                                           for x in tickets))

    if recipient == 'p':
        cform = P3BillingData
    else:
        cform = P3BillingDataCompany

    coupon = request.session['user-cart']['coupon']
    totals = amodels.Order.calculator(items=tickets,
                                      coupons=[coupon] if coupon else None,
                                      user=request.user.assopy_user)

    if request.method == 'POST':
        auser = request.user.assopy_user
        post_data = request.POST.copy()

        order_data = None
        if totals['total'] == 0:
            # free order, I'm only interested in knowing the user accepted the code of conduct.
            if 'code_conduct' in request.POST:
                order_data = {
                    'payment': 'bank',
                }
            else:
                # if it wasn't accepted the form is prepared and the user
                # will see the checkbox in red
                form = cform(instance=auser, data=post_data)
                form.is_valid()
        else:
            form = cform(instance=auser, data=post_data)
            if form.is_valid():
                order_data = form.cleaned_data
                form.save()

        if order_data:
            coupon = request.session['user-cart']['coupon']
            kw = dict(
                user=auser,
                payment=order_data['payment'],
                billing_notes=order_data.get('billing_notes', ''),
                items=request.session['user-cart']['tickets'],
                coupons=[coupon] if coupon else None,
            )
            if recipient == 'p':
                kw['cf_code'] = auser.cf_code
            else:
                kw['vat_number'] = auser.vat_number

            o = amodels.Order.objects.create(**kw)
            if totals['total'] == 0:
                return HttpResponseRedirectSeeOther(reverse('assopy-tickets'))

            if settings.STRIPE_ENABLED and order_data['payment'] == 'cc':
                return redirect('assopy-stripe-checkout', pk=o.pk)
            elif order_data['payment'] in ('paypal', 'cc'):
                urlname = 'assopy-paypal-redirect' if order_data[
                    'payment'] == 'paypal' else 'assopy-cc-paypal-redirect'
                return HttpResponseRedirectSeeOther(
                    reverse(urlname,
                            kwargs={'code': unicode(o.code).replace('/',
                                                                    '-')}))
            elif o.payment_url:
                return HttpResponseRedirectSeeOther(o.payment_url)
            else:
                return HttpResponseRedirectSeeOther(
                    reverse('assopy-bank-feedback-ok',
                            kwargs={'code': o.code.replace('/', '-')}))
    else:
        auser = request.user.assopy_user
        if not auser.card_name:
            auser.card_name = '%s %s' % (request.user.first_name,
                                         request.user.last_name)
        form = cform(instance=auser)

    ctx = {
        'totals': totals,
        'form': form,
    }
    return render(request, 'p3/billing.html', ctx)
Exemple #6
0
def billing(request):
    try:
        tickets = request.session['user-cart']['tickets']
    except KeyError:
        # la sessione non ha più la chiave user-cart, invece che sollevare un
        # errore 500 rimando l'utente sul carrello
        return redirect('p3-cart')

    recipient = 'p'
    conference_recipients = set()
    for fare, foo in tickets:
        if fare.recipient_type == 'c':
            recipient = 'c'
        if fare.ticket_type == 'conference':
            # non si possono comprare biglietti destinati ad entità diverse
            # (persone/ditte)
            conference_recipients.add('c' if fare.recipient_type ==
                                      'c' else 'p')
    if len(conference_recipients) > 1:
        raise ValueError('mismatched fares: %s' % ','.join(x[0].code
                                                           for x in tickets))

    if recipient == 'p':
        cform = P3BillingData
    else:
        cform = P3BillingDataCompany

    coupon = request.session['user-cart']['coupon']
    totals = amodels.Order.calculator(items=tickets,
                                      coupons=[coupon] if coupon else None,
                                      user=request.user.assopy_user)

    if request.method == 'POST':
        auser = request.user.assopy_user
        post_data = request.POST.copy()

        order_data = None
        if totals['total'] == 0:
            # free order, mi interessa solo sapere che l'utente ha accettato il
            # code of conduct
            if 'code_conduct' in request.POST:
                order_data = {
                    'payment': 'bank',
                }
            else:
                # se non lo ha accettato, preparo la form, e l'utente si
                # troverà la checkbox colorata in rosso
                form = cform(instance=auser, data=post_data)
                form.is_valid()
        else:
            form = cform(instance=auser, data=post_data)
            if form.is_valid():
                order_data = form.cleaned_data
                form.save()

        if order_data:
            coupon = request.session['user-cart']['coupon']
            kw = dict(
                user=auser,
                payment=order_data['payment'],
                billing_notes=order_data.get('billing_notes', ''),
                items=request.session['user-cart']['tickets'],
                coupons=[coupon] if coupon else None,
            )
            if recipient == 'p':
                kw['cf_code'] = auser.cf_code
            else:
                kw['vat_number'] = auser.vat_number

            o = amodels.Order.objects.create(**kw)
            if totals['total'] == 0:
                return HttpResponseRedirectSeeOther(reverse('assopy-tickets'))

            if order_data['payment'] in ('paypal', 'cc'):
                urlname = 'assopy-paypal-redirect' if order_data[
                    'payment'] == 'paypal' else 'assopy-cc-paypal-redirect'
                return HttpResponseRedirectSeeOther(
                    reverse(urlname,
                            kwargs={'code': unicode(o.code).replace('/',
                                                                    '-')}))
            elif o.payment_url:
                return HttpResponseRedirectSeeOther(o.payment_url)
            else:
                return HttpResponseRedirectSeeOther(
                    reverse('assopy-bank-feedback-ok',
                            kwargs={'code': o.code.replace('/', '-')}))
    else:
        auser = request.user.assopy_user
        if not auser.card_name:
            auser.card_name = '%s %s' % (request.user.first_name,
                                         request.user.last_name)
        form = cform(instance=auser)

    ctx = {
        'totals': totals,
        'form': form,
    }
    return render(request, 'p3/billing.html', ctx)