예제 #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
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())
예제 #3
0
파일: account.py 프로젝트: rockyburt/Rezine
def login(request):
    """Show a login page."""
    if request.user.is_somebody:
        return redirect_to('account/index')
    form = LoginForm()

    if request.method == 'POST' and form.validate(request.form):
        request.login(form['user'], form['permanent'])
        if request.user.is_admin:
            return form.redirect('admin/index')
        return form.redirect('account/index')

    return render_response('account/login.html', form=form.as_widget())
예제 #4
0
파일: blog.py 프로젝트: rockyburt/Rezine
def dispatch_content_type(req):
    """Show the post for a specific content type."""
    slug = req.path[1:]

    # feed for the post
    if slug.endswith('/feed.atom'):
        slug = slug[:-10]
        want_feed = True
    else:
        want_feed = False

    post = Post.query.filter_by(slug=slug).first()

    if post is None:
        # if the post does not exist, check if a post with a trailing slash
        # exists.  If it does, redirect to that post.  This is allows users
        # to emulate folders and to get relative links working.
        if not slug.endswith('/'):
            real_post = Post.query.filter_by(slug=slug + '/').first()
            if real_post is None:
                raise NotFound()
            # if we want the feed, we don't want a redirect
            elif want_feed:
                post = real_post
            else:
                return redirect_to(real_post)
        else:
            raise NotFound()

    # make sure the current user can access that page.
    if not post.can_read():
        raise Forbidden()

    # feed requested?  jump to the feed page
    if want_feed:
        return atom_feed(req, post=post)

    # create the comment form
    form = NewCommentForm(post, req.user)
    if post.comments_enabled or post.comments:
        add_link('alternate', post.comment_feed_url, 'application/atom+xml',
                 _(u'Comments Feed'))

    # now dispatch to the correct view
    handler = req.app.content_type_handlers.get(post.content_type)
    if handler is None:
        log.warn('No handler for the content type %r found.' %
                 post.content_type)
        raise NotFound()

    return handler(req, post, form)
예제 #5
0
파일: account.py 프로젝트: rockyburt/Rezine
def profile(request):
    form = EditProfileForm(request.user)
    if request.method == 'POST':
        if request.form.get('cancel'):
            return form.redirect('account/index')
        elif request.form.get('delete'):
            return redirect_to('account/delete')
        elif form.validate(request.form):
            form.save_changes()
            db.commit()
            flash(_(u'Your profile was updated successfully.'), 'info')
            return form.redirect('account/index')
    return render_account_response('account/edit_profile.html', 'profile',
                                   form=form.as_widget())
예제 #6
0
파일: blog.py 프로젝트: rockyburt/Rezine
def dispatch_content_type(req):
    """Show the post for a specific content type."""
    slug = req.path[1:]

    # feed for the post
    if slug.endswith('/feed.atom'):
        slug = slug[:-10]
        want_feed = True
    else:
        want_feed = False

    post = Post.query.filter_by(slug=slug).first()

    if post is None:
        # if the post does not exist, check if a post with a trailing slash
        # exists.  If it does, redirect to that post.  This is allows users
        # to emulate folders and to get relative links working.
        if not slug.endswith('/'):
            real_post = Post.query.filter_by(slug=slug + '/').first()
            if real_post is None:
                raise NotFound()
            # if we want the feed, we don't want a redirect
            elif want_feed:
                post = real_post
            else:
                return redirect_to(real_post)
        else:
            raise NotFound()

    # make sure the current user can access that page.
    if not post.can_read():
        raise Forbidden()

    # feed requested?  jump to the feed page
    if want_feed:
        return atom_feed(req, post=post)

    # create the comment form
    form = NewCommentForm(post, req.user)
    if post.comments_enabled or post.comments:
        add_link('alternate', post.comment_feed_url, 'application/atom+xml',
                 _(u'Comments Feed'))

    # now dispatch to the correct view
    handler = req.app.content_type_handlers.get(post.content_type)
    if handler is None:
        log.warn('No handler for the content type %r found.' % post.content_type)
        raise NotFound()

    return handler(req, post, form)
예제 #7
0
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
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
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())
예제 #10
0
파일: feed.py 프로젝트: rockyburt/Rezine
    def configure(self, request):
        form = FeedImportForm()

        if request.method == 'POST' and form.validate(request.form):
            feed = request.files.get('feed')
            if form.data['download_url']:
                try:
                    feed = open_url(form.data['download_url']).stream
                except Exception, e:
                    log.exception(_('Error downloading feed'))
                    flash(_(u'Error downloading from URL: %s') % e, 'error')
            if not feed:
                return redirect_to('import/feed')

            try:
                blog = parse_feed(feed)
            except Exception, e:
                log.exception(_(u'Error parsing uploaded file'))
                flash(_(u'Error parsing feed: %s') % e, 'error')
