示例#1
0
文件: api.py 项目: alphabits/stingy
 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)
示例#2
0
文件: views.py 项目: alphabits/stingy
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())
示例#3
0
文件: api.py 项目: alphabits/stingy
 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)
示例#4
0
文件: api.py 项目: alphabits/stingy
    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))
示例#5
0
文件: api.py 项目: alphabits/stingy
    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))
示例#6
0
文件: api.py 项目: alphabits/stingy
    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())
示例#7
0
文件: api.py 项目: alphabits/stingy
    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())
示例#8
0
文件: views.py 项目: alphabits/stingy
def get_event_or_abort(slug):
    event = Event.get_by_slug(slug)
    if not event or event.is_deleted():
        abort(404)
    return event
示例#9
0
文件: api.py 项目: alphabits/stingy
 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))
示例#10
0
文件: api.py 项目: alphabits/stingy
 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))