コード例 #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
ファイル: __init__.py プロジェクト: jace/zine-plugins
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())
コード例 #3
0
ファイル: __init__.py プロジェクト: adityaathalye/zine
def show_akismet_stats(req):
    """Show the akismet control panel."""
    api_key = req.app.cfg['akismet_spam_filter/apikey']
    blog_url = req.app.cfg['zine/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
ファイル: __init__.py プロジェクト: peicheng/zine
def show_akismet_stats(req):
    """Show the akismet control panel."""
    api_key = req.app.cfg['akismet_spam_filter/apikey']
    blog_url = req.app.cfg['zine/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
ファイル: __init__.py プロジェクト: adityaathalye/zine
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())
コード例 #6
0
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())
コード例 #7
0
ファイル: __init__.py プロジェクト: peicheng/zine
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())
コード例 #8
0
ファイル: __init__.py プロジェクト: adityaathalye/zine
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())
コード例 #9
0
ファイル: __init__.py プロジェクト: adityaathalye/zine
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())
コード例 #10
0
ファイル: __init__.py プロジェクト: peicheng/zine
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())
コード例 #11
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())
コード例 #12
0
ファイル: __init__.py プロジェクト: arneb/zine-themes
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())
コード例 #13
0
ファイル: __init__.py プロジェクト: tshirtman/zine_ad_sense
    height = req.args.get('height')
    if client_code and banner_slot and width and height:
        try:
            req.app.cfg.change_single('ad_sense/client_code', client_code)
            req.app.cfg.change_single('ad_sense/banner_slot', banner_slot)
            req.app.cfg.change_single('ad_sense/width', width)
            req.app.cfg.change_single('ad_sense/height', height)
            flash(_('Config updated!'), 'info')
        except ConfigurationTransactionError, e:
            flash(_('The code could not be changed.'), 'error')
        return redirect(url_for('ad_sense/config'))

    return render_admin_response('admin/ad_sense.html',
            'config.ad_sense',
            client_code=req.app.cfg['ad_sense/client_code'],
            banner_slot=req.app.cfg['ad_sense/banner_slot'],
            width=req.app.cfg['ad_sense/width'],
            height=req.app.cfg['ad_sense/height']
            )


def add_adsense_banner(post):
    conf = get_application().cfg
    client_code = conf['ad_sense/client_code']
    banner_slot =  conf['ad_sense/banner_slot']
    banner_width = conf['ad_sense/width']
    banner_height = conf['ad_sense/height']
    if choice((True, False)):
        return '''
            <span class="ad">
            <script type="text/javascript"><!--
コード例 #14
0
ファイル: __init__.py プロジェクト: peicheng/zine
def show_eric_options(req):
    """This renders the eric admin panel. Allow switching the skin and show
    the available skins.
    """
    new_skin = req.args.get('select')
    if new_skin in SKINS:
        try:
            req.app.cfg.change_single('eric_the_fish/skin', new_skin)
        except ConfigurationTransactionError, e:
            flash(_('The skin could not be changed.'), 'error')
        return redirect(url_for('eric_the_fish/config'))

    return render_admin_response('admin/eric_the_fish.html',
                                 'options.eric_the_fish',
        skins=[{
            'name':     skin,
            'active':   skin == req.app.cfg['eric_the_fish/skin']
        } for skin in SKINS]
    )


def get_fortune(req):
    """The servicepoint function. Just return one fortune from the database."""
    fortune_ids = db.session.query(Fortune.id).all()
    return {'fortune': db.session.query(Fortune).get(choice(fortune_ids)).text}


def setup(app, plugin):
    """This function is called by Zine in the application initialisation
    phase. Here we connect to the events and register our template paths,
    url rules, views etc.
コード例 #15
0
ファイル: __init__.py プロジェクト: adityaathalye/zine
 def render_admin_page(self, template_name, **context):
     """Shortcut for rendering an page for the admin."""
     from zine.views.admin import render_admin_response
     return render_admin_response(template_name, 'system.import',
                                  **context)
コード例 #16
0
ファイル: __init__.py プロジェクト: jace/zine-main
 def render_admin_page(self, template_name, **context):
     """Shortcut for rendering an page for the admin."""
     from zine.views.admin import render_admin_response
     return render_admin_response(template_name, 'system.import',
                                  **context)
コード例 #17
0
ファイル: __init__.py プロジェクト: tshirtman/zine_ad_sense
    height = req.args.get('height')
    if client_code and banner_slot and width and height:
        try:
            req.app.cfg.change_single('ad_sense/client_code', client_code)
            req.app.cfg.change_single('ad_sense/banner_slot', banner_slot)
            req.app.cfg.change_single('ad_sense/width', width)
            req.app.cfg.change_single('ad_sense/height', height)
            flash(_('Config updated!'), 'info')
        except ConfigurationTransactionError, e:
            flash(_('The code could not be changed.'), 'error')
        return redirect(url_for('ad_sense/config'))

    return render_admin_response(
        'admin/ad_sense.html',
        'config.ad_sense',
        client_code=req.app.cfg['ad_sense/client_code'],
        banner_slot=req.app.cfg['ad_sense/banner_slot'],
        width=req.app.cfg['ad_sense/width'],
        height=req.app.cfg['ad_sense/height'])


def add_adsense_banner(post):
    conf = get_application().cfg
    client_code = conf['ad_sense/client_code']
    banner_slot = conf['ad_sense/banner_slot']
    banner_width = conf['ad_sense/width']
    banner_height = conf['ad_sense/height']
    if choice((True, False)):
        return '''
            <span class="ad">
            <script type="text/javascript"><!--
コード例 #18
0
    if thumb_max_width:
        try:
            req.app.cfg.change_single('img_upload/thumb_max_width', thumb_max_width)
        except ConfigurationTransactionError, e:
            flash(_('The thumb max width could not be changed.'), 'error')

    if thumb_max_height:
        try:
            req.app.cfg.change_single('img_upload/thumb_max_height', thumb_max_height)
        except ConfigurationTransactionError, e:
            flash(_('The thumb max height could not be changed.'), 'error')

    return render_admin_response('admin/img_uploader.html',
            images_directory=req.app.cfg['img_upload/images_directory'],
            base_url=req.app.cfg['img_upload/base_url'],
            thumb_max_width=req.app.cfg['img_upload/thumb_max_width'],
            thumb_max_height=req.app.cfg['img_upload/thumb_max_height'])

@require_privilege(BLOG_ADMIN)
def upload_image(req):
    """
    """
    image = req.files['userfile']
    if "image" in image.content_type:
        name = image.filename
        name, ext = splitext(name)
        while name+ext in os.listdir(req.app.cfg['img_upload/images_directory']):
            name += choice(letters)

        image.save(os.path.join(req.app.cfg['img_upload/images_directory'], name+ext))