Exemple #1
0
def render_template(template, content=None, **context):
    context['site'] = get_current_site_info()
    context['user'] = get_current_user_info()

    context['content'] = content

    return render_theme_template('default', template, **context)
def render_admin(template, **context):
    context['bootstrap_theme'] = context.get('bootstrap_theme', get_setting('bootstrap-theme', 'yeti'))
    context['syntax_highlighting_theme'] = context.get('syntax_highlighting_theme', get_setting('syntax-highlighting-theme', 'monokai.css'))
    context['blog_title'] = context.get('blog_title', get_setting('blog-title', 'Blog Title'))
    context['blog_copyright'] = context.get('blog_copyright', get_setting('blog-copyright', 'Blog Copyright'))
    context['freeze'] = context.get('freeze')
    return render_theme_template(get_theme('admin'), template, **context)
Exemple #3
0
def get_session_expired(eq_id, form_type, collection_id):  # pylint: disable=unused-argument
    schema = load_schema_from_params(eq_id, form_type)
    return render_theme_template(
        schema['theme'],
        template_name='session-expired.html',
        analytics_ua_id=current_app.config['EQ_UA_ID'],
        survey_title=TemplateRenderer.safe_content(schema['title']))
Exemple #4
0
def get_view_submission(schema, eq_id, form_type):  # pylint: disable=unused-argument

    session_data = get_session_store().session_data

    if _is_submission_viewable(schema.json, session_data.submitted_time):
        submitted_data = data_access.get_by_key(SubmittedResponse,
                                                session_data.tx_id)

        if submitted_data:

            metadata_context = build_metadata_context_for_survey_completed(
                session_data)

            pepper = current_app.eq['secret_store'].get_secret_by_name(
                'EQ_SERVER_SIDE_STORAGE_ENCRYPTION_USER_PEPPER')
            encrypter = StorageEncryption(current_user.user_id,
                                          current_user.user_ik, pepper)

            submitted_data = json.loads(
                encrypter.decrypt_data(submitted_data.data))
            answer_store = AnswerStore(
                existing_answers=submitted_data.get('answers'))

            metadata = submitted_data.get('metadata')

            routing_path = PathFinder(schema, answer_store, metadata,
                                      []).get_full_routing_path()

            schema_context = _get_schema_context(routing_path, 0, metadata,
                                                 answer_store, schema)
            rendered_schema = renderer.render(schema.json, **schema_context)
            summary_rendered_context = build_summary_rendering_context(
                schema, rendered_schema['sections'], answer_store, metadata)

            context = {
                'summary': {
                    'groups':
                    summary_rendered_context,
                    'answers_are_editable':
                    False,
                    'is_view_submission_response_enabled':
                    is_view_submitted_response_enabled(schema.json),
                },
                'variables': None,
            }

            return render_theme_template(
                schema.json['theme'],
                template_name='view-submission.html',
                metadata=metadata_context,
                analytics_ua_id=current_app.config['EQ_UA_ID'],
                survey_id=schema.json['survey_id'],
                survey_title=TemplateRenderer.safe_content(
                    schema.json['title']),
                content=context)

    return redirect(
        url_for('post_submission.get_thank_you',
                eq_id=eq_id,
                form_type=form_type))
Exemple #5
0
def render(template, **context):
    '''
    Render a template with uData frontend specifics

        * Theme
    '''
    theme = current_app.config['THEME']
    return render_theme_template(get_theme(theme), template, **context)
Exemple #6
0
def render(template, **context):
    '''
    Render a template with uData frontend specifics

        * Theme
    '''
    theme = current_app.config['THEME']
    return render_theme_template(get_theme(theme), template, **context)
Exemple #7
0
def render_template(template, content=None, **context):
    context['site'] = get_current_site_info()
    context['user'] = get_current_user_info()

    context['content'] = content

    return render_theme_template(context['site']['settings']['theme'],
                                 template, **context)
