def post(self): form = CreateEventForm(data_to_multidict(request.json)) if form.validate(): admin = Admin.get_by_email(form.admin_email.data) if not admin: admin = form.create_admin() event = Event(name=form.name.data, admin=admin) event.save() return json_response(event.get_json_data(url_for)) else: return json_response(form.errors)
def index(): event_form = CreateEventForm(request.form) events = Event.query.all() if request.method == 'POST' and event_form.validate(): admin = Admin.get_by_email(event_form.admin_email.data) if not admin: admin = event_form.create_admin() event = Event(name=event_form.name.data, admin=admin) event.save() return redirect(url_for('event_details', slug=event.slug)) return render_template('index.html', **locals())
def post(self): form = CreateEventForm(data_to_multidict(request.json)) if form.validate(): admin = Admin.get_by_email(form.admin_email.data) if not admin: admin = form.create_admin() event = Event( name=form.name.data, admin=admin ) event.save() return json_response(event.get_json_data(url_for)) else: return json_response(form.errors)
def get(self, event_slug, payer_id): event = Event.get_by_slug(event_slug) if not event: abort(404) if payer_id is None: payers = [payer.get_json_data(url_for) for payer in event.payers] data = {'payers': payers} return json_response(data) else: payer = Payer.get_by_id_and_event_id(payer_id, event.id) if not payer: abort(404) return json_response(payer.get_json_data(url_for))
def get(self, event_slug, expense_id): event = Event.get_by_slug(event_slug) if not event: abort(404) if expense_id is None: expenses = [expense.get_json_data(url_for) for expense in event.expenses] data = {'expenses': expenses} return json_response(data) else: expense = Expense.get_by_id_and_event_id(expense_id, event.id) if not expense: abort(404) return json_response(expense.get_json_data())
def get(self, event_slug, expense_id): event = Event.get_by_slug(event_slug) if not event: abort(404) if expense_id is None: expenses = [ expense.get_json_data(url_for) for expense in event.expenses ] data = {'expenses': expenses} return json_response(data) else: expense = Expense.get_by_id_and_event_id(expense_id, event.id) if not expense: abort(404) return json_response(expense.get_json_data())
def get_event_or_abort(slug): event = Event.get_by_slug(slug) if not event or event.is_deleted(): abort(404) return event
def get(self, event_slug): event = Event.get_by_slug(event_slug) if not event: abort(404) return json_response(event.get_json_data(url_for))