예제 #11
0
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())
예제 #12
0
    def configure(self, request):
        form = WordPressImportForm()

        if request.method == "POST" and form.validate(request.form):
            dump = request.files.get("dump")
            if form.data["download_url"]:
                try:
                    dump = open_url(form.data["download_url"]).stream
                except Exception, e:
                    log.exception(_("Error downloading feed"))
                    flash(_(u"Error downloading from URL: %s") % e, "error")
            if not dump:
                return redirect_to("import/wordpress")

            try:
                blog = parse_feed(dump)
            except Exception, e:
                raise
                log.exception(_(u"Error parsing uploaded file"))
                flash(_(u"Error parsing uploaded file: %s") % e, "error")
예제 #13
0
    def configure(self, request):
        form = WordPressImportForm()

        if request.method == 'POST' and form.validate(request.form):
            dump = request.files.get('dump')
            if form.data['download_url']:
                try:
                    dump = open_url(form.data['download_url']).stream
                except Exception, e:
                    log.exception(_('Error downloading feed'))
                    flash(_(u'Error downloading from URL: %s') % e, 'error')
            if not dump:
                return redirect_to('import/wordpress')

            try:
                blog = parse_feed(dump)
            except Exception, e:
                raise
                log.exception(_(u'Error parsing uploaded file'))
                flash(_(u'Error parsing uploaded file: %s') % e, 'error')
예제 #14
0
파일: account.py 프로젝트: rockyburt/Rezine
def help(req, page=''):
    """Show help page."""
    from rezine.docs import load_page, get_resource

    rv = load_page(req.app, page)
    if rv is None:
        resource = get_resource(req.app, page)
        if resource is None:
            return render_account_response('account/help.html', 'system.help',
                                           not_found=True)
        return resource

    parts, is_index = rv
    ends_with_slash = not page or page.endswith('/')
    if is_index and not ends_with_slash:
        return redirect_to('account/help', page=page + '/')
    elif not is_index and ends_with_slash:
        raise NotFound()

    return render_account_response('account/help.html', 'system.help', **parts)
예제 #15
0
    name = "wordpress"
    title = "WordPress"
    description = lazy_gettext(u'Handles import of WordPress "extended RSS" ' u" feeds.")

    def configure(self, request):
        form = WordPressImportForm()

        if request.method == "POST" and form.validate(request.form):
            dump = request.files.get("dump")
            if form.data["download_url"]:
                try:
                    dump = open_url(form.data["download_url"]).stream
                except Exception, e:
                    log.exception(_("Error downloading feed"))
                    flash(_(u"Error downloading from URL: %s") % e, "error")
            if not dump:
                return redirect_to("import/wordpress")

            try:
                blog = parse_feed(dump)
            except Exception, e:
                raise
                log.exception(_(u"Error parsing uploaded file"))
                flash(_(u"Error parsing uploaded file: %s") % e, "error")
            else:
                self.enqueue_dump(blog)
                flash(_(u"Added imported items to queue."))
                return redirect_to("admin/import")

        return self.render_admin_page("admin/import_wordpress.html", form=form.as_widget())
예제 #16
0
    description = lazy_gettext(u'Handles import of WordPress "extended RSS" '
                               u' feeds.')

    def configure(self, request):
        form = WordPressImportForm()

        if request.method == 'POST' and form.validate(request.form):
            dump = request.files.get('dump')
            if form.data['download_url']:
                try:
                    dump = open_url(form.data['download_url']).stream
                except Exception, e:
                    log.exception(_('Error downloading feed'))
                    flash(_(u'Error downloading from URL: %s') % e, 'error')
            if not dump:
                return redirect_to('import/wordpress')

            try:
                blog = parse_feed(dump)
            except Exception, e:
                raise
                log.exception(_(u'Error parsing uploaded file'))
                flash(_(u'Error parsing uploaded file: %s') % e, 'error')
            else:
                self.enqueue_dump(blog)
                flash(_(u'Added imported items to queue.'))
                return redirect_to('admin/import')

        return self.render_admin_page('admin/import_wordpress.html',
                                      form=form.as_widget())
예제 #17
0
파일: feed.py 프로젝트: rockyburt/Rezine
                    feed = open_url(form.data['download_url']).stream
                except Exception, e:
                    log.exception(_('Error downloading feed'))
                    flash(_(u'Error downloading from URL: %s') % e, 'error')
            if not feed:
                return redirect_to('import/feed')

            try:
                blog = parse_feed(feed)
            except Exception, e:
                log.exception(_(u'Error parsing uploaded file'))
                flash(_(u'Error parsing feed: %s') % e, 'error')
            else:
                self.enqueue_dump(blog)
                flash(_(u'Added imported items to queue.'))
                return redirect_to('admin/import')

        return self.render_admin_page('admin/import_feed.html',
                                      form=form.as_widget())


class Extension(object):
    """Extensions are instanciated for each parsing process."""
    feed_types = frozenset()

    def __init__(self, app, parser, root):
        self.app = app
        self.parser = parser
        self.root = root

    def handle_root(self, blog):