Esempio n. 1
0
def make_product(request, line):
    code = line.strip()
    C = request.environ['couchish']
    with C.session() as S:
        product = S.doc_by_view('product/by_code',key=code)
    data = {'request': request, 'product': product}
    out = templating.render(request, 'shop/product-fragment.html', data, encoding='utf8')
    return out
Esempio n. 2
0
 def html(self, request):
     C = request.environ['couchish']
     with C.session() as S:
         results = list(S.view('page/by_url',key='/',include_docs=True))
         news = S.docs_by_view('newsitem/homepage_news')
     news = [n for n in news if n.get('date') and n['date'] < date.today()]
     page = results[0].doc
     sitemap = navigation.get_navigation(request)
     data = {'page': page, 'request': request, 'sitemap': sitemap, 'news':news}
     out = templating.render(request, page['pagetype'], data, encoding='utf-8')
     return http.ok([('Content-Type', 'text/html')], out)
Esempio n. 3
0
 def test_encoding(self):
     """
     Check that only a rendered page encoded output by default.
     """
     def renderer(template, args, encoding=None):
         return str(encoding)
     @templating.element('element')
     def element(element, request):
         return {}
     @templating.page('page')
     def page(page, request):
         return {}
     request = http.Request.blank('/', environ={'restish.templating': templating.Templating(renderer)})
     assert templating.render(request, 'render') == 'None'
     assert element(None, request) == 'None'
     assert page(None, request).body == 'utf-8'
Esempio n. 4
0
 def test_encoding(self):
     """
     Check that only a rendered page encoded output by default.
     """
     def renderer(template, args, encoding=None):
         return str(encoding)
     @templating.element('element')
     def element(element, request):
         return {}
     @templating.page('page')
     def page(page, request):
         return {}
     request = http.Request.blank('/', environ={'restish.templating': templating.Templating(renderer)})
     assert templating.render(request, 'render') == 'None'
     assert element(None, request) == 'None'
     assert page(None, request).body == 'utf-8'
Esempio n. 5
0
 def test_render(self):
     request = http.Request.blank('/', environ={
         'restish.templating': templating.Templating(self.renderer)})
     assert templating.render(request, 'static') == self.content('static')
Esempio n. 6
0
 def __call__(self, request):
     messages = flash.get_messages(request.environ)
     if not messages:
         return ''
     return templating.render(request, 'flash_messages.html', {'messages': messages})
Esempio n. 7
0
 def csss(self, request, file):
     if file is None:
         return
     ccss = templating.render(request,'ccss/%s'%file, {})
     return http.ok([],ccss)
Esempio n. 8
0
 def css(self, request, file):
     if file is None:
         return
     ccss = templating.render(request,'ccss/%s'%file, {})
     css = clevercss.convert(ccss)
     return http.ok([('Content-Type', 'text/css')], css)
Esempio n. 9
0
 def test_render(self):
     def renderer(template, args, encoding=None):
         return "%s %r" % (template, sorted(args))
     request = http.Request.blank('/', environ={'restish.templating': templating.Templating(renderer)})
     assert templating.render(request, 'render') == "render ['urls']"
Esempio n. 10
0
 def test_render(self):
     request = http.Request.blank('/', environ={
         'restish.templating': templating.Templating(self.renderer)})
     assert templating.render(request, 'whatever') == TEST_STRING
Esempio n. 11
0
 def test_render_different_encoding(self):
     request = http.Request.blank('/', environ={
         'restish.templating': templating.Templating(self.renderer)})
     assert templating.render(request, 'static', encoding='iso-8859-1') == self.content('static', 'iso-8859-1')
Esempio n. 12
0
 def test_render_vars(self):
     request = http.Request.blank('/', environ={
         'restish.templating': templating.Templating(self.renderer)})
     assert templating.render(request, 'dynamic', {'foo': 'bar'}) == '<p>bar</p>'
Esempio n. 13
0
 def test_render(self):
     request = http.Request.blank('/', environ={
         'restish.templating': templating.Templating(self.renderer)})
     assert templating.render(request, 'static') == self.content('static')
Esempio n. 14
0
 def __call__(self, request):
     messages = flash.get_messages(request.environ)
     if not messages:
         return ''
     return templating.render(request, 'flash_messages.html',
                              {'messages': messages})
Esempio n. 15
0
 def test_render_vars(self):
     request = http.Request.blank('/', environ={
         'restish.templating': templating.Templating(self.renderer)})
     assert templating.render(request, 'dynamic', {'foo': 'bar'}) == '<p>bar</p>'
Esempio n. 16
0
 def test_render_different_encoding(self):
     request = http.Request.blank('/', environ={
         'restish.templating': templating.Templating(self.renderer)})
     assert templating.render(request, 'whatever', encoding='iso-8859-1') == TEST_STRING.encode('iso-8859-1')
Esempio n. 17
0
 def test_render_different_encoding(self):
     request = http.Request.blank('/', environ={
         'restish.templating': templating.Templating(self.renderer)})
     assert templating.render(request, 'static', encoding='iso-8859-1') == self.content('static', 'iso-8859-1')
Esempio n. 18
0
 def test_render(self):
     def renderer(template, args, encoding=None):
         return "%s %r" % (template, sorted(args))
     request = http.Request.blank('/', environ={'restish.templating': templating.Templating(renderer)})
     assert templating.render(request, 'render') == "render ['urls']"