def render_template(template, context, previous_location):
    try:
        theme = context['meta']['survey']['theme']
        logger.debug("Theme selected: {} ".format(theme))
    except KeyError:
        logger.info("No theme set ")
        theme = None
    return render_theme_template(theme, template, meta=context['meta'], content=context['content'], previous_location=previous_location)
Exemple #9
0
def render_template(template, **context):  # pragma: no cover
    """A helper function that uses the `render_theme_template` function
    without needing to edit all the views
    """
    if current_user.is_authenticated and current_user.theme:
        theme = current_user.theme
    else:
        theme = session.get('theme', flaskbb_config['DEFAULT_THEME'])
    return render_theme_template(theme, template, **context)
Exemple #10
0
def _render_error_page(status_code):
    tx_id = get_tx_id()
    user_agent = user_agent_parser.Parse(request.headers.get('User-Agent', ''))

    return render_theme_template('default', 'errors/error.html',
                                 status_code=status_code,
                                 analytics_ua_id=current_app.config['EQ_UA_ID'],
                                 account_service_url=cookie_session.get('account_service_url'),
                                 ua=user_agent, tx_id=tx_id), status_code
Exemple #11
0
def index():
    forums = Forum.query.all()

    for forum in forums:
        forum.url = format_url_friendly(forum.title)

    return render_theme_template("default", "forum/index.html",
                                 page_title="Hooome!",
                                 forums=forums)
Exemple #12
0
def render_template(template, **context):  # pragma: no cover
    """A helper function that uses the `render_theme_template` function
    without needing to edit all the views
    """
    if current_user.is_authenticated and current_user.theme:
        theme = current_user.theme
    else:
        theme = session.get('theme', flaskbb_config['DEFAULT_THEME'])
    return render_theme_template(theme, template, **context)
Exemple #13
0
def index():
    dummy_objects = DummyObject.query.all()
    dummy_files = DummyFile.query.all()
    # print(dummy_objects)
    # print(dummy_files)
    return render_theme_template(get_current_theme(),
                                 'index.html',
                                 dummy_objects=dummy_objects,
                                 dummy_files=dummy_files)
Exemple #14
0
def _render_template(context, block_id, front_end_navigation=None, metadata_context=None, previous_url=None, template=None):
    theme = g.schema_json.get('theme', None)
    logger.debug("Theme selected: %s", theme)
    template = '{}.html'.format(template or block_id)
    return render_theme_template(theme, template, meta=metadata_context,
                                 content=context,
                                 previous_location=previous_url,
                                 navigation=front_end_navigation,
                                 schema_title=g.schema_json['title'],
                                 legal_basis=g.schema_json['legal_basis'])
Exemple #15
0
def render_template(template, **kwargs):
    theme = g.schema.json.get('theme')
    template = '{}.html'.format(template).lower()

    return render_theme_template(theme,
                                 template,
                                 survey_title=TemplateRenderer.safe_content(
                                     g.schema.json['title']),
                                 survey_id=g.schema.json['survey_id'],
                                 **kwargs)
Exemple #16
0
def get_sign_out():
    logout_user()

    return render_theme_template(
        cookie_session.get('theme', 'default'),
        template_name='signed-out.html',
        analytics_ua_id=current_app.config['EQ_UA_ID'],
        account_service_url=cookie_session.get('account_service_url'),
        survey_title=TemplateRenderer.safe_content(
            cookie_session.get('survey_title', '')))
Exemple #17
0
def render_template(template_name):
    tx_id = get_tx_id()
    user_agent = user_agent_parser.Parse(request.headers.get('User-Agent', ''))

    return render_theme_template(cookie_session.get('theme', 'default'),
                                 template_name=template_name,
                                 analytics_ua_id=current_app.config['EQ_UA_ID'],
                                 ua=user_agent,
                                 tx_id=tx_id,
                                 account_service_url=cookie_session.get('account_service_url'),
                                 survey_title=TemplateRenderer.safe_content(cookie_session.get('survey_title', '')))
Exemple #18
0
def settings():
    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)

    cookie_template = render_theme_template(theme=cookie_session.get('theme', 'default'),
                                            analytics_gtm_id=current_app.config['EQ_GTM_ID'],
                                            analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
                                            cookie_message=cookie_message,
                                            allow_analytics=allow_analytics,
                                            template_name='static/cookies-settings.html')
    return cookie_template
