Esempio n. 1
0
def purchase_tickets():
    tickets = app.config['TICKETS']
    form = forms.PurchaseForm()
    if form.validate_on_submit():
        purchase = Purchase()
        purchase.date = datetime.now()
        form.populate_obj(purchase)

        # First thing that we need to do is check to make sure that the email
        # actually is a .edu address.  If not, tell the user they f****d up and
        # set it back to attendee.
        if purchase.ticket_type == 'student' and purchase.email[-3:] != 'edu':
            flash('Not a student, defaulting to Attendee')
            # The student was a lie!  Reset it to attendee.
            purchase.ticket_type = 'attendee'
            purchase.price = tickets[purchase.ticket_type]['price']

        # Next we need to match up the ticket types to make sure that no one
        # was mucking about with the ticket types.  If everything matches, then
        # go ahead and trust what the form is telling us and apply the price.
        if (purchase.ticket_type in tickets
                and tickets[purchase.ticket_type]['visible'] and
            (tickets[purchase.ticket_type]['expiration'] is None
             or date.today() < tickets[purchase.ticket_type]['expiration'])):
            purchase.price = tickets[purchase.ticket_type]['price']
        else:
            flash('Invalid Ticket Type...resetting to Attendee')
            # If it looks like someone was actually sending odd form values,
            # then we wont trust the ticket type and override it with a regular
            # attendee ticket type.
            purchase.ticket_type = 'attendee'
            purchase.price = tickets[purchase.ticket_type]['price']
        if form.discountcode.data != '':
            # Lets check to see if the discount code is valid.  If it is, then
            # we will be overriding the price and the ticket type associated
            # with this purchase.
            code = DiscountCode.query.filter_by(
                code=form.discountcode.data).first()
            if code is None or code.uses < 1:
                flash('Invalid or Expired Discount Code')
            else:
                purchase.price = code.price
                purchase.ticket_type = code.t_type

        # Add the purchase to the database and then return the confirmation page.
        db.session.add(purchase)
        db.session.commit()
        return render_template('ticketing/confirm.html',
                               purchase=purchase,
                               title='Purchase Confirmation',
                               stripe_key=app.config['STRIPE_PKEY'])
    return render_template('ticketing/purchase.html',
                           form=form,
                           title='Ticket Purchasing')
Esempio n. 2
0
def purchase_tickets():
    tickets = app.config['TICKETS']
    form = forms.PurchaseForm()
    if form.validate_on_submit():
        purchase = Purchase()
        purchase.date = datetime.now()
        form.populate_obj(purchase)

        # First thing that we need to do is check to make sure that the email
        # actually is a .edu address.  If not, tell the user they f****d up and
        # set it back to attendee. 
        if purchase.ticket_type == 'student' and purchase.email[-3:] != 'edu':
            flash('Not a student, defaulting to Attendee')
            # The student was a lie!  Reset it to attendee.
            purchase.ticket_type = 'attendee'
            purchase.price = tickets[purchase.ticket_type]['price']
        
        # Next we need to match up the ticket types to make sure that no one
        # was mucking about with the ticket types.  If everything matches, then
        # go ahead and trust what the form is telling us and apply the price.
        if (purchase.ticket_type in tickets 
            and tickets[purchase.ticket_type]['visible']
            and (tickets[purchase.ticket_type]['expiration'] is None
                or date.today() < tickets[purchase.ticket_type]['expiration'])):
            purchase.price = tickets[purchase.ticket_type]['price']
        else:
            flash('Invalid Ticket Type...resetting to Attendee')
            # If it looks like someone was actually sending odd form values,
            # then we wont trust the ticket type and override it with a regular
            # attendee ticket type.
            purchase.ticket_type = 'attendee'
            purchase.price = tickets[purchase.ticket_type]['price']
        if form.discountcode.data != '':
            # Lets check to see if the discount code is valid.  If it is, then
            # we will be overriding the price and the ticket type associated
            # with this purchase.
            code = DiscountCode.query.filter_by(code=form.discountcode.data).first()
            if code is None or code.uses < 1:
                flash('Invalid or Expired Discount Code')
            else:
                purchase.price = code.price
                purchase.ticket_type = code.t_type

        # Add the purchase to the database and then return the confirmation page.
        db.session.add(purchase)
        db.session.commit()
        return render_template('ticketing/confirm.html', 
            purchase=purchase, 
            title='Purchase Confirmation',
            stripe_key=app.config['STRIPE_PKEY'])
    return render_template('ticketing/purchase.html', 
            form=form,
            title='Ticket Purchasing')
Esempio n. 3
0
def homepage(request):
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = PurchaseForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            data = form.cleaned_data

            purchase = Purchase()

            purchase.category = data['category']
            purchase.price = data['price']

            purchase.save()

    form = PurchaseForm()
    categories = Category.objects.all()
    today = datetime.date.today()

    month = request.GET.get('month', today.month)
    year = request.GET.get('year', today.year)

    purchases = Purchase.objects.filter(date__year=year, date__month=month).order_by('-date')
    x = [category.name for category in categories]
    y = [category.total_in_month(month, year) for category in categories]
    limits = [category.limit for category in categories]
    colors = [category.color for category in categories]

    return render(
        request,
        'homepage.html',
        {
            'form': form,
            'today': today,
            'categories': categories,
            'purchases': purchases,
            'plot': {
                'x': x,
                'y': y,
                'colors': colors,
                'limits': limits,
                'total_limits': sum(limits),
                'xyc': zip(x, y, colors)
            }
        }
    )