コード例 #1
0
ファイル: __init__.py プロジェクト: rciorba/moin-2.0-mirror
def get_current_theme():
    # this might be called at a time when flaskg.user is not setup yet:
    u = getattr(flaskg, 'user', None)
    if u and u.theme_name is not None:
        theme_name = u.theme_name
    else:
        theme_name = app.cfg.theme_default
    try:
        return get_theme(theme_name)
    except KeyError:
        logging.warning("Theme {0!r} was not found; using default of {1!r} instead.".format(
            theme_name, app.cfg.theme_default))
        theme_name = app.cfg.theme_default
        return get_theme(theme_name)
コード例 #2
0
def get_current_theme():
    # this might be called at a time when flaskg.user is not setup yet:
    u = getattr(flaskg, 'user', None)
    if u and u.theme_name is not None:
        theme_name = u.theme_name
    else:
        theme_name = app.cfg.theme_default
    try:
        return get_theme(theme_name)
    except KeyError:
        logging.warning("Theme {0!r} was not found; using default of {1!r} instead.".format(
            theme_name, app.cfg.theme_default))
        theme_name = app.cfg.theme_default
        return get_theme(theme_name)
コード例 #3
0
ファイル: website.py プロジェクト: elvisds/eventframe
def favicon(website):
    theme = get_theme(website.theme)
    favicon = theme.options.get('favicon')
    if favicon:
        return send_file(os.path.join(theme.static_path, favicon))
    else:
        return baseframe_favicon()
コード例 #4
0
def favicon(website):
    theme = get_theme(website.theme)
    favicon = theme.options.get('favicon')
    if favicon:
        return send_file(os.path.join(theme.static_path, favicon))
    else:
        return baseframe_favicon()
コード例 #5
0
def node(website, folder, node):
    folderob = Folder.query.filter_by(name=folder, website=website).first()
    if folderob is None:
        # Are we handling a /node/custom_url case?
        folderob = Folder.query.filter_by(name=u'',
                                          website=website).first_or_404()
        nodeob = Node.query.filter_by(name=folder,
                                      folder=folderob).first_or_404()
        # The node exists. Let the path handler figure out what to do with it
        return path_handler(path=u'/' + nodeob.name + u'/' + node)
    else:
        nodeob = Node.query.filter_by(name=node,
                                      folder=folderob).first_or_404()

    # For the context processor to pick up theme for this request
    # and for the nodehelper to know the current folder
    g.folder = folderob
    if node_registry[nodeob.type].view_handler is not None:
        # This node type is capable of rendering itself
        return node_registry[nodeob.type].view_handler(eventapp,
                                                       folderob.website,
                                                       folderob, nodeob).GET()
    elif node_registry[nodeob.type].render:
        theme = get_theme(folderob.theme)
        return render_theme_template(theme,
                                     nodeob.template,
                                     website=folderob.website,
                                     folder=folderob,
                                     title=nodeob.title,
                                     node=nodeob,
                                     _fallback=False)
    else:
        abort(404)  # We don't know how to render anything else
