Пример #1
0
def show_config(req):
    """Request handler that provides an admin page with the configuration
    for the pygments plugin. So far this only allows changing the style.
    """
    active_style = get_current_style()
    styles = sorted([(x, x.title()) for x in STYLES])
    form = ConfigurationForm(initial=dict(style=active_style))
    form.fields['style'].choices = styles

    if req.method == 'POST' and form.validate(req.form):
        active_style = form['style']
        if 'apply' in req.form:
            req.app.cfg.change_single('pygments_support/style',
                                      active_style)
            flash(_('Pygments theme changed successfully.'), 'configure')
            return redirect_to('pygments_support/config')

    preview_formatter = get_formatter(active_style, preview=True)
    add_header_snippet('<style type="text/css">\n%s\n</style>' %
                       escape(preview_formatter.get_style_defs()))
    example = highlight(EXAMPLE, get_lexer_by_name('html+jinja'),
                        preview_formatter)

    return render_admin_response('admin/pygments_support.html',
                                 'options.pygments_support',
                                 example=example, form=form.as_widget())
Пример #2
0
def show_config(req):
    """Request handler that provides an admin page with the configuration
    for the pygments plugin. So far this only allows changing the style.
    """
    active_style = get_current_style()
    styles = sorted([(x, x.title()) for x in STYLES])
    form = ConfigurationForm(initial=dict(style=active_style))
    form.fields['style'].choices = styles

    if req.method == 'POST' and form.validate(req.form):
        active_style = form['style']
        if 'apply' in req.form:
            req.app.cfg.change_single('pygments_support/style', active_style)
            flash(_('Pygments theme changed successfully.'), 'configure')
            return redirect_to('pygments_support/config')

    preview_formatter = get_formatter(active_style, preview=True)
    add_header_snippet('<style type="text/css">\n%s\n</style>' %
                       escape(preview_formatter.get_style_defs()))
    example = highlight(EXAMPLE, get_lexer_by_name('html+jinja'),
                        preview_formatter)

    return render_admin_response('admin/pygments_support.html',
                                 'options.pygments_support',
                                 example=example,
                                 form=form.as_widget())
Пример #3
0
def show_akismet_stats(req):
    """Show the akismet control panel."""
    api_key = req.app.cfg['akismet_spam_filter/apikey']
    blog_url = req.app.cfg['rezine/blog_url']

    if req.app.cfg['maintenance_mode']:
        js_file = 'jquery.uicore.plus.tabs.js'
    else:
        js_file = 'jquery.uicore.plus.tabs.packed.js'
    add_script(url_for('akismet/shared', filename=js_file))

    return render_admin_response('admin/akismet_spam_filter_stats.html',
                                 'comments.akismet_spam_filter',
                                 api_key=api_key, blog_url=blog_url)
Пример #4
0
def show_akismet_stats(req):
    """Show the akismet control panel."""
    api_key = req.app.cfg['akismet_spam_filter/apikey']
    blog_url = req.app.cfg['rezine/blog_url']

    if req.app.cfg['maintenance_mode']:
        js_file = 'jquery.uicore.plus.tabs.js'
    else:
        js_file = 'jquery.uicore.plus.tabs.packed.js'
    add_script(url_for('akismet/shared', filename=js_file))

    return render_admin_response('admin/akismet_spam_filter_stats.html',
                                 'comments.akismet_spam_filter',
                                 api_key=api_key,
                                 blog_url=blog_url)
Пример #5
0
def show_akismet_config(req):
    """Show the akismet control panel."""
    form = ConfigurationForm(initial=dict(
        api_key=req.app.cfg['akismet_spam_filter/apikey']))

    if req.method == 'POST' and form.validate(req.form):
        if form.has_changed:
            req.app.cfg.change_single('akismet_spam_filter/apikey',
                                      form['api_key'])
            if form['api_key']:
                flash(_('Akismet has been successfully enabled.'), 'ok')
            else:
                flash(_('Akismet disabled.'), 'ok')
        return redirect_to('akismet_spam_filter/config')
    return render_admin_response('admin/akismet_spam_filter.html',
                                 'options.akismet_spam_filter',
                                 form=form.as_widget())
