[Checkins] SVN: five.grok/trunk/ Merge branch that uses
grokcore.view.
Lennart Regebro
regebro at gmail.com
Fri Jul 18 10:57:10 EDT 2008
Log message for revision 88516:
Merge branch that uses grokcore.view.
Changed:
U five.grok/trunk/buildout.cfg
_U five.grok/trunk/devel/
U five.grok/trunk/devel/EXTERNALS.txt
U five.grok/trunk/setup.py
U five.grok/trunk/src/five/grok/__init__.py
U five.grok/trunk/src/five/grok/components.py
U five.grok/trunk/src/five/grok/ftests/view/macros.py
U five.grok/trunk/src/five/grok/meta.py
U five.grok/trunk/src/five/grok/templatereg.py
-=-
Modified: five.grok/trunk/buildout.cfg
===================================================================
--- five.grok/trunk/buildout.cfg 2008-07-18 14:56:28 UTC (rev 88515)
+++ five.grok/trunk/buildout.cfg 2008-07-18 14:57:10 UTC (rev 88516)
@@ -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/trunk/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/trunk/devel/EXTERNALS.txt
===================================================================
--- five.grok/trunk/devel/EXTERNALS.txt 2008-07-18 14:56:28 UTC (rev 88515)
+++ five.grok/trunk/devel/EXTERNALS.txt 2008-07-18 14:57:10 UTC (rev 88516)
@@ -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/trunk/setup.py
===================================================================
--- five.grok/trunk/setup.py 2008-07-18 14:56:28 UTC (rev 88515)
+++ five.grok/trunk/setup.py 2008-07-18 14:57:10 UTC (rev 88516)
@@ -30,6 +30,7 @@
install_requires=[
'setuptools',
'grokcore.component',
+ 'grokcore.view',
],
entry_points="""
""",
Modified: five.grok/trunk/src/five/grok/__init__.py
===================================================================
--- five.grok/trunk/src/five/grok/__init__.py 2008-07-18 14:56:28 UTC (rev 88515)
+++ five.grok/trunk/src/five/grok/__init__.py 2008-07-18 14:57:10 UTC (rev 88516)
@@ -4,10 +4,10 @@
from zope.component import adapts
from grokcore.component import Adapter, MultiAdapter, GlobalUtility
-from grokcore.component.directive import context, name, provides
-from grokcore.component.decorators import subscribe
+from grokcore.component import context, name, provides, subscribe
+from grokcore.view.components import PageTemplate
-from five.grok.components import View, Model, PageTemplate, IGrokLayer, Skin
+from five.grok.components import View, Model, IGrokLayer, Skin
from five.grok.directive import require, layer, template, templatedir
# I don't know why this is necessary:
Modified: five.grok/trunk/src/five/grok/components.py
===================================================================
--- five.grok/trunk/src/five/grok/components.py 2008-07-18 14:56:28 UTC (rev 88515)
+++ five.grok/trunk/src/five/grok/components.py 2008-07-18 14:57:10 UTC (rev 88516)
@@ -17,216 +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)
-
-
-class BaseTemplate(object):
- """Any sort of page template"""
-
- interface.implements(interfaces.ITemplate)
-
- __grok_name__ = ''
- __grok_location__ = ''
-
- def __repr__(self):
- return '<%s template in %s>' % (self.__grok_name__,
- self.__grok_location__)
-
- def _annotateGrokInfo(self, name, location):
- self.__grok_name__ = name
- self.__grok_location__ = location
-
- def _initFactory(self, factory):
- pass
-
-class GrokTemplate(BaseTemplate):
- """A slightly more advanced page template
-
- This provides most of what a page template needs and is a good base for
- writing your own page template"""
-
- def __init__(self, string=None, filename=None, _prefix=None):
-
- # __grok_module__ is needed to make defined_locally() return True for
- # inline templates
- # XXX unfortunately using caller_module means that care must be taken
- # when GrokTemplate is subclassed. You can not do a super().__init__
- # for example.
- self.__grok_module__ = martian.util.caller_module()
-
- if not (string is None) ^ (filename is None):
- raise AssertionError(
- "You must pass in template or filename, but not both.")
-
- if string:
- self.setFromString(string)
- else:
- if _prefix is None:
- module = sys.modules[self.__grok_module__]
- _prefix = os.path.dirname(module.__file__)
- self.setFromFilename(filename, _prefix)
-
- def __repr__(self):
- return '<%s template in %s>' % (self.__grok_name__,
- self.__grok_location__)
-
- def _annotateGrokInfo(self, name, location):
- self.__grok_name__ = name
- self.__grok_location__ = location
-
- def _initFactory(self, factory):
- pass
-
- def namespace(self, view):
- # By default use the namespaces that are defined as the
- # default by the view implementation.
- return view.default_namespace()
-
- def getNamespace(self, view):
- namespace = self.namespace(view)
- namespace.update(view.namespace())
- return namespace
-
-class TrustedPageTemplate(TrustedAppPT, pagetemplate.PageTemplate):
+from grokcore.view.components import ViewMixin
+class View(ViewMixin, BrowserPage, Acquisition.Implicit):
pass
-class TrustedFilePageTemplate(TrustedAppPT, pagetemplatefile.PageTemplateFile):
- pass
-
-class PageTemplate(GrokTemplate):
-
- def setFromString(self, string):
- zpt = TrustedPageTemplate()
- if martian.util.not_unicode_or_ascii(string):
- raise ValueError("Invalid page template. Page templates must be "
- "unicode or ASCII.")
- zpt.write(string)
- self._template = zpt
-
- def setFromFilename(self, filename, _prefix=None):
- self._template = TrustedFilePageTemplate(filename, _prefix)
-
- def _initFactory(self, factory):
- factory.macros = self._template.macros
-
- def render(self, view):
- namespace = self.getNamespace(view)
- template = self._template
- namespace.update(template.pt_getContext())
- return template.pt_render(namespace)
-
class IGrokLayer(interface.Interface):
pass
Modified: five.grok/trunk/src/five/grok/ftests/view/macros.py
===================================================================
--- five.grok/trunk/src/five/grok/ftests/view/macros.py 2008-07-18 14:56:28 UTC (rev 88515)
+++ five.grok/trunk/src/five/grok/ftests/view/macros.py 2008-07-18 14:57:10 UTC (rev 88516)
@@ -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
Modified: five.grok/trunk/src/five/grok/meta.py
===================================================================
--- five.grok/trunk/src/five/grok/meta.py 2008-07-18 14:56:28 UTC (rev 88515)
+++ five.grok/trunk/src/five/grok/meta.py 2008-07-18 14:57:10 UTC (rev 88516)
@@ -112,9 +112,10 @@
def grok(self, name, module, module_info, config, **kw):
module.__grok_templates__ = templatereg.TemplateRegistry()
return True
-
+
+import grokcore.view
class ModulePageTemplateGrokker(martian.InstanceGrokker):
- martian.component(grok.components.BaseTemplate)
+ martian.component(grokcore.view.components.BaseTemplate)
# this needs to happen before any other grokkers execute that actually
# use the templates
martian.priority(1000)
Modified: five.grok/trunk/src/five/grok/templatereg.py
===================================================================
--- five.grok/trunk/src/five/grok/templatereg.py 2008-07-18 14:56:28 UTC (rev 88515)
+++ five.grok/trunk/src/five/grok/templatereg.py 2008-07-18 14:57:10 UTC (rev 88516)
@@ -122,10 +122,11 @@
"'render' method." %
(component_name.title(), factory), factory)
+import grokcore.view
class PageTemplateFileFactory(grok.GlobalUtility):
grok.implements(grok.interfaces.ITemplateFileFactory)
grok.name('pt')
def __call__(self, filename, _prefix=None):
- return grok.components.PageTemplate(filename=filename, _prefix=_prefix)
+ return grokcore.view.components.PageTemplate(filename=filename, _prefix=_prefix)
More information about the Checkins
mailing list