Exemple #19
0
def render_template(template, **context):  # pragma: no cover
    """A helper function that uses the `render_theme_template` function
    without needing to edit all the views
    """
    #~ print("flask_config : %s"%flask_config)
    #~ for key in janitoo_config:
        #~ print "%s"%janitoo_config[key]
    if current_user.is_authenticated and current_user.theme:
        theme = current_user.theme
    else:
        theme = session.get('theme', flask_config['DEFAULT_THEME'])
    return render_theme_template(theme, template, **context)
def render(template, **context):
    context['bootstrap_theme'] = context.get('bootstrap_theme', get_setting('bootstrap-theme', 'yeti'))
    context['syntax_highlighting_theme'] = context.get('syntax_highlighting_theme', get_setting('syntax-highlighting-theme', 'monokai.css'))
    context['blog_title'] = context.get('blog_title', get_setting('blog-title', 'Blog Title'))
    context['blog_copyright'] = context.get('blog_copyright', get_setting('blog-copyright', 'Blog Copyright'))
    context['freeze'] = context.get('freeze')
    content = context.get('content')
    if content:
        theme = content.theme or get_current_theme()
    else:
        theme = 'impression'

    return render_theme_template(theme, template, **context)
Exemple #21
0
def render_template(template, **kwargs):
    theme = g.schema.json.get('theme')
    template = '{}.html'.format(template).lower()

    return render_theme_template(
        theme,
        template,
        survey_title=TemplateRenderer.safe_content(g.schema.json['title']),
        account_service_url=cookie_session.get('account_service_url'),
        account_service_log_out_url=cookie_session.get(
            'account_service_log_out_url'),
        survey_id=g.schema.json['survey_id'],
        **kwargs)
Exemple #22
0
def view_forum_topics(forum_id_or_title):
    #if it isn't convertible to a number, it is the url-friendly forum name
    if not forum_id_or_title.isdigit():
        forum_id_or_title = Forum.query.\
            filter_by(title=format_url_friendly(forum_id_or_title, True)).first_or_404().id

    #at this point it should guaranteed be the forum id
    forum_topics = Topic.query.filter_by(forum_id=forum_id_or_title)

    for topic in forum_topics:
        topic.url = format_url_friendly(topic.title)

    return render_theme_template("default", "forum/forum.html",
                                 page_title="Forum info",
                                 topics=forum_topics)
Exemple #23
0
def get_thank_you(schema, metadata, eq_id, form_type):
    session_data = get_session_store().session_data
    completeness = get_completeness(current_user)

    if session_data.submitted_time:
        metadata_context = build_metadata_context_for_survey_completed(
            session_data)

        view_submission_url = None
        view_submission_duration = 0
        if _is_submission_viewable(schema.json, session_data.submitted_time):
            view_submission_url = url_for('.get_view_submission',
                                          eq_id=eq_id,
                                          form_type=form_type)
            view_submission_duration = humanize.naturaldelta(
                timedelta(seconds=schema.json['view_submitted_response']
                          ['duration']))

        cookie_message = request.cookies.get('ons_cookie_message_displayed')
        allow_analytics = analytics_allowed(request)

        return render_theme_template(
            schema.json['theme'],
            template_name='thank-you.html',
            metadata=metadata_context,
            analytics_gtm_id=current_app.config['EQ_GTM_ID'],
            analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
            survey_id=schema.json['survey_id'],
            survey_title=TemplateRenderer.safe_content(schema.json['title']),
            is_view_submitted_response_enabled=
            is_view_submitted_response_enabled(schema.json),
            view_submission_url=view_submission_url,
            account_service_url=cookie_session.get('account_service_url'),
            account_service_log_out_url=cookie_session.get(
                'account_service_log_out_url'),
            view_submission_duration=view_submission_duration,
            cookie_message=cookie_message,
            allow_analytics=allow_analytics)

    routing_path = path_finder.get_full_routing_path()

    router = Router(schema, routing_path, completeness)
    next_location = router.get_next_location()

    return _redirect_to_location(metadata['collection_exercise_sid'],
                                 metadata.get('eq_id'),
                                 metadata.get('form_type'), next_location)
