[Checkins] SVN: grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/ The tests works again
Christian Klinger
cklinger at novareto.de
Fri Jul 3 10:59:43 EDT 2009
Log message for revision 101447:
The tests works again
Changed:
U grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/components.py
U grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/ftests/view/macros.py
U grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/meta/views.py
-=-
Modified: grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/components.py
===================================================================
--- grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/components.py 2009-07-03 14:48:44 UTC (rev 101446)
+++ grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/components.py 2009-07-03 14:59:43 UTC (rev 101447)
@@ -31,12 +31,64 @@
from grokcore.view import interfaces, util
-class CodeView(BrowserPage):
+class BaseView(BrowserPage):
interface.implements(interfaces.IGrokView)
def __init__(self, context, request):
+ super(BaseView, self).__init__(context, request)
+ self.__name__ = getattr(self, '__view_name__', None)
+
+ def update(self):
+ pass
+
+ def redirect(self, url):
+ return self.request.response.redirect(url)
+
+
+ def url(self, obj=None, name=None, data=None):
+ """Return string for the URL based on the obj and name. The data
+ argument is used to form a CGI query string.
+ """
+ if isinstance(obj, basestring):
+ if name is not None:
+ raise TypeError(
+ 'url() takes either obj argument, obj, string arguments, '
+ 'or string argument')
+ name = obj
+ obj = None
+
+ if name is None and obj is None:
+ # create URL to view itself
+ obj = self
+ elif name is not None and obj is None:
+ # create URL to view on context
+ obj = self.context
+
+ if data is None:
+ data = {}
+ else:
+ if not isinstance(data, dict):
+ raise TypeError('url() data argument must be a dict.')
+
+ return util.url(self.request, obj, name, data=data)
+
+
+class CodeView(BaseView):
+ interface.implements(interfaces.IGrokView)
+
+ def __init__(self, context, request):
super(CodeView, self).__init__(context, request)
+ def default_namespace(self):
+ namespace = {}
+ namespace['context'] = self.context
+ namespace['request'] = self.request
+ namespace['view'] = self
+ return namespace
+
+ def namespace(self):
+ return {}
+
def __call__(self):
mapply(self.update, (), self.request)
if self.request.response.getStatus() in (302, 303):
@@ -49,16 +101,12 @@
return self._render_template()
return mapply(self.render, (), self.request)
- def update(self):
- pass
-
-class View(BrowserPage):
+class View(BaseView):
interface.implements(interfaces.IGrokView)
def __init__(self, context, request):
super(View, self).__init__(context, request)
- self.__name__ = getattr(self, '__view_name__', None)
if getattr(self, 'module_info', None) is not None:
self.static = component.queryAdapter(
@@ -69,6 +117,8 @@
else:
self.static = None
+
+ # Might be moved to BaseView currently only needed for PageTemplates CHECKTHIS
@property
def response(self):
return self.request.response
@@ -114,40 +164,6 @@
return value
- def url(self, obj=None, name=None, data=None):
- """Return string for the URL based on the obj and name. The data
- argument is used to form a CGI query string.
- """
- if isinstance(obj, basestring):
- if name is not None:
- raise TypeError(
- 'url() takes either obj argument, obj, string arguments, '
- 'or string argument')
- name = obj
- obj = None
-
- if name is None and obj is None:
- # create URL to view itself
- obj = self
- elif name is not None and obj is None:
- # create URL to view on context
- obj = self.context
-
- if data is None:
- data = {}
- else:
- if not isinstance(data, dict):
- raise TypeError('url() data argument must be a dict.')
-
- return util.url(self.request, obj, name, data=data)
-
- def redirect(self, url):
- return self.request.response.redirect(url)
-
- def update(self):
- pass
-
-
class BaseTemplate(object):
"""Any sort of page template"""
Modified: grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/ftests/view/macros.py
===================================================================
--- grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/ftests/view/macros.py 2009-07-03 14:48:44 UTC (rev 101446)
+++ grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/ftests/view/macros.py 2009-07-03 14:59:43 UTC (rev 101447)
@@ -19,7 +19,8 @@
>>> browser.open("http://localhost/manfred/@@dancing")
Traceback (most recent call last):
- AttributeError: 'DancingHall' object has no attribute 'template'
+ ...
+ TraversalError: (<grokcore.view.ftests.view.macros.DancingHall object at ...>, 'macros')
If the view has an attribute with the same name as a macro, the macro
shadows the view. XXX This should probably generate a warning at runtime.
@@ -82,7 +83,7 @@
class DancingHall(grok.CodeView):
def render(self):
- return "A nice large dancing hall for mammoths."
+ return "Bla Bla Dancing Hall"
class Grilled(grok.View):
Modified: grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/meta/views.py
===================================================================
--- grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/meta/views.py 2009-07-03 14:48:44 UTC (rev 101446)
+++ grokcore.view/branches/reinout-christian-codeview/src/grokcore/view/meta/views.py 2009-07-03 14:59:43 UTC (rev 101447)
@@ -135,7 +135,7 @@
class ViewSecurityGrokker(martian.ClassGrokker):
- martian.component(components.View)
+ martian.component(components.BaseView)
martian.directive(grokcore.security.require, name='permission')
def execute(self, factory, config, permission, **kw):
More information about the Checkins
mailing list