def test_js_many(self): Component( Component(js='test1js'), Component(js='test2js'), Component(js='test3js'), ).render() self.assertEqual(parts()['js'], ['test1js', 'test2js', 'test3js'])
def test_css_many(self): Component( Component(css='test1css'), Component(css='test2css'), Component(css='test3css'), ).render() self.assertEqual(parts()['css'], ['test1css', 'test2css', 'test3css'])
def test_css_many_with_none(self): Component( Component(css='test1css'), Component(css=None), None, Component(css='test3css'), ).render() self.assertEqual(parts()['css'], ['test1css', 'test3css'])
def test_js_many_with_none(self): Component( Component(js='test1js'), Component(js=None), None, Component(js='test3js'), ).render() self.assertEqual(parts()['js'], ['test1js', 'test3js'])
def test_undefined_many_with_none(self): Component( Component(other='test1other'), Component(other=None), None, Component(other='test3other'), ).render() self.assertEqual(parts()['other'], ['test1other', 'test3other'])
def test_mixed(self): html = Component( Component('test', css='css1', other='test1other'), Component('one', Component('two', css='css2'), other=None, css=None), None, Component('Hey', None, js='testjs'), ).render() self.assertEqual(html, 'testonetwoHey') self.assertEqual(parts()['css'], ['css1', 'css2']) self.assertEqual(parts()['js'], ['testjs']) self.assertEqual(parts()['other'], ['test1other'])
def index(self): content = Component( markdown(""" Parts ==== * <div class="component-pink">component styles makes this pink</div> * <div class="component-green">component css makes this green</div> * <div class="component-chocolate">component libs makes this chocolate</div> * <div class="component-magenta">component js makes this magenta</div> * <div class="component-coral">component head makes this coral</div> * <div class="component-tomato">component tail makes this tomato</div> * <div class="page-slategray">page styles makes this slategray</div> * <div class="page-red">page css makes this red</div> * <div class="page-purple">page libs makes this purple</div> * <div class="page-cyan">page js makes this cyan</div> * <div class="page-navy">page head makes this navy</div> * <div class="page-olive">page tail makes this olive</div> """), styles=['/sample/parts/mystyle'], css=".component-green {color: green}", libs=['/sample/parts/mylib'], js='$(".component-magenta").css("color", "magenta")', head='<style>.component-coral {color: coral}</style>', tail= '<script>$(".component-tomato").css("color", "tomato")</script>', ) return page( content, styles=['/sample/parts/pagestyle'], css='.page-red {color: red}', libs=['/sample/parts/pagelib'], js='$(".page-cyan").css("color", "cyan")', head='<style>.page-navy {color: navy}</style>', tail='<script>$(".page-olive").css("color", "olive")</script>', )
def render(self, request): """render page""" logger = logging.getLogger(__name__) logger.debug('rendering page') self.content = Component(self.header(), self.content, *self.args).render() app_theme = request.app.theme if hasattr(request, 'app') else None site_theme = request.site.theme self.theme = self.kwargs.get('theme', app_theme or site_theme or 'default') self.theme_uri = '/themes/' + self.theme zoom.render.add_helpers( zoom.forms.helpers(request), self.helpers(request), ) template = zoom.tools.get_template(self.template, self.theme) if zoom.system.site.settings.site.cookie_consent: zoom.requires('cookieconsent') return HTMLResponse(template, status=self.status)
def test_format_css_multi(self): css = '.thing { color1: $(( color1 )); color2: $(( color2 )); }' Component(css=css).format( color1='red', color2='blue', ).render() self.assertEqual(parts()['css'], ['.thing { color1: red; color2: blue; }'])
def render(self, request): """render page""" logger = logging.getLogger(__name__) logger.debug('rendering page') if self.title or self.subtitle or self.actions or self.search: full_page = Component(PageHeader(page=self), self.content) else: full_page = Component(self.content) self.content = full_page.render() zoom.render.add_helpers( zoom.forms.helpers(request), self.helpers(request), ) template = request.site.get_template(self.template) return HTMLResponse(template)
def index(self, q=''): db = self.model.site.db users = sorted(Users(db).find(status='A'), key=lambda a: a.name) groups = db('select * from groups') members = db('select * from members') subgroups = db('select * from subgroups') content = Component( index_metrics_view(db), IndexPageLayoutView( feed1=Component( PanelView(title='Users', content=browse(users)), PanelView(title='Groups', content=browse(groups)), ), feed2=PanelView(title='Memberships', content=browse(members)), feed3=PanelView(title='Subgroups', content=browse(subgroups)), ), ) return page(content, title='Overview', subtitle='Raw dump of main tables', search=q)
def _index(self): # return None self.model.site.logging = False db = self.model.site.db content = Component( index_metrics_view(db), IndexPageLayoutView( feed1=activity_panel(db), feed2=users_panel(db), feed3=error_panel(db), ), ) return content
def render(self, request): """render page""" logger = logging.getLogger(__name__) logger.debug('rendering page') if self.title or self.subtitle or self.actions or self.search: full_page = Component(PageHeader(page=self), self.content) else: full_page = Component(self.content) self.content = full_page.render() self.theme = self.kwargs.get('theme', zoom.system.site.theme) self.theme_uri = '/themes/' + self.theme zoom.render.add_helpers( zoom.forms.helpers(request), self.helpers(request), ) template = zoom.tools.get_template(self.template, self.theme) return HTMLResponse(template)
def test_html_many_with_none(self): self.assertEqual( Component(None, 'hey', None, 'you', None).render(), 'heyyou')
def test_undefined(self): Component(other='othertext').render() self.assertEqual(parts()['other'], ['othertext'])
def test_format_html(self): widget = Component('Hello {name}!') html = widget.format(name='Sam').render() self.assertEqual(html, 'Hello Sam!')
def test_format_js(self): Component(js='$(".thing").html("$(( name ))");').format( name='Sam').render() self.assertEqual(parts()['js'], ['$(".thing").html("Sam");'])
def test_js(self): Component(js='testjs').render() self.assertEqual(parts()['js'], ['testjs'])
def test_format_css(self): Component(css='.thing { color: $(( color )); }').format( color='red').render() self.assertEqual(parts()['css'], ['.thing { color: red; }'])
def test_html_many(self): self.assertEqual(Component('hey', 'you').render(), 'heyyou')
def test_html(self): self.assertEqual(Component('hey').render(), 'hey')
def setUp(self): zoom.system.parts = Component()
def metrics(self): return Component(MetricView(m) for m in self.model)
def test_css(self): Component(css='testcss').render() self.assertEqual(parts()['css'], ['testcss'])