Exemple #24
0
def _render_error_page(status_code):
    tx_id = get_tx_id()
    user_agent = user_agent_parser.Parse(request.headers.get('User-Agent', ''))

    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)
    return render_theme_template(
        'default',
        'errors/error.html',
        status_code=status_code,
        analytics_gtm_id=current_app.config['EQ_GTM_ID'],
        analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
        cookie_message=cookie_message,
        allow_analytics=allow_analytics,
        account_service_url=cookie_session.get('account_service_url'),
        ua=user_agent,
        tx_id=tx_id), status_code
def contact():
    session = None
    survey_id = None
    session_store = get_session_store()

    if session_store:
        session = session_store.session_data
        schema = load_schema_from_session_data(session)
        survey_id = schema.json['survey_id']

    contact_template = render_theme_template(
        theme=cookie_session.get('theme', 'default'),
        template_name='static/contact-us.html',
        session=session,
        survey_id=survey_id,
        analytics_ua_id=current_app.config['EQ_UA_ID'])
    return contact_template
Exemple #26
0
def render_template(template_name):
    tx_id = get_tx_id()
    user_agent = user_agent_parser.Parse(request.headers.get('User-Agent', ''))

    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)
    return render_theme_template(
        cookie_session.get('theme', 'default'),
        template_name=template_name,
        analytics_gtm_id=current_app.config['EQ_GTM_ID'],
        analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
        cookie_message=cookie_message,
        allow_analytics=allow_analytics,
        ua=user_agent,
        tx_id=tx_id,
        account_service_url=cookie_session.get('account_service_url'),
        survey_title=TemplateRenderer.safe_content(
            cookie_session.get('survey_title', '')))
def get_sign_out():
    """
    Signs the user first out of eq, then the account service by hitting the account services'
    logout url.
    """
    account_service_log_out_url = cookie_session.get(
        'account_service_log_out_url')
    logout_user()

    if account_service_log_out_url:
        return redirect(account_service_log_out_url)

    return render_theme_template(
        cookie_session.get('theme', 'default'),
        template_name='signed-out.html',
        analytics_ua_id=current_app.config['EQ_UA_ID'],
        account_service_url=cookie_session.get('account_service_url'),
        survey_title=TemplateRenderer.safe_content(
            cookie_session.get('survey_title', '')))
Exemple #28
0
def _render_template(context, current_location, template, front_end_navigation,
                     metadata_context, previous_url):
    theme = g.schema_json.get('theme', None)
    logger.debug("theme selected", theme=theme)
    session_timeout = current_app.config['EQ_SESSION_TIMEOUT_SECONDS']
    schema_session_timeout = g.schema_json.get('session_timeout_in_seconds')
    if schema_session_timeout is not None and schema_session_timeout < current_app.config[
            'EQ_SESSION_TIMEOUT_SECONDS']:
        session_timeout = schema_session_timeout
    session_timeout_prompt = g.schema_json.get(
        'session_prompt_in_seconds'
    ) or current_app.config['EQ_SESSION_TIMEOUT_PROMPT_SECONDS']

    survey_data = metadata_context['survey']
    url_prefix = '/questionnaire/{}/{}/{}'.format(survey_data['eq_id'],
                                                  survey_data['form_type'],
                                                  survey_data['collection_id'])

    page_title = get_page_title_for_location(g.schema_json, current_location)
    template = '{}.html'.format(template).lower()
    feedback_enable = False
    if settings.FEEDBACK_ENABLED_ALL or request.view_args[
            'form_type'] in settings.FEEDBACK_ENABLED_FOR:
        feedback_enable = True
    return render_theme_template(
        theme,
        template,
        meta=metadata_context,
        content=context,
        current_location=current_location,
        analytics_ua_id=current_app.config['EQ_UA_ID'],
        previous_location=previous_url,
        navigation=front_end_navigation,
        survey_title=TemplateRenderer.safe_content(g.schema_json['title']),
        legal_basis=g.schema_json['legal_basis'],
        survey_id=g.schema_json['survey_id'],
        session_timeout=session_timeout,
        session_timeout_prompt=session_timeout_prompt,
        url_prefix=url_prefix,
        page_title=page_title,
        feedback_enable=feedback_enable,
    )