コード例 #6
0
    def test_get_helpers(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            cool = app.theme_manager.themes['cool']
            plain = app.theme_manager.themes['plain']
            assert get_theme('cool') is cool
            assert get_theme('plain') is plain
            tl = get_themes_list()
            assert tl[0] is cool
            assert tl[1] is plain
            try:
                get_theme('notthis')
            except KeyError:
                pass
            else:
                raise AssertionError("Getting a nonexistent theme should "
                                     "raised KeyError")
コード例 #7
0
ファイル: views.py プロジェクト: nibrahim/eventframe
 def GET(self):
     form = ConfirmForm()
     theme = get_theme(self.folder.theme)
     return render_theme_template(theme,
                                  self.node.template,
                                  website=self.website,
                                  folder=self.folder,
                                  title=self.node.title,
                                  node=self.node,
                                  form=form,
                                  _fallback=False)
コード例 #8
0
ファイル: views.py プロジェクト: elvisds/eventframe
def feed(website):
    theme = get_theme(website.theme)
    posts = rootfeed(website)
    if posts:
        updated = max(posts[0].revisions.published.updated_at, posts[0].published_at).isoformat() + 'Z'
    else:
        updated = datetime.utcnow().isoformat() + 'Z'
    return Response(render_theme_template(theme, 'feed.xml',
            feedid=url_for('index', _external=True),
            website=website, title=website.title, posts=posts, updated=updated),
        content_type='application/atom+xml; charset=utf-8')
コード例 #9
0
    def test_get_helpers(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            cool = app.theme_manager.themes['cool']
            plain = app.theme_manager.themes['plain']
            assert get_theme('cool') is cool
            assert get_theme('plain') is plain
            tl = get_themes_list()
            assert tl[0] is cool
            assert tl[1] is plain
            try:
                get_theme('notthis')
            except KeyError:
                pass
            else:
                raise AssertionError("Getting a nonexistent theme should "
                                     "raised KeyError")
コード例 #10
0
ファイル: website.py プロジェクト: anandology/eventframe
def node(folder, node):
    # For the context processor to pick up theme for this request
    # and for the nodehelper to know the current folder
    g.folder = folder
    if node_registry[node.type].view_handler is not None:
        # This node type is capable of rendering itself
        return node_registry[node.type].view_handler(eventapp, folder.website, folder, node).GET()
    elif node_registry[node.type].render:
        theme = get_theme(folder.theme)
        return render_theme_template(theme, node.template,
            website=folder.website, folder=folder, title=node.title, node=node, _fallback=False)
    else:
        abort(404)  # We don't know how to render anything else
コード例 #11
0
ファイル: views.py プロジェクト: elvisds/eventframe
def folder_feed(folder):
    theme = get_theme(folder.theme)
    posts = folderfeed(folder)
    if posts:
        updated = posts[0].published_at.isoformat() + 'Z'
    else:
        updated = datetime.utcnow().isoformat() + 'Z'
    return Response(render_theme_template(
            theme, 'feed.xml',
            feedid=url_for('folder', folder=folder.name),
            website=folder.website,
            title=u"%s — %s" % (folder.title or folder.name, folder.website.title),
            posts=posts, updated=updated),
        content_type='application/atom+xml; charset=utf-8')
コード例 #12
0
def folder_feed(folder):
    theme = get_theme(folder.theme)
    posts = folderfeed(folder)
    if posts:
        updated = posts[0].published_at.isoformat() + 'Z'
    else:
        updated = datetime.utcnow().isoformat() + 'Z'
    return Response(render_theme_template(
        theme,
        'feed.xml',
        feedid=url_for('folder', folder=folder.name),
        website=folder.website,
        title=u"%s — %s" % (folder.title or folder.name, folder.website.title),
        posts=posts,
        updated=updated),
                    content_type='application/atom+xml; charset=utf-8')
コード例 #13
0
def feed(website):
    theme = get_theme(website.theme)
    posts = rootfeed(website)
    if posts:
        updated = max(posts[0].revisions.published.updated_at,
                      posts[0].published_at).isoformat() + 'Z'
    else:
        updated = datetime.utcnow().isoformat() + 'Z'
    return Response(render_theme_template(theme,
                                          'feed.xml',
                                          feedid=url_for('index',
                                                         _external=True),
                                          website=website,
                                          title=website.title,
                                          posts=posts,
                                          updated=updated),
                    content_type='application/atom+xml; charset=utf-8')
コード例 #14
0
ファイル: website.py プロジェクト: elvisds/eventframe
def node(website, folder, node):
    folderob = Folder.query.filter_by(name=folder, website=website).first()
    if folderob is None:
        # Are we handling a /node/custom_url case?
        folderob = Folder.query.filter_by(name=u'', website=website).first_or_404()
        nodeob = Node.query.filter_by(name=folder, folder=folderob).first_or_404()
        # The node exists. Let the path handler figure out what to do with it
        return path_handler(path=u'/' + nodeob.name + u'/' + node)
    else:
        nodeob = Node.query.filter_by(name=node, folder=folderob).first_or_404()

    # For the context processor to pick up theme for this request
    # and for the nodehelper to know the current folder
    g.folder = folderob
    if node_registry[nodeob.type].view_handler is not None:
        # This node type is capable of rendering itself
        return node_registry[nodeob.type].view_handler(eventapp, folderob.website, folderob, nodeob).GET()
    elif node_registry[nodeob.type].render:
        theme = get_theme(folderob.theme)
        return render_theme_template(theme, nodeob.template,
            website=folderob.website, folder=folderob, title=nodeob.title, node=nodeob, _fallback=False)
    else:
        abort(404)  # We don't know how to render anything else
コード例 #15
0
def error500(website, e):
    theme = get_theme(website.theme)
    return render_theme_template(theme, '500.html'), 500
コード例 #16
0
ファイル: views.py プロジェクト: rudimk/eventframe
 def GET(self):
     form = ConfirmForm()
     theme = get_theme(self.folder.theme)
     return render_theme_template(theme, self.node.template,
         website=self.website, folder=self.folder, title=self.node.title, node=self.node,
         form=form, _fallback=False)
コード例 #17
0
def get_current_theme():
    return get_theme(current_app.config.get('THEME', 'default'))
コード例 #18
0
ファイル: test-themes.py プロジェクト: jace/flask-themes
        setup_themes(app, app_identifier='testing')

        assert hasattr(app, 'theme_manager')
        assert '_themes' in app.blueprints
        assert 'theme' in app.jinja_env.globals
        assert 'theme_static' in app.jinja_env.globals

    def test_get_helpers(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            cool = app.theme_manager.themes['cool']
            plain = app.theme_manager.themes['plain']
            assert get_theme('cool') is cool
            assert get_theme('plain') is plain
            tl = get_themes_list()
            assert tl[0] is cool
            assert tl[1] is plain
            try:
                get_theme('notthis')
            except KeyError:
                pass
            else:
                raise AssertionError("Getting a nonexistent theme should "
                                     "raised KeyError")


class TestStatic(object):
    def test_static_file_url(self):
コード例 #19
0
ファイル: helpers.py プロジェクト: hugleecool/wtxlog
def get_current_theme():
    return get_theme(current_app.config.get('THEME', 'default'))
コード例 #20
0
def error404(website, e):
    theme = get_theme(website.theme)
    return render_theme_template(theme, '404.html'), 404