def tickets_token(token=None): tts = TicketType.get_types_for_token(token) if tts: session['ticket_token'] = token else: if 'ticket_token' in session: del session['ticket_token'] flash('Ticket token was invalid') if any(tt.admits in ['full', 'kid'] for tt in tts): return redirect(url_for('tickets.choose')) return redirect(url_for('tickets.choose', flow='other'))
def tickets_token(token=None): tts = TicketType.get_types_for_token(token) if tts: session['ticket_token'] = token else: if 'ticket_token' in session: del session['ticket_token'] flash('Ticket token was invalid') if any(tt.admits in ['full', 'kid'] for tt in tts): return redirect(url_for('tickets.choose')) return redirect(url_for('tickets.choose', flow='other'))
def choose(flow=None): token = session.get('ticket_token') sales_state = get_sales_state() if flow is None: admissions = True elif flow == 'other': admissions = False else: abort(404) if sales_state in ['unavailable', 'sold-out']: # For the main entry point, we assume people want admissions tickets, # but we still need to sell people e.g. parking tickets or tents until # the final cutoff (sales-ended). if not admissions: sales_state = 'available' # Allow people with valid discount tokens to buy tickets elif token is not None and TicketType.get_types_for_token(token): sales_state = 'available' if app.config.get('DEBUG'): sales_state = request.args.get("sales_state", sales_state) if sales_state == 'available': pass elif not current_user.is_anonymous() and current_user.has_permission( 'admin'): pass else: return render_template("tickets-cutoff.html") form = TicketAmountsForm() # If this is the main page, exclude tents and other paraphernalia. # For the non-admissions page, only exclude actual admissions tickets. # This means both pages show parking and caravan tickets. if admissions: tts = TicketType.query.filter(~TicketType.admits.in_(['other'])) else: tts = TicketType.query.filter(~TicketType.admits.in_(['full', 'kid'])) tts = tts.order_by(TicketType.order).all() limits = dict((tt.id, tt.user_limit(current_user, token)) for tt in tts) if request.method != 'POST': # Empty form - populate ticket types for tt in tts: form.types.append_entry() form.types[-1].type_id.data = tt.id tts = {tt.id: tt for tt in tts} for f in form.types: t_id = f.type_id.data f._type = tts[t_id] values = range(limits[t_id] + 1) f.amount.values = values f._any = any(values) if form.validate_on_submit(): if form.buy.data or form.buy_other.data: set_user_currency(form.currency_code.data) basket = [] for f in form.types: if f.amount.data: tt = f._type app.logger.info('Adding %s %s tickets to basket', f.amount.data, tt.name) basket += [tt.id] * f.amount.data if basket: session['basket'] = basket return redirect(url_for('tickets.pay', flow=flow)) elif admissions: flash("Please select at least one ticket to buy.") else: flash("Please select at least one item to buy.") if request.method == 'POST' and form.set_currency.data: if form.set_currency.validate(form): app.logger.info("Updating currency to %s only", form.set_currency.data) set_user_currency(form.set_currency.data) for field in form: field.errors = [] form.currency_code.data = get_user_currency() return render_template("tickets-choose.html", form=form, admissions=admissions)
def choose(flow=None): token = session.get('ticket_token') sales_state = get_sales_state() if flow is None: admissions = True elif flow == 'other': admissions = False else: abort(404) if sales_state in ['unavailable', 'sold-out']: # For the main entry point, we assume people want admissions tickets, # but we still need to sell people e.g. parking tickets or tents until # the final cutoff (sales-ended). if not admissions: sales_state = 'available' # Allow people with valid discount tokens to buy tickets elif token is not None and TicketType.get_types_for_token(token): sales_state = 'available' if app.config.get('DEBUG'): sales_state = request.args.get("sales_state", sales_state) if sales_state == 'available': pass elif not current_user.is_anonymous() and current_user.has_permission('admin'): pass else: return render_template("tickets-cutoff.html") form = TicketAmountsForm() # If this is the main page, exclude tents and other paraphernalia. # For the non-admissions page, only exclude actual admissions tickets. # This means both pages show parking and caravan tickets. if admissions: tts = TicketType.query.filter(~TicketType.admits.in_(['other'])) else: tts = TicketType.query.filter(~TicketType.admits.in_(['full', 'kid'])) tts = tts.order_by(TicketType.order).all() limits = dict((tt.id, tt.user_limit(current_user, token)) for tt in tts) if request.method != 'POST': # Empty form - populate ticket types for tt in tts: form.types.append_entry() form.types[-1].type_id.data = tt.id tts = {tt.id: tt for tt in tts} for f in form.types: t_id = f.type_id.data f._type = tts[t_id] values = range(limits[t_id] + 1) f.amount.values = values f._any = any(values) if form.validate_on_submit(): if form.buy.data or form.buy_other.data: set_user_currency(form.currency_code.data) basket = [] for f in form.types: if f.amount.data: tt = f._type app.logger.info('Adding %s %s tickets to basket', f.amount.data, tt.name) basket += [tt.id] * f.amount.data if basket: session['basket'] = basket return redirect(url_for('tickets.pay', flow=flow)) elif admissions: flash("Please select at least one ticket to buy.") else: flash("Please select at least one item to buy.") if request.method == 'POST' and form.set_currency.data: if form.set_currency.validate(form): app.logger.info("Updating currency to %s only", form.set_currency.data) set_user_currency(form.set_currency.data) for field in form: field.errors = [] form.currency_code.data = get_user_currency() return render_template("tickets-choose.html", form=form, admissions=admissions)