Beispiel #1
0
def call(self, view):
    self.set_request_content_type()
    self.template_header(self.content_type, view)
    w = self.w
    w(u'<div class="row-fluid">')
    w(u'<div class="span12" id="pageContent">')
    vtitle = self._cw.form.get('vtitle')
    if vtitle:
        w(u'<div class="vtitle">%s</div>\n' % xml_escape(vtitle))
    # display entity type restriction component
    etypefilter = self._cw.vreg['components'].select_or_none(
        'etypenavigation', self._cw, rset=self.cw_rset)
    if etypefilter and etypefilter.cw_propval('visible'):
        etypefilter.render(w=w)
    nav_html = UStringIO()
    if view and not view.handle_pagination:
        view.paginate(w=nav_html.write)
    w(nav_html.getvalue())
    w(u'<div id="contentmain">\n')
    view.render(w=w)
    w(u'</div>\n') # closes id=contentmain
    w(nav_html.getvalue())
    w(u'</div>\n' # closes id=pageContent
      u'</div>\n') # closes row-fluid
    self.template_footer(view)
Beispiel #2
0
 def render_table(self, w, actions, paginate):
     view = self.view
     divid = view.domid
     if divid is not None:
         w(u'<div id="%s">' % divid)
     else:
         assert not (actions or paginate)
     nav_html = UStringIO()
     if paginate:
         view.paginate(w=nav_html.write,
                       show_all_option=self.show_all_option)
     w(nav_html.getvalue())
     if actions and self.display_actions == 'top':
         self.render_actions(w, actions)
     colrenderers = view.build_column_renderers()
     attrs = self.table_attributes()
     w(u'<table %s>' % sgml_attributes(attrs))
     if self.view.has_headers:
         self.render_table_headers(w, colrenderers)
     self.render_table_body(w, colrenderers)
     w(u'</table>')
     if actions and self.display_actions == 'bottom':
         self.render_actions(w, actions)
     w(nav_html.getvalue())
     if divid is not None:
         w(u'</div>')
Beispiel #3
0
 def _convert(self, trdata):
     context = CubicWebContext()
     appobject = trdata.appobject
     context.update({'self': appobject, 'rset': appobject.cw_rset,
                     'req': appobject._cw,
                     '_' : appobject._cw._,
                     'user': appobject._cw.user})
     output = UStringIO()
     template = compile_template(trdata.encode(self.output_encoding))
     template.expand(context, output)
     return output.getvalue()
Beispiel #4
0
 def tal_render(self, template, variables):
     """render a precompiled page template with variables in the given
     dictionary as context
     """
     from cubicweb.ext.tal import CubicWebContext
     context = CubicWebContext()
     context.update({
         'self': self,
         'rset': self.cw_rset,
         '_': self._cw._,
         'req': self._cw,
         'user': self._cw.user
     })
     context.update(variables)
     output = UStringIO()
     template.expand(context, output)
     return output.getvalue()
Beispiel #5
0
    def page_main(self, view):
        """display main section of the main template
        """
        components = self._cw.vreg['components']
        rqlcomp = components.select_or_none('rqlinput',
                                            self._cw,
                                            rset=self.cw_rset)
        #FIXME this is a trick to find out if boxes exists for this element
        context = 'left'
        boxes = list(self._cw.vreg['ctxcomponents'].poss_visible_objects(
            self._cw, rset=self.cw_rset, view=view, context=context))
        if boxes:
            columns = 9
        else:
            columns = 12
        self.w(u'<!-- <section id="main">'
               u'<div class="container">'
               u'<div class="row"> -->')

        self.w(u'<div class="span%i container" id="pageContent">' % columns)
        if rqlcomp:
            rqlcomp.render(w=self.w, view=view)
        msgcomp = components.select_or_none('applmessages',
                                            self._cw,
                                            rset=self.cw_rset)
        if msgcomp:
            msgcomp.render(w=self.w)
        # vtitle
        vtitle = self._cw.form.get('vtitle')
        if vtitle:
            self.w(u'<div class="vtitle">%s</div>' % xml_escape(vtitle))
        # display entity type restriction component
        etypefilter = self._cw.vreg['components'].select_or_none(
            'etypenavigation', self._cw, rset=self.cw_rset)
        if etypefilter and etypefilter.cw_propval('visible'):
            etypefilter.render(w=w)
        nav_html = UStringIO()
        if view and not view.handle_pagination:
            view.paginate(w=nav_html.write)
        self.w(nav_html.getvalue())
        view.render(w=self.w)
        self.w(nav_html.getvalue())
        self.w(u'</div>')
        # aside section - write boxes for this element
        self.nav_column(view, 'left')
        self.w(u'<!-- </div>' u'</div>' u'</section> -->')
Beispiel #6
0
 def set_stream(self, w=None):
     if self.w is not None:
         return
     if w is None:
         if self.binary:
             self._stream = stream = BytesIO()
         else:
             self._stream = stream = UStringIO()
         w = stream.write
     else:
         stream = None
     self.w = w
     return stream
Beispiel #7
0
 def call(self, view):
     self.set_request_content_type()
     self.template_header(self.content_type, view)
     w = self.w
     w(u'<div id="pageContent">\n')
     vtitle = self._cw.form.get('vtitle')
     if vtitle:
         w(u'<div class="vtitle">%s</div>\n' % xml_escape(vtitle))
     # display entity type restriction component
     etypefilter = self._cw.vreg['components'].select_or_none(
         'etypenavigation', self._cw, rset=self.cw_rset)
     if etypefilter and etypefilter.cw_propval('visible'):
         etypefilter.render(w=w)
     w(u'<div id="contentmain">\n')
     nav_html = UStringIO()
     if view and not view.handle_pagination:
         view.paginate(w=nav_html.write)
     w(nav_html.getvalue())
     view.render(w=w)
     w(nav_html.getvalue())
     w(u'</div>\n')  # close id=contentmain
     w(u'</div>\n')  # closes id=pageContent
     self.template_footer(view)
