Пример #1
0
 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
    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))
Пример #3
0
    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))
Пример #4
0
 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)
Пример #5
0
    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())
Пример #6
0
def oneup(star_id):
    """
    Issue a 1up to a Star using the currently activated Persona

    Args:
        star_id (string): ID of the Star
    """
    star = Star.query.get_or_404(star_id)
    try:
        oneup = star.toggle_oneup()
    except PersonaNotFoundError:
        error_message = "Please activate a Persona for upvoting"
        oneup = None

    resp = dict()
    if oneup is None:
        resp = {
            "meta": {
                "oneup_count": star.oneup_count(),
                "error_message": error_message
            }
        }
    else:
        resp = {
            "meta": {
                "oneup_count": star.oneup_count(),
            },
            "oneups": [{
                "id": oneup.id,
                "author": oneup.author.id,
                "state_value": oneup.state,
                "state_name": oneup.get_state()
            }]
        }
    return json_response(resp)
Пример #7
0
    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
def oneup(star_id):
    """
    Issue a 1up to a Star using the currently activated Persona

    Args:
        star_id (string): ID of the Star
    """
    star = Star.query.get_or_404(star_id)
    try:
        oneup = star.toggle_oneup()
    except PersonaNotFoundError:
        error_message = "Please activate a Persona for upvoting"
        oneup = None

    resp = dict()
    if oneup is None:
        resp = {
            "meta": {
                "oneup_count": star.oneup_count(),
                "error_message": error_message
            }
        }
    else:
        resp = {
            "meta": {
                "oneup_count": star.oneup_count(),
            },
            "oneups": [{
                "id": oneup.id,
                "author": oneup.author.id,
                "state_value": oneup.state,
                "state_name": oneup.get_state()
            }]
        }

        message_oneup = {
            "author_id": oneup.author.id,
            "action": "insert" if len(oneup.vesicles)==0 else "update",
            "object_id": oneup.id,
            "object_type": "Oneup",
            "recipients": star.author.contacts.all() + [star.author, ]
        }

        local_model_changed.send(oneup, message=message_oneup)
    return json_response(resp)
Пример #9
0
 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
 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))