Пример #6
0
def show_akismet_config(req):
    """Show the akismet control panel."""
    form = ConfigurationForm(initial=dict(
        api_key=req.app.cfg['akismet_spam_filter/apikey']
    ))

    if req.method == 'POST' and form.validate(req.form):
        if form.has_changed:
            req.app.cfg.change_single('akismet_spam_filter/apikey',
                                      form['api_key'])
            if form['api_key']:
                flash(_('Akismet has been successfully enabled.'), 'ok')
            else:
                flash(_('Akismet disabled.'), 'ok')
        return redirect_to('akismet_spam_filter/config')
    return render_admin_response('admin/akismet_spam_filter.html',
                                 'options.akismet_spam_filter',
                                 form=form.as_widget())
Пример #7
0
def show_analytics_config(req):
    """Show the analytics control panel."""
    form = ConfigurationForm(initial=dict(
        account=req.app.cfg['analytics/account']
    ))

    if req.method == 'POST' and form.validate(req.form):
        if form.has_changed:
            req.app.cfg.change_single('analytics/account',
                                      form['account'])
            if form['account']:
                flash(_('Google Analytics has been '
                        'successfully enabled.'), 'ok')
            else:
                flash(_('Google Analytics disabled.'), 'ok')
        return redirect_to(CONFIG_ENDPOINT)
    return render_admin_response('admin/google-analytics.html',
                                 'options.analytics',
                                 form=form.as_widget())
Пример #8
0
def show_config(req):
    """The configuration form."""
    form = ConfigurationForm(initial=dict((k, req.app.cfg['typography/' + k])
                                          for k in ConfigurationForm.fields))

    if req.method == 'POST' and form.validate(req.form):
        if form.has_changed:
            t = req.app.cfg.edit()
            for key, value in form.data.iteritems():
                t['typography/' + key] = value
            try:
                t.commit()
            except IOError:
                flash(_('Typography settings could not be changed.'), 'error')
            else:
                flash(_('Typography settings changed.'), 'configure')
        return redirect_to('typography/config')

    return render_admin_response('admin/typography.html',
                                 'options.typography', form=form.as_widget())
Пример #9
0
def configure(request):
    """This callback is called from the admin panel if the theme configuration
    page is opened.  Because only the active theme can be configured it's
    perfectly okay to ship the template for the configuration page as part of
    the theme template folder.  No need to register a separate template folder
    just for the admin panel template.
    """
    cfg = request.app.cfg
    form = ConfigurationForm(initial=dict(
        variation=cfg['vessel_theme/variation']))

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/theme')
        elif form.validate(request.form):
            flash(_('Color variation changed successfully.'), 'configure')
            cfg.change_single('vessel_theme/variation', form['variation'])
            return form.redirect('admin/theme')

    return render_admin_response('admin/configure_vessel_theme.html',
                                 'options.theme',
                                 form=form.as_widget())
Пример #10
0
def configure(request):
    """This callback is called from the admin panel if the theme configuration
    page is opened.  Because only the active theme can be configured it's
    perfectly okay to ship the template for the configuration page as part of
    the theme template folder.  No need to register a separate template folder
    just for the admin panel template.
    """
    cfg = request.app.cfg
    form = ConfigurationForm(initial=dict(
        variation=cfg['vessel_theme/variation']
    ))

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/theme')
        elif form.validate(request.form):
            flash(_('Color variation changed successfully.'), 'configure')
            cfg.change_single('vessel_theme/variation', form['variation'])
            return form.redirect('admin/theme')

    return render_admin_response('admin/configure_vessel_theme.html',
                                 'options.theme', form=form.as_widget())
Пример #11
0
 def render_admin_page(self, template_name, **context):
     """Shortcut for rendering an page for the admin."""
     from rezine.views.admin import render_admin_response
     return render_admin_response(template_name, 'system.import', **context)
Пример #12
0
 def render_admin_page(self, template_name, **context):
     """Shortcut for rendering an page for the admin."""
     from rezine.views.admin import render_admin_response
     return render_admin_response(template_name, 'system.import',
                                  **context)