Skip to content

Commit

Permalink
update test and buildout
Browse files Browse the repository at this point in the history
  • Loading branch information
janwijbrand committed May 14, 2014
2 parents 83827ec + 4b262bc commit 29d7989
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ Changes
2.9 (unreleased)
----------------

- Make possible to disable the template warning with the help of the
``GROK_DISABLE_TEMPLATE_WARNING`` environment variable.

- The ``skin`` option of ``grokcore.view.util.url`` now accepts
strings that will be used as skin name as possible alternative to a
skin interface.

- The ``skin`` directive can now be used on interfaces that inherits
only from ``IRequest`` instead of ``IBrowserRequest``.

2.8 (2012-12-11)
----------------

Expand Down
8 changes: 4 additions & 4 deletions src/grokcore/view/meta/skin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


from zope.interface.interface import InterfaceClass
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.publisher.interfaces import IRequest
from zope.publisher.interfaces.browser import IBrowserSkinType

import martian
Expand All @@ -36,11 +36,11 @@ def grok(self, name, interface, module_info, config, **kw):
# The skin directive is not actually used on the found interface.
return False

if not interface.extends(IBrowserRequest):
# For layers it is required to extend IBrowserRequest.
if not interface.extends(IRequest):
# For layers it is required to extend IRequest.
raise GrokError(
"The grok.skin() directive is used on interface %r. "
"However, %r does not extend IBrowserRequest which is "
"However, %r does not extend IRequest which is "
"required for interfaces that are used as layers and are to "
"be registered as a skin."
% (interface.__identifier__, interface.__identifier__),
Expand Down
6 changes: 4 additions & 2 deletions src/grokcore/view/meta/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
##############################################################################
"""Grokkers for templates."""
import sys
import os
import martian

from grokcore.view import components
from grokcore.view import templatereg


class ModulePageTemplateGrokker(martian.InstanceGrokker):
martian.component(components.BaseTemplate)
# this needs to happen before any other grokkers execute that actually
Expand Down Expand Up @@ -60,7 +62,8 @@ class UnassociatedTemplatesGrokker(martian.GlobalGrokker):
martian.priority(-1001)
# XXX: The action should be registered only once, not for each module.
# There should be a way to register the action without a module grokker...
_action_registered = False
_action_registered = os.environ.get(
'GROK_DISABLE_TEMPLATE_WARNING', 'no').lower() in ('yes', 'on', 'true')

def grok(self, name, module, module_info, config, **kw):
if not self._action_registered:
Expand All @@ -74,4 +77,3 @@ def grok(self, name, module, module_info, config, **kw):
order=sys.maxint
)
return True

18 changes: 10 additions & 8 deletions src/grokcore/view/templatereg.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def clear(self):
def register_inline_template(self, module_info, template_name, template):
# verify no file template got registered with the same name
try:
existing_template = file_template_registry.lookup(
module_info, template_name)
file_template_registry.lookup(module_info, template_name)
except TemplateLookupError:
pass
else:
Expand Down Expand Up @@ -147,7 +146,7 @@ def _register_template_file(self, module_info, template_path):
(template_name, module_info.dotted_name,
template_dir), None)

extension = extension[1:] # Get rid of the leading dot.
extension = extension[1:] # Get rid of the leading dot.

template_factory = zope.component.queryUtility(
grokcore.view.interfaces.ITemplateFileFactory,
Expand Down Expand Up @@ -210,13 +209,16 @@ def get_template_dir(self, module_info):
inline_template_registry = InlineTemplateRegistry()
file_template_registry = FileTemplateRegistry()


def register_inline_template(module_info, template_name, template):
return inline_template_registry.register_inline_template(
module_info, template_name, template)


def register_directory(module_info):
return file_template_registry.register_directory(module_info)


def _clear():
"""Remove the registries (for use by tests)."""
inline_template_registry.clear()
Expand All @@ -231,6 +233,7 @@ def _clear():
addCleanUp(_clear)
del addCleanUp


def lookup(module_info, template_name, mark_as_associated=False):
try:
return file_template_registry.lookup(
Expand All @@ -239,10 +242,11 @@ def lookup(module_info, template_name, mark_as_associated=False):
try:
return inline_template_registry.lookup(
module_info, template_name, mark_as_associated)
except TemplateLookupError, e2:
except TemplateLookupError:
# re-raise first error again
raise e


def check_unassociated():
unassociated = inline_template_registry.unassociated()
if unassociated:
Expand All @@ -256,7 +260,7 @@ def check_unassociated():
for template_name in unassociated:
msg = (
"Found the following unassociated template "
"after configuration: %s" % (
"after configuration: %s" % (
template_name))
warnings.warn(msg, UserWarning, 1)

Expand Down Expand Up @@ -324,7 +328,7 @@ def associate_template(module_info, factory, component_name,
(template_name, component_name.title(), factory), factory)

# Check for render or error.
if has_no_render(factory):
if has_no_render(factory):
raise GrokError(
"%s %r has no associated template or 'render' method." %
(component_name.title(), factory), factory)
Expand Down Expand Up @@ -352,5 +356,3 @@ class PageTemplateFileFactory(grokcore.component.GlobalUtility):

def __call__(self, filename, _prefix=None):
return PageTemplate(filename=filename, _prefix=_prefix)


0 comments on commit 29d7989

Please sign in to comment.