Пример #1
0
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
Пример #2
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())
Пример #3
0
def is_valid_account_id(message=None, memorize=False):
    if message is None:
        message = _('The key is invalid.')

    def validate(form, account):
        # TODO: cache the account id by querying google analytics itself
        # to make sure account is valid

        blog_url = get_application().cfg['blog_url']
        cachekey = (account, blog_url)
        if cachekey in _verified_accounts:
            return

        if not account:
            raise ValidationError(message)
        if memorize:
            _verified_accounts.add(cachekey)
    return validate
Пример #4
0
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
Пример #5
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())
Пример #6
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())
Пример #7
0
 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
Пример #8
0
    :copyright: (c) 2010 by the Rezine Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""
from os.path import join, dirname
from rezine.api import _
from rezine.views.admin import render_admin_response
from rezine.utils.admin import flash
from rezine.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

Пример #9
0
 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
Пример #10
0
    :license: BSD, see LICENSE for more details.
"""
from os.path import join, dirname
from rezine.api import _
from rezine.views.admin import render_admin_response
from rezine.utils.admin import flash
from rezine.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