--- a/cwvreg.py Wed Feb 18 16:55:01 2009 +0100
+++ b/cwvreg.py Wed Feb 18 17:12:52 2009 +0100
@@ -198,7 +198,7 @@
and returning the output as a string instead of requiring the [w]rite
method as argument
"""
- res = self.render('templates', oid, req, **context)
+ res = self.render('views', oid, req, **context)
if isinstance(res, unicode):
return res.encode(req.encoding)
assert isinstance(res, str)
--- a/view.py Wed Feb 18 16:55:01 2009 +0100
+++ b/view.py Wed Feb 18 17:12:52 2009 +0100
@@ -9,6 +9,7 @@
from cStringIO import StringIO
+from logilab.common.deprecation import obsolete
from logilab.mtconverter import html_escape
from cubicweb import NotAnEntity, NoSelectableObject
@@ -91,8 +92,9 @@
attributes are added and the `w` attribute will be set at rendering
time to a write function to use.
"""
+ __registry__ = 'views'
__registerer__ = priority_registerer
- __registry__ = 'views'
+ registered = require_group_compat(AppRsetObject.registered)
templatable = True
need_navigation = True
@@ -205,8 +207,8 @@
self.req.set_content_type(self.content_type)
# view utilities ##########################################################
-
- def view(self, __vid, rset, __fallback_vid=None, **kwargs):
+
+ def view(self, __vid, rset=None, __fallback_vid=None, **kwargs):
"""shortcut to self.vreg.render method avoiding to pass self.req"""
try:
view = self.vreg.select_view(__vid, self.req, rset, **kwargs)
@@ -215,7 +217,10 @@
raise
view = self.vreg.select_view(__fallback_vid, self.req, rset, **kwargs)
return view.dispatch(**kwargs)
-
+
+ # XXX Template bw compat
+ template = obsolete('.template is deprecated, use .view')(view)
+
def wview(self, __vid, rset, __fallback_vid=None, **kwargs):
"""shortcut to self.view method automatically passing self.w as argument
"""
@@ -414,27 +419,13 @@
# concrete template base classes ##############################################
-class Template(View):
- """a template is almost like a view, except that by default a template
- is only used globally (i.e. no result set adaptation)
- """
- __registry__ = 'templates'
- __select__ = yes()
-
- registered = require_group_compat(View.registered)
-
- def template(self, oid, **kwargs):
- """shortcut to self.registry.render method on the templates registry"""
- w = kwargs.pop('w', self.w)
- self.vreg.render('templates', oid, self.req, w=w, **kwargs)
-
-
-class MainTemplate(Template):
+class MainTemplate(View):
"""main template are primary access point to render a full HTML page.
There is usually at least a regular main template and a simple fallback
one to display error if the first one failed
"""
base_doctype = STRICT_DOCTYPE
+ registered = require_group_compat(View.registered)
@property
def doctype(self):
--- a/web/box.py Wed Feb 18 16:55:01 2009 +0100
+++ b/web/box.py Wed Feb 18 17:12:52 2009 +0100
@@ -12,8 +12,9 @@
from cubicweb import Unauthorized, role as get_role
from cubicweb.selectors import (one_line_rset, primary_view,
match_context_prop, abstract_has_related_entities,
- accepts_compat, has_relation_compat, condition_compat)
-from cubicweb.view import Template, ReloadableMixIn
+ accepts_compat, has_relation_compat,
+ condition_compat, require_group_compat)
+from cubicweb.view import View, ReloadableMixIn
from cubicweb.web.htmlwidgets import (BoxLink, BoxWidget, SideBoxWidget,
RawBoxItem, BoxSeparator)
@@ -22,7 +23,7 @@
_ = unicode
-class BoxTemplate(Template):
+class BoxTemplate(View):
"""base template for boxes, usually a (contextual) list of possible
actions. Various classes attributes may be used to control the box
@@ -38,6 +39,7 @@
"""
__registry__ = 'boxes'
__select__ = match_context_prop()
+ registered = require_group_compat(View.registered)
categories_in_order = ()
property_defs = {
--- a/web/views/basetemplates.py Wed Feb 18 16:55:01 2009 +0100
+++ b/web/views/basetemplates.py Wed Feb 18 17:12:52 2009 +0100
@@ -11,7 +11,7 @@
from logilab.mtconverter import html_escape
from cubicweb import NoSelectableObject, ObjectNotFound
-from cubicweb.view import Template, MainTemplate, NOINDEX, NOFOLLOW
+from cubicweb.view import View, MainTemplate, NOINDEX, NOFOLLOW
from cubicweb.utils import make_uid, UStringIO
from cubicweb.web.views.baseviews import vid_from_rset
@@ -38,7 +38,7 @@
w(NOINDEX)
w(NOFOLLOW)
w(u'\n'.join(additional_headers) + u'\n')
- self.template('htmlheader', rset=self.rset)
+ self.view('htmlheader', rset=self.rset)
w(u'<title>%s</title>\n' % html_escape(page_title))
@@ -47,7 +47,7 @@
title = 'log in'
def content(self, w):
- self.template('logform', rset=self.rset, id='loginBox', klass='')
+ self.view('logform', rset=self.rset, id='loginBox', klass='')
class LoggedOutTemplate(LogInOutTemplate):
@@ -128,7 +128,7 @@
self.set_request_content_type()
content_type = self.content_type
self.template_header(content_type, view)
- self.template('page-content', view=view, rset=rset)
+ self.view('page-content', view=view, rset=rset)
if with_templates:
self.template_footer(view)
@@ -161,14 +161,14 @@
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n'
% (content_type, self.req.encoding))
w(u'\n'.join(additional_headers) + u'\n')
- self.template('htmlheader', rset=self.rset)
+ self.view('htmlheader', rset=self.rset)
if page_title:
w(u'<title>%s</title>\n' % html_escape(page_title))
def template_body_header(self, view):
w = self.w
w(u'<body>\n')
- self.template('header', rset=self.rset, view=view)
+ self.view('header', rset=self.rset, view=view)
w(u'<div id="page"><table width="100%" border="0" id="mainLayout"><tr>\n')
self.nav_column(view, 'left')
w(u'<td id="contentcol">\n')
@@ -185,7 +185,7 @@
self.w(u'</td>\n')
self.nav_column(view, 'right')
self.w(u'</tr></table></div>\n')
- self.template('footer', rset=self.rset)
+ self.view('footer', rset=self.rset)
self.w(u'</body>')
def nav_column(self, view, context):
@@ -199,10 +199,10 @@
def content_header(self, view=None):
"""by default, display informal messages in content header"""
- self.template('contentheader', rset=self.rset, view=view)
+ self.view('contentheader', rset=self.rset, view=view)
def content_footer(self, view=None):
- self.template('contentfooter', rset=self.rset, view=view)
+ self.view('contentfooter', rset=self.rset, view=view)
class PageContentTemplate(TheMainTemplate):
@@ -266,7 +266,7 @@
w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n'
% (content_type, self.req.encoding))
w(u'\n'.join(additional_headers))
- self.template('htmlheader', rset=self.rset)
+ self.view('htmlheader', rset=self.rset)
w(u'<title>%s</title>\n' % html_escape(page_title))
self.w(u'<body>\n')
@@ -287,7 +287,7 @@
whead(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n'
% (content_type, self.req.encoding))
whead(u'\n'.join(additional_headers) + u'\n')
- self.template('htmlheader', rset=self.rset)
+ self.view('htmlheader', rset=self.rset)
w = self.w
w(u'<title>%s</title>\n' % html_escape(page_title))
w(u'<body>\n')
@@ -318,7 +318,7 @@
# page parts templates ########################################################
-class HTMLHeader(Template):
+class HTMLHeader(View):
"""default html headers"""
id = 'htmlheader'
@@ -362,7 +362,7 @@
req.html_headers.define_var('pageid', pid);
-class HTMLPageHeader(Template):
+class HTMLPageHeader(View):
"""default html page header"""
id = 'header'
@@ -403,8 +403,8 @@
self.w(u'<td id="lastcolumn">')
self.w(u'</td>\n')
self.w(u'</tr></table>\n')
- self.template('logform', rset=self.rset, id='popupLoginBox', klass='hidden',
- title=False, message=False)
+ self.view('logform', rset=self.rset, id='popupLoginBox', klass='hidden',
+ title=False, message=False)
def state_header(self):
state = self.req.search_state
@@ -422,7 +422,7 @@
-class HTMLPageFooter(Template):
+class HTMLPageFooter(View):
"""default html page footer: include logo if any, and close the HTML body
"""
id = 'footer'
@@ -441,7 +441,7 @@
self.w(u'</div>')
-class HTMLContentHeader(Template):
+class HTMLContentHeader(View):
"""default html page content header:
* include message component if selectable for this request
* include selectable content navigation components
@@ -460,7 +460,7 @@
self.w(u'</div><div class="clear"></div>')
-class HTMLContentFooter(Template):
+class HTMLContentFooter(View):
"""default html page content footer: include selectable content navigation
components
"""
@@ -477,7 +477,7 @@
self.w(u'</div>')
-class LogFormTemplate(Template):
+class LogFormTemplate(View):
id = 'logform'
title = 'log in'