Exemple #29
0
def render_template(template, **context):
    """
    For themes to work this replacement of flask.render_template must be used.

    INPUT:

    - As in flask.render_template

    OUTPUT:

    - As in flask.render_template, but if the current theme miss the template,
      the application's normal template is served.

    EXAMPLES::

        sage: from sagenb.util.templates import render_template
        sage: type(render_template)
    """
    theme = g.notebook.conf['theme']
    return render_theme_template(theme, template, **context)
Exemple #30
0
def get_thank_you(eq_id, form_type, collection_id):  # pylint: disable=unused-argument
    survey_completed_metadata = current_app.eq[
        'session_storage'].get_survey_completed_metadata()
    schema = load_schema_from_params(eq_id, form_type)

    if survey_completed_metadata:
        metadata_context = build_metadata_context_for_survey_completed(
            survey_completed_metadata)
        thank_you_template = render_theme_template(
            schema['theme'],
            template_name='thank-you.html',
            meta=metadata_context,
            analytics_ua_id=current_app.config['EQ_UA_ID'],
            survey_id=schema['survey_id'],
            survey_title=TemplateRenderer.safe_content(schema['title']))
        if settings.FEEDBACK_ENABLED_ALL or form_type in settings.FEEDBACK_ENABLED_FOR:
            session['feedback'] = True
            session['form_type'] = form_type
        return thank_you_template
    else:
        return _redirect_to_latest_location(collection_id, eq_id, form_type,
                                            schema)
Exemple #31
0
def get_thank_you(schema, metadata, eq_id, form_type):  # pylint: disable=unused-argument
    session_data = get_session_store().session_data
    completeness = get_completeness(current_user)

    if session_data.submitted_time:
        metadata_context = build_metadata_context_for_survey_completed(
            session_data)

        view_submission_url = None
        view_submission_duration = 0
        if _is_submission_viewable(schema.json, session_data.submitted_time):
            view_submission_url = url_for('.get_view_submission',
                                          eq_id=eq_id,
                                          form_type=form_type)
            view_submission_duration = humanize.naturaldelta(
                timedelta(seconds=schema.json['view_submitted_response']
                          ['duration']))

        return render_theme_template(
            schema.json['theme'],
            template_name='thank-you.html',
            metadata=metadata_context,
            analytics_ua_id=current_app.config['EQ_UA_ID'],
            survey_id=schema.json['survey_id'],
            survey_title=TemplateRenderer.safe_content(schema.json['title']),
            is_view_submitted_response_enabled=
            is_view_submitted_response_enabled(schema.json),
            view_submission_url=view_submission_url,
            view_submission_duration=view_submission_duration)

    routing_path = path_finder.get_full_routing_path()

    collection_id = metadata['collection_exercise_sid']

    router = Router(schema, routing_path, completeness)
    next_location = router.get_next_location()

    return _redirect_to_location(collection_id, metadata.get('eq_id'),
                                 metadata.get('form_type'), next_location)
Exemple #32
0
def contact():
    session = None
    survey_id = None
    session_store = get_session_store()

    if session_store:
        session = session_store.session_data
        schema = load_schema_from_session_data(session)
        survey_id = schema.json['survey_id']

    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)

    contact_template = render_theme_template(theme=cookie_session.get('theme', 'default'),
                                             template_name='static/contact-us.html',
                                             session=session,
                                             survey_id=survey_id,
                                             analytics_gtm_id=current_app.config['EQ_GTM_ID'],
                                             analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
                                             cookie_message=cookie_message,
                                             allow_analytics=allow_analytics)
    return contact_template
