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_restructuredtext_config(req): """Show reStructuredText Parser configuration options.""" form = ConfigurationForm(initial=dict( initial_header_level=req.app.cfg[CFG_HEADER_LEVEL])) if req.method == 'POST' and form.validate(req.form): if form.has_changed: req.app.cfg.change_single(CFG_HEADER_LEVEL, form['initial_header_level']) flash(_('reStructuredText Parser settings saved.'), 'ok') return render_admin_response('admin/restructuredtext_options.html', 'options.restructuredtext', form=form.as_widget())
def show_markdown_config(req): """Show Markdown Parser configuration options.""" form = ConfigurationForm( initial=dict(extensions=req.app.cfg[CFG_EXTENSIONS], makeintro=req.app.cfg[CFG_MAKEINTRO])) if req.method == 'POST' and form.validate(req.form): if form.has_changed: cfg = req.app.cfg.edit() cfg[CFG_EXTENSIONS] = form['extensions'] cfg[CFG_MAKEINTRO] = form['makeintro'] cfg.commit() flash(_('Markdown Parser settings saved.'), 'ok') return render_admin_response('admin/markdown_options.html', 'options.markdown', 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_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_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())