[Checkins] SVN: five.grok/branches/regebro-grokcore.view/ Now uses
ViewMixin from grokcore.view.
Lennart Regebro
regebro at gmail.com
Fri Jul 18 06:20:31 EDT 2008
Log message for revision 88486:
Now uses ViewMixin from grokcore.view.
Changed:
U five.grok/branches/regebro-grokcore.view/buildout.cfg
_U five.grok/branches/regebro-grokcore.view/devel/
U five.grok/branches/regebro-grokcore.view/devel/EXTERNALS.txt
U five.grok/branches/regebro-grokcore.view/setup.py
U five.grok/branches/regebro-grokcore.view/src/five/grok/components.py
U five.grok/branches/regebro-grokcore.view/src/five/grok/ftests/view/macros.py
-=-
Modified: five.grok/branches/regebro-grokcore.view/buildout.cfg
===================================================================
--- five.grok/branches/regebro-grokcore.view/buildout.cfg 2008-07-18 10:12:26 UTC (rev 88485)
+++ five.grok/branches/regebro-grokcore.view/buildout.cfg 2008-07-18 10:20:31 UTC (rev 88486)
@@ -14,6 +14,7 @@
eggs = five.grok
grokcore.component
+ grokcore.view
martian
zope.testing
@@ -21,6 +22,7 @@
# e.g.: develop = src/my.package
develop = .
devel/grokcore.component
+ devel/grokcore.view
devel/martian
newest = false
@@ -28,6 +30,7 @@
[zope2]
recipe = plone.recipe.zope2install
url = http://www.zope.org/Products/Zope/2.10.5/Zope-2.10.5-final.tgz
+fake-zope-eggs = true
[instance]
recipe = plone.recipe.zope2instance
@@ -59,6 +62,6 @@
[test]
recipe = zc.recipe.testrunner
-eggs = five.grok
+eggs = ${buildout:eggs}
extra-paths = ${zope2:location}/lib/python
-defaults = ['--tests-pattern', '^f?tests$', '-v']
+defaults = ['-m', 'five.grok', '--tests-pattern', '^f?tests$', '-v']
Property changes on: five.grok/branches/regebro-grokcore.view/devel
___________________________________________________________________
Name: svn:externals
- # svn ps -F EXTERNALS.txt svn:externals .
grokcore.component svn://svn.zope.org/repos/main/grokcore.component/trunk
martian svn://svn.zope.org/repos/main/martian/trunk
+ # svn ps -F EXTERNALS.txt svn:externals .
grokcore.component svn://svn.zope.org/repos/main/grokcore.component/trunk
grokcore.view svn://svn.zope.org/repos/main/grok/branches/grokcore.xxx/devel/grokcore.view
martian svn://svn.zope.org/repos/main/martian/trunk
Modified: five.grok/branches/regebro-grokcore.view/devel/EXTERNALS.txt
===================================================================
--- five.grok/branches/regebro-grokcore.view/devel/EXTERNALS.txt 2008-07-18 10:12:26 UTC (rev 88485)
+++ five.grok/branches/regebro-grokcore.view/devel/EXTERNALS.txt 2008-07-18 10:20:31 UTC (rev 88486)
@@ -1,3 +1,4 @@
# svn ps -F EXTERNALS.txt svn:externals .
grokcore.component svn://svn.zope.org/repos/main/grokcore.component/trunk
-martian svn://svn.zope.org/repos/main/martian/trunk
\ No newline at end of file
+grokcore.view svn://svn.zope.org/repos/main/grok/branches/grokcore.xxx/devel/grokcore.view
+martian svn://svn.zope.org/repos/main/martian/trunk
Modified: five.grok/branches/regebro-grokcore.view/setup.py
===================================================================
--- five.grok/branches/regebro-grokcore.view/setup.py 2008-07-18 10:12:26 UTC (rev 88485)
+++ five.grok/branches/regebro-grokcore.view/setup.py 2008-07-18 10:20:31 UTC (rev 88486)
@@ -30,6 +30,7 @@
install_requires=[
'setuptools',
'grokcore.component',
+ 'grokcore.view',
],
entry_points="""
""",
Modified: five.grok/branches/regebro-grokcore.view/src/five/grok/components.py
===================================================================
--- five.grok/branches/regebro-grokcore.view/src/five/grok/components.py 2008-07-18 10:12:26 UTC (rev 88485)
+++ five.grok/branches/regebro-grokcore.view/src/five/grok/components.py 2008-07-18 10:20:31 UTC (rev 88486)
@@ -17,121 +17,18 @@
from zope.app.container.contained import Contained
import persistent
-import zope.publisher.browser
-class BrowserPage(zope.publisher.browser.BrowserPage, Acquisition.Implicit):
- """Browser page with implicit Acquisition."""
+from zope.publisher.browser import BrowserPage
-# XXX Should probably be a SimpleItem.
class Model(SimpleItem):
# XXX Inheritance order is important here. If we reverse this,
# then containers can't be models anymore because no unambigous MRO
# can be established.
interface.implements(IAttributeAnnotatable, interfaces.IContext)
-
-class View(BrowserPage):
- interface.implements(interfaces.IGrokView)
- def __init__(self, context, request):
- super(View, self).__init__(context, request)
- self.__name__ = self.__view_name__
- self.static = component.queryAdapter(
- self.request,
- interface.Interface,
- name=self.module_info.package_dotted_name
- )
-
- @property
- def response(self):
- return self.request.response
-
- def __call__(self):
- mapply(self.update, (), self.request)
- if self.request.response.getStatus() in (302, 303):
- # A redirect was triggered somewhere in update(). Don't
- # continue rendering the template or doing anything else.
- return
-
- template = getattr(self, 'template', None)
- if template is not None:
- return self._render_template()
- return mapply(self.render, (), self.request)
-
- def _render_template(self):
- return self.template.render(self)
-
- def default_namespace(self):
- namespace = {}
- namespace['context'] = self.context
- namespace['request'] = self.request
- namespace['static'] = self.static
- namespace['view'] = self
- return namespace
-
- def namespace(self):
- return {}
-
- def __getitem__(self, key):
- # This is BBB code for Zope page templates only:
- if not isinstance(self.template, PageTemplate):
- raise AttributeError("View has no item %s" % key)
-
- value = self.template._template.macros[key]
- # When this deprecation is done with, this whole __getitem__ can
- # be removed.
- warnings.warn("Calling macros directly on the view is deprecated. "
- "Please use context/@@viewname/macros/macroname\n"
- "View %r, macro %s" % (self, key),
- DeprecationWarning, 1)
- 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 application_url(self, name=None):
- obj = self.context
- while obj is not None:
- if isinstance(obj, Application):
- return self.url(obj, name)
- obj = obj.__parent__
- raise ValueError("No application found.")
-
- def redirect(self, url):
- return self.request.response.redirect(url)
-
- def update(self):
- pass
-
- def flash(self, message, type='message'):
- source = component.getUtility(
- z3c.flashmessage.interfaces.IMessageSource, name='session')
- source.send(message, type)
+from grokcore.view.components import ViewMixin
+class View(ViewMixin, BrowserPage, Acquisition.Implicit):
+ pass
-
class BaseTemplate(object):
"""Any sort of page template"""
@@ -198,7 +95,7 @@
namespace = self.namespace(view)
namespace.update(view.namespace())
return namespace
-
+
class TrustedPageTemplate(TrustedAppPT, pagetemplate.PageTemplate):
pass
Modified: five.grok/branches/regebro-grokcore.view/src/five/grok/ftests/view/macros.py
===================================================================
--- five.grok/branches/regebro-grokcore.view/src/five/grok/ftests/view/macros.py 2008-07-18 10:12:26 UTC (rev 88485)
+++ five.grok/branches/regebro-grokcore.view/src/five/grok/ftests/view/macros.py 2008-07-18 10:20:31 UTC (rev 88486)
@@ -16,12 +16,6 @@
</body>
</html>
-Views without a template do not support macros:
-
- >>> browser.open("http://localhost/manfred/@@dancing")
- Traceback (most recent call last):
- AttributeError: template
-
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.
@@ -31,31 +25,12 @@
Curry
</html>
-You can skip the "macro" part of the macro call, but this is deprecated:
-
- >>> from five.grok.testing import warn
- >>> import warnings
- >>> saved_warn = warnings.warn
- >>> warnings.warn = warn
-
- >>> browser.open("http://localhost/manfred/@@burnt")
- From five.grok.testing's warn():
- ... DeprecationWarning: Calling macros directly on the view is deprecated. Please use context/@@viewname/macros/macroname
- ...
-
- >>> warnings.warn = saved_warn
-
"""
from five import grok
class Mammoth(grok.Model):
pass
-class DancingHall(grok.View):
-
- def render(self):
- return "A nice large dancing hall for mammoths."
-
class Grilled(grok.View):
def update(self):
@@ -99,13 +74,6 @@
<html metal:use-macro="context/@@grilled/macros/spices">
</html>""")
-class Burnt(grok.View):
- pass
-
-burnt = grok.PageTemplate("""\
-<html metal:use-macro="context/@@grilled/spices">
-</html>""")
-
class Grilled(grok.View):
pass
More information about the Checkins
mailing list