Exemple #33
0
def get_sign_out():
    """
    Signs the user first out of eq, then the account service by hitting the account services'
    logout url.
    """
    account_service_log_out_url = cookie_session.get('account_service_log_out_url')
    logout_user()

    if account_service_log_out_url:
        return redirect(account_service_log_out_url)

    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)

    return render_theme_template(cookie_session.get('theme', 'default'),
                                 template_name='signed-out.html',
                                 analytics_gtm_id=current_app.config['EQ_GTM_ID'],
                                 analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
                                 cookie_message=cookie_message,
                                 allow_analytics=allow_analytics,
                                 account_service_url=cookie_session.get('account_service_url'),
                                 survey_title=TemplateRenderer.safe_content(cookie_session.get('survey_title', '')))
Exemple #34
0
def render_template(template, **context):
    themeid = current_theme_id()
    return flask_themes2.render_theme_template(themeid, template, **context)
Exemple #35
0
def render(template, **context):
    from cert_viewer import app
    return render_theme_template(app.config['THEME'], template, **context)
Exemple #36
0
def render_template(template, **context):
    themeid = current_theme_id()
    return flask_themes2.render_theme_template(themeid, template, **context)
Exemple #37
0
def render_template(template, **context):
    return render_theme_template(get_current_theme(), template, **context)
Exemple #38
0
def _render_submission_page(session_data, submitted_data, schema, eq_id,
                            form_type):  # pylint: disable=unused-argument, too-many-locals

    metadata_context = build_metadata_context_for_survey_completed(
        session_data)

    pepper = current_app.eq['secret_store'].get_secret_by_name(
        'EQ_SERVER_SIDE_STORAGE_ENCRYPTION_USER_PEPPER')

    encrypter = StorageEncryption(current_user.user_id, current_user.user_ik,
                                  pepper)
    submitted_data = encrypter.decrypt_data(submitted_data.data)

    # for backwards compatibility
    # submitted data used to be base64 encoded before encryption
    try:
        submitted_data = base64url_decode(submitted_data.decode()).decode()
    except ValueError:
        pass

    submitted_data = json.loads(submitted_data)
    answer_store = AnswerStore(submitted_data.get('answers'))

    metadata = submitted_data.get('metadata')
    collection_metadata = submitted_data.get('collection_metadata')

    routing_path = PathFinder(schema, answer_store, metadata,
                              []).get_full_routing_path()

    schema_context = _get_schema_context(routing_path, None, metadata,
                                         collection_metadata, answer_store,
                                         schema)
    section_list = schema.json['sections']
    summary_rendered_context = build_summary_rendering_context(
        schema, section_list, answer_store, metadata, schema_context)

    context = {
        'summary': {
            'groups':
            summary_rendered_context,
            'answers_are_editable':
            False,
            'is_view_submission_response_enabled':
            is_view_submitted_response_enabled(schema.json),
        },
        'variables': None,
    }

    cookie_message = request.cookies.get('ons_cookie_message_displayed')
    allow_analytics = analytics_allowed(request)
    download_pdf_url = url_for('post_submission.download_pdf',
                               eq_id=eq_id,
                               form_type=form_type)

    return render_theme_template(
        schema.json['theme'],
        template_name='view-submission.html',
        metadata=metadata_context,
        download_pdf_url=download_pdf_url,
        analytics_gtm_id=current_app.config['EQ_GTM_ID'],
        analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'],
        survey_id=schema.json['survey_id'],
        survey_title=TemplateRenderer.safe_content(schema.json['title']),
        account_service_url=cookie_session.get('account_service_url'),
        account_service_log_out_url=cookie_session.get(
            'account_service_log_out_url'),
        content=context,
        cookie_message=cookie_message,
        allow_analytics=allow_analytics)
Exemple #39
0
def render_template(template, **context):
    theme = session.get('theme', current_app.config['DEFAULT_THEME'])
    return render_theme_template(theme, template, _fallback=False, **context)
def render(template, **context):
    from cert_viewer import app
    return render_theme_template(app.config['THEME'], template, **context)