Beispiel #8
0
class PlotWidget(object):
    # XXX refactor with cubicweb.web.views.htmlwidgets.HtmlWidget
    def _initialize_stream(self, w=None):
        if w:
            self.w = w
        else:
            self._stream = UStringIO()
            self.w = self._stream.write

    def render(self, *args, **kwargs):
        w = kwargs.pop('w', None)
        self._initialize_stream(w)
        self._render(*args, **kwargs)
        if w is None:
            return self._stream.getvalue()

    def _render(self, *args, **kwargs):
        raise NotImplementedError
Beispiel #9
0
class HTMLWidget(object):
    def _initialize_stream(self, w=None):
        if w:
            self.w = w
        else:
            self._stream = UStringIO()
            self.w = self._stream.write

    def _render(self):
        raise NotImplementedError

    def render(self, w=None):
        self._initialize_stream(w)
        self._render()
        if w is None:
            return self._stream.getvalue()

    def is_empty(self):
        return False
Beispiel #10
0
 def _initialize_stream(self, w=None):
     if w:
         self.w = w
     else:
         self._stream = UStringIO()
         self.w = self._stream.write
Beispiel #11
0
 def _call_view(self, view, paginate=False, **kwargs):
     divid = self._cw.form.get('divid')
     # we need to call pagination before with the stream set
     try:
         stream = view.set_stream()
     except AttributeError:
         stream = UStringIO()
         kwargs['w'] = stream.write
         assert not paginate
     if divid == 'contentmain':
         # ensure divid isn't reused by the view (e.g. table view)
         del self._cw.form['divid']
         paginate = True
     if divid == 'contentmain':
         stream.write(u'<div id="contentmain">')
     nav_html = UStringIO()
     if paginate and not view.handle_pagination:
         view.paginate(w=nav_html.write)
     stream.write(nav_html.getvalue())
     view.render(**kwargs)
     stream.write(nav_html.getvalue())
     if divid == 'contentmain':
         stream.write(u'</div>')
     extresources = self._cw.html_headers.getvalue(skiphead=True)
     if extresources:
         stream.write(u'<div class="ajaxHtmlHead">\n')  # XXX use a widget?
         stream.write(extresources)
         stream.write(u'</div>\n')
     return stream.getvalue()
 def test_boolean_value(self):
     self.assertTrue(UStringIO())
Beispiel #13
0
def _call_view(self, view, paginate=False, **kwargs):
    divid = self._cw.form.get('divid')
    # we need to call pagination before with the stream set
    try:
        stream = view.set_stream()
    except AttributeError:
        stream = UStringIO()
        kwargs['w'] = stream.write
        assert not paginate
    if divid == 'pageContent':
        # ensure divid isn't reused by the view (e.g. table view)
        del self._cw.form['divid']
        # mimick main template behaviour
        stream.write(u'<div class="col-md-12" id="pageContent">')
        vtitle = self._cw.form.get('vtitle')
        if vtitle:
            stream.write(u'<h1 class="vtitle">%s</h1>\n' % vtitle)
        paginate = True
    nav_html = UStringIO()
    if paginate and not view.handle_pagination:
        view.paginate(w=nav_html.write)
    stream.write(nav_html.getvalue())
    if divid == 'pageContent':
        stream.write(u'<div id="contentmain">')
    view.render(**kwargs)
    extresources = self._cw.html_headers.getvalue(skiphead=True)
    if extresources:
        stream.write(u'<div class="ajaxHtmlHead">\n') # XXX use a widget ?
        stream.write(extresources)
        stream.write(u'</div>\n')
    if divid == 'pageContent':
        stream.write(u'</div>%s</div>' % nav_html.getvalue())
    return stream.getvalue()
Beispiel #14
0
 def _call_view(self, view, paginate=False, **kwargs):
     divid = self._cw.form.get('divid')
     # we need to call pagination before with the stream set
     try:
         stream = view.set_stream()
     except AttributeError:
         stream = UStringIO()
         kwargs['w'] = stream.write
         assert not paginate
     if divid == 'pageContent':
         # ensure divid isn't reused by the view (e.g. table view)
         del self._cw.form['divid']
         # mimick main template behaviour
         stream.write(u'<div class="span9 pull-right" id="pageContent">')
         vtitle = self._cw.form.get('vtitle')
         if vtitle:
             stream.write(u'<h1 class="vtitle">%s</h1>\n' % vtitle)
         paginate = True
     nav_html = UStringIO()
     if paginate and not view.handle_pagination:
         view.paginate(w=nav_html.write)
     stream.write(nav_html.getvalue())
     if divid == 'pageContent':
         stream.write(u'<div id="contentmain">')
     view.render(**kwargs)
     extresources = self._cw.html_headers.getvalue(skiphead=True)
     if extresources:
         stream.write(u'<div class="ajaxHtmlHead">\n')  # XXX use a widget ?
         stream.write(extresources)
         stream.write(u'</div>\n')
     if divid == 'pageContent':
         stream.write(u'</div>%s</div>' % nav_html.getvalue())
     return stream.getvalue()