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())
def do_submit_ham(comment): """Contribute to akismet; submit ham.""" # comment is not spam, don't submit it to akismet if not comment.blocked: return apikey, data = build_akismet_data(get_request(), comment) if not (data or apikey): return send_request(apikey, True, data, 'submit-ham') flash(_("Comment by %s reported to Akismet") % comment.author)
def do_submit_spam(comment): """Contribute to akismet; submit spam.""" # comment is spam, don't submit it to akismet again if comment.blocked: return apikey, data = build_akismet_data(get_request(), comment) if not (data or apikey): return send_request(apikey, True, data, 'submit-spam') # Blocking flags will be issued by the form calling this flash(_("Comment by %s reported to Akismet") % comment.author)
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())
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())
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())