class ConfigurationForm(forms.Form): """Very simple form for the variation selection.""" variation = forms.ChoiceField(_('Color variation')) def __init__(self, initial=None): forms.Form.__init__(self, initial) choices = sorted(variations.items(), key=lambda x: x[1].lower()) self.fields['variation'].choices = choices
class PingbackError(UserException): """Raised if the remote server caused an exception while pingbacking. This is not raised if the pingback function is unable to locate a remote server. """ _ = lambda x: x default_messages = { 16: _(u'source URL does not exist'), 17: _(u'The source URL does not contain a link to the target URL'), 32: _(u'The specified target URL does not exist'), 33: _(u'The specified target URL cannot be used as a target'), 48: _(u'The pingback has already been registered'), 49: _(u'Access Denied') } del _ def __init__(self, fault_code, internal_message=None): UserException.__init__(self) self.fault_code = fault_code self._internal_message = internal_message def as_fault(self): """Return the pingback errors XMLRPC fault.""" return Fault(self.fault_code, self.internal_message or 'unknown server error') @property def ignore_silently(self): """If the error can be ignored silently.""" return self.fault_code in (17, 33, 48, 49) @property def means_missing(self): """If the error means that the resource is missing or not accepting pingbacks. """ return self.fault_code in (32, 33) @property def internal_message(self): if self._internal_message is not None: return self._internal_message return self.default_messages.get(self.fault_code) or 'server error' @property def message(self): msg = self.default_messages.get(self.fault_code) if msg is not None: return _(msg) return _(u'An unknown server error (%s) occurred') % self.fault_code
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())
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['kubrick_theme/variation'] )) if request.method == 'POST': if 'cancel' in request.form: return form.redirect('admin/theme') elif form.validate(request.form): flash(_('Variation changed successfully.'), 'configure') cfg.change_single('kubrick_theme/variation', form['variation']) return form.redirect('admin/theme') return render_admin_response('admin/configure_kubrick_theme.html', 'options.theme', form=form.as_widget())
def setup(app, plugin): app.add_shared_exports('example_theme', SHARED_FILES) kubrick_theme.add_variation(u'example_theme::example.css', _('Example'))
""" example_captcha_screen ~~~~~~~~~~~~~~~~~~~~~~ Sample CAPTCHA on comments form. """ from zine.api import _ from zine.application import get_request from zine.models import COMMENT_BLOCKED_SPAM from os.path import join, dirname TEMPLATES = join(dirname(__file__), 'templates') FAILED_TEST_MSG = _("Failed the captcha -- it's a robot!") SKIPPED_TEST_MSG = _('Neglected to attempt the captcha, maybe a robot') choices = ["dog", "cat", "chicken"] import random def set_session_captcha(post): req = get_request() req.session['captcha'] = random.choice(choices) req.session['captcha_mangled'] = req.session['captcha'].replace("o", "0").replace("a", "A").replace("i", "1").replace("e", "3") def validate_session_captcha(req, comment): req = get_request() if 'captcha' not in req.session: return captcha = req.session.pop("captcha")
def message(self): msg = self.default_messages.get(self.fault_code) if msg is not None: return _(msg) return _(u'An unknown server error (%s) occurred') % self.fault_code
:license: BSD, see LICENSE for more details. """ from os.path import join, dirname from zine.api import url_for, _ from zine.views.admin import render_admin_response from zine.utils.admin import flash from zine.utils import forms TEMPLATE_FILES = join(dirname(__file__), 'templates') SHARED_FILES = join(dirname(__file__), 'shared') blue_variation = u'vessel_theme::blue.css' variations = { blue_variation: _('Blue'), u'vessel_theme::gray.css': _('Gray'), u'vessel_theme::green.css': _('Green') } class ConfigurationForm(forms.Form): """Very simple form for the variation selection.""" variation = forms.ChoiceField(_('Color variation')) def __init__(self, initial=None): forms.Form.__init__(self, initial) choices = sorted(variations.items(), key=lambda x: x[1].lower()) self.fields['variation'].choices = choices
def setup(app, plugin): app.add_shared_exports('dark_vessel_colorscheme', SHARED_FILES) vessel_theme.add_variation(u'dark_vessel_colorscheme::dark.css', _('Dark'))
""" from os.path import join, dirname from zine.api import url_for, _ from zine.views.admin import render_admin_response from zine.utils.admin import flash from zine.utils import forms from widgets import ListPages, MetaInfo TEMPLATE_FILES = join(dirname(__file__), 'templates') SHARED_FILES = join(dirname(__file__), 'shared') blue_variation = u'kubrick_theme::blue.css' variations = { blue_variation: _('Blue'), } class ConfigurationForm(forms.Form): """Very simple form for the variation selection.""" variation = forms.ChoiceField(_('Variation')) def __init__(self, initial=None): forms.Form.__init__(self, initial) choices = sorted(variations.items(), key=lambda x: x[1].lower()) self.fields['variation'].choices = choices 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
:license: BSD, see LICENSE for more details. """ from os.path import join, dirname from zine.api import _ from zine.views.admin import render_admin_response from zine.utils.admin import flash from zine.utils import forms TEMPLATE_FILES = join(dirname(__file__), 'templates') SHARED_FILES = join(dirname(__file__), 'shared') blue_variation = u'vessel_theme::blue.css' variations = { blue_variation: _('Blue'), u'vessel_theme::gray.css': _('Gray'), u'vessel_theme::green.css': _('Green') } class ConfigurationForm(forms.Form): """Very simple form for the variation selection.""" variation = forms.ChoiceField(_('Color variation')) def __init__(self, initial=None): forms.Form.__init__(self, initial) choices = sorted(variations.items(), key=lambda x: x[1].lower()) self.fields['variation'].choices = choices