Пример #1
0
        async def wrapped(request, *args, **kwargs):
            if '_csrf' in request.cookies:
                csrf_token = request.cookies['_csrf']
            else:
                csrf_token = new_csrf_token()

            context = await f(request, *args, **kwargs)
            context['csrf_token'] = csrf_token
            context['base_path'] = deploy_config.base_path('atgu')

            response = aiohttp_jinja2.render_template(file, request, context)
            response.set_cookie('_csrf', csrf_token, domain=os.environ['HAIL_DOMAIN'], secure=True, httponly=True)
            return response
async def render_template(service, request, userdata, file, page_context):
    if '_csrf' in request.cookies:
        csrf_token = request.cookies['_csrf']
    else:
        csrf_token = new_csrf_token()

    session = await aiohttp_session.get_session(request)
    context = base_context(session, userdata, service)
    context.update(page_context)
    context['csrf_token'] = csrf_token

    response = aiohttp_jinja2.render_template(file, request, context)
    response.set_cookie('_csrf', csrf_token, domain=os.environ['HAIL_DOMAIN'], secure=True, httponly=True)
    return response
Пример #3
0
async def index(request, userdata):  # pylint: disable=unused-argument
    app = request.app
    dbpool = app['dbpool']
    wb_configs = []
    for i, wb in enumerate(watched_branches):
        if wb.prs:
            pr_configs = []
            for pr in wb.prs.values():
                batch_id = pr.batch.id if pr.batch and hasattr(pr.batch,
                                                               'id') else None
                build_state = pr.build_state if await pr.authorized(
                    dbpool) else 'unauthorized'
                if build_state is None and batch_id is not None:
                    build_state = 'building'

                pr_config = {
                    'number':
                    pr.number,
                    'title':
                    pr.title,
                    # FIXME generate links to the merge log
                    'batch_id':
                    pr.batch.id
                    if pr.batch and hasattr(pr.batch, 'id') else None,
                    'build_state':
                    build_state,
                    'review_state':
                    pr.review_state,
                    'author':
                    pr.author,
                    'out_of_date':
                    pr.build_state in ['failure', 'success', None]
                    and not pr.is_up_to_date(),
                }
                pr_configs.append(pr_config)
        else:
            pr_configs = None
        # FIXME recent deploy history
        wb_config = {
            'index':
            i,
            'branch':
            wb.branch.short_str(),
            'sha':
            wb.sha,
            # FIXME generate links to the merge log
            'deploy_batch_id':
            wb.deploy_batch.id
            if wb.deploy_batch and hasattr(wb.deploy_batch, 'id') else None,
            'deploy_state':
            wb.deploy_state,
            'repo':
            wb.branch.repo.short_str(),
            'prs':
            pr_configs,
        }
        wb_configs.append(wb_config)

    token = new_csrf_token()

    context = {
        'watched_branches': wb_configs,
        'age': humanize.naturaldelta(datetime.datetime.now() - start_time),
        'token': token
    }

    response = aiohttp_jinja2.render_template('index.html', request, context)
    response.set_cookie('_csrf', token, secure=True, httponly=True)
    return response