Beispiel #1
0
from webob import Response
from webob.exc import HTTPFound

from models import Root, Page

def render_properties_to_jinja(template, properties):
    output = []
    output.append(u'{%% extends "%s" %%}' % template)
    for key, content in properties.items():
        output.append('{%% block %s %%}%s{%% endblock %%}' % (key.replace('.', '__'), content))
    return '\n'.join(output)

env = Environment(loader=PackageLoader('jingle', 'templates'))


static_view = static('static')

@bfg_view(for_=Root)
def create_page_get(context, request):
    template = env.get_template('add_page.html')
    return Response(template.render())

@bfg_view(for_=Root, request_type='POST')
def create_page_post(context, request):
    data = request.POST
    page = Page(data['title'])
    page.layout_template = u'master.html'
    for behaviour in data.getall('behaviour'):
        page.update(behaviour, data, behaviour + '.')
    context[data['uid']] = page
    location = model_url(page, request)
Beispiel #2
0
"""Publish static resources under /static/"""

import os
import re

from webob.exc import HTTPFound

from repoze.bfg.url import model_url
from repoze.bfg.view import static

from karl.views.utils import get_user_home

here = os.path.abspath(os.path.dirname(__file__))

# five year expires time
static_view = static('static', cache_max_age=157680000)

version_match = re.compile(r'^r-?\d+$').match
# version number is "r" plus an integer (possibly negative)

def versioning_static_view(context, request):
    # if the first element in the subpath is the version number, strip
    # it out of the subpath (see views/api.py static_url)
    subpath = request.subpath
    if subpath and version_match(subpath[0]):
        request.subpath = subpath[1:]
    return static_view(context, request)

def site_view(context, request):
    home, extra_path = get_user_home(context, request)
    return HTTPFound(location=model_url(home, request, *extra_path))
Beispiel #3
0
from repoze.bfg.interfaces import ISettings

from zope.component import queryUtility
from zope.component import getUtility

from webob import Response
from webob.exc import HTTPFound

from interfaces import IHTMLRenderer
from interfaces import IFRSFolder, IFRSDocument

#mimetypes.add_type('text/html', '.py')
#mimetypes.add_type('text/html', '.zcml')
#mimetypes.add_type('application/pdf', '.pdf')

resources_view = static('resources')
rules_view = static('deliverance/rules')
static_view = static('templates/static')

def folder_view(context, request):
    if not request.url.endswith('/'):
        response = HTTPFound(location=request.url + '/')
        return response

    defaults = ('index.html', 'index.rst')
    for name in defaults:
        try:
            index = context[name]
        except KeyError:
            continue
        return document_view(index, request)
Beispiel #4
0
from webob.exc import HTTPFound

from repoze.bfg.chameleon_zpt import render_template_to_response
from repoze.bfg.url import model_url
from repoze.bfg.view import static

from opencore.views.utils import get_user_home
from opencore.views.api import TemplateAPI
import logging

log = logging.getLogger(__name__)

here = os.path.abspath(os.path.dirname(__file__))

# five year expires time
static_view = static("static", cache_max_age=157680000)

version_match = re.compile(r"^r-?\d+$").match
# version number is "r" plus an integer (possibly negative)


def versioning_static_view(context, request):
    # if the first element in the subpath is the version number, strip
    # it out of the subpath (see views/api.py static_url)
    subpath = request.subpath
    if subpath and version_match(subpath[0]):
        request.subpath = subpath[1:]
    return static_view(context, request)


def site_view(context, request):
Beispiel #5
0
from repoze.bfg.view import static
static_view = static('templates/static')
Beispiel #6
0
from repoze.bfg.view import static
static_view = static('templates/static')
Beispiel #7
0
#############################################################################
#
# Copyright (c) 2009 Victorian Partnership for Advanced Computing Ltd and
# Contributors.
# All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################


from repoze.bfg.view import static
static_view = static('../templates/static')


Beispiel #8
0
from repoze.bfg.interfaces import ISettings

from zope.component import queryUtility
from zope.component import getUtility

from webob import Response
from webob.exc import HTTPFound

from interfaces import IHTMLRenderer
from interfaces import IFRSFolder, IFRSDocument

#mimetypes.add_type('text/html', '.py')
#mimetypes.add_type('text/html', '.zcml')
#mimetypes.add_type('application/pdf', '.pdf')

resources_view = static('resources')
rules_view = static('deliverance/rules')
static_view = static('templates/static')


def folder_view(context, request):
    if not request.url.endswith('/'):
        response = HTTPFound(location=request.url + '/')
        return response

    defaults = ('index.html', 'index.rst')
    for name in defaults:
        try:
            index = context[name]
        except KeyError:
            continue