Beispiel #1
0
async def suggest_edit_save(request):
    secret = request.match_info['secret']

    context = default_context()

    data = await request.post()
    context.update(data)
    context['edit'] = "{}://{}{}".format(request.scheme, request.host, request.path_qs)
    for level in 'TRAINEE', 'JUNIOR', 'MIDDLE', 'SENIOR':
        context["is_{}".format(level)] = data.get('level') == level

    checked = None
    try:
        checked = EVENT_SUGGESTION_TRAFARET.check(data)
    except t.DataError as e:
        context['error'] = [{"key": k, "error": str(v)} for k,v in e.error.items()]

    if checked:
        checked['team'] = EVENTSMONKEY_TEAM
        api = EventsMonkey(EVENTSMONKEY_URL)
        suggested = api.edit(secret, checked)
        return HTTPFound(request.app.router['edit_suggested'].url(parts={"secret": suggested['secret']}))

    html = await make_template(request, "suggest_event", context)
    return Response(body=html, headers={'Content-type': 'text/html; charset=utf-8'})
Beispiel #2
0
async def suggest_edit(request):
    secret = request.match_info['secret']

    context = default_context()

    api = EventsMonkey(EVENTSMONKEY_URL)
    data = api.get(secret)
    context.update(data)
    context['edit'] = "{}://{}{}".format(request.scheme, request.host, request.path_qs)

    for level in 'TRAINEE', 'JUNIOR', 'MIDDLE', 'SENIOR':
        context["is_{}".format(level)] = data.get('level') == level

    html = await make_template(request, "suggest_event", context)
    return Response(body=html, headers={'Content-type': 'text/html; charset=utf-8'})