Skip to content

Commit

Permalink
Some fixed for five.grok.
Browse files Browse the repository at this point in the history
  • Loading branch information
regebro committed Jul 18, 2008
1 parent 276d709 commit af44efc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
29 changes: 24 additions & 5 deletions devel/grokcore.view/src/grokcore/view/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ class Permission(Permission):
#XXX rename to GrokView
class ViewMixin(object):

def _initialize(self):
def __init__(self, context, request):
super(ViewMixin, self).__init__(context, request)
self.__name__ = self.__view_name__
self.static = component.queryAdapter(
self.request,
interface.Interface,
name=self.module_info.package_dotted_name)

name=self.module_info.package_dotted_name
)

def _update_and_render(self):
mapply(self.update, (), self.request)
if self.request.response.getStatus() in (302, 303):
Expand All @@ -49,6 +51,18 @@ def _render_template(self):
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 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.
Expand Down Expand Up @@ -86,8 +100,13 @@ def namespace(self):
return {}

def default_namespace(self):
raise NotImplementedError

namespace = {}
namespace['context'] = self.context
namespace['request'] = self.request
namespace['static'] = self.static
namespace['view'] = self
return namespace

def application_url(self, name=None):
raise NotImplementedError

Expand Down
8 changes: 3 additions & 5 deletions devel/grokcore.view/src/grokcore/view/templatereg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

from martian.error import GrokError

import grok

import grokcore.component
import grokcore.view

Expand Down Expand Up @@ -50,7 +48,7 @@ def findFilesystem(self, module_info):
template_name, extension = os.path.splitext(template_file)
extension = extension[1:] # Get rid of the leading dot.
template_factory = zope.component.queryUtility(
grok.interfaces.ITemplateFileFactory,
grokcore.view.interfaces.ITemplateFileFactory,
name=extension)

if template_factory is None:
Expand Down Expand Up @@ -129,8 +127,8 @@ def checkTemplates(self, module_info, factory, component_name,


class PageTemplateFileFactory(grokcore.component.GlobalUtility):
implements(grok.interfaces.ITemplateFileFactory)
implements(grokcore.view.interfaces.ITemplateFileFactory)
grokcore.component.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)

0 comments on commit af44efc

Please sign in to comment.