Skip to content

Commit

Permalink
grokcore.layout should not depend on grokcore.formlib. Move the compo…
Browse files Browse the repository at this point in the history
…nents that mix these all up to grok
  • Loading branch information
janwijbrand committed May 1, 2012
1 parent f1c491c commit cea06cc
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 84 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
1.5 (unreleased)
----------------

- Move the layout-aware form components to the grok package where the
dependency with grokcore.formib can be mixed in.

- Add a directive ``layout`` to select a different type of layout. A layout
type is defined on a ``Layout`` component with the help of the
``grokcore.component.provides`` directive. It defaults to ``ILayout``
Expand Down
4 changes: 1 addition & 3 deletions src/grokcore/layout/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-

from grokcore.layout.interfaces import ILayout, IPage
from grokcore.layout.components import Layout, layout, Page, FormPage
from grokcore.layout.components import AddFormPage, EditFormPage, DisplayFormPage
from grokcore.layout.components import Layout, layout, Page
from grokcore.layout.components import UnauthorizedPage, NotFoundPage
from grokcore.layout.components import ExceptionPage


from grokcore.layout.interfaces import IGrokcoreLayoutAPI
__all__ = list(IGrokcoreLayoutAPI)
62 changes: 0 additions & 62 deletions src/grokcore/layout/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import martian
import grokcore.component as grok
import grokcore.formlib
import grokcore.view
import zope.component
import zope.errorview.browser
Expand Down Expand Up @@ -100,27 +99,6 @@ def content(self):
return mapply(self.render, (), self.request)


class LayoutAwareFormPage(LayoutAware):
"""A mixin to make form aware of layouts.
"""
def __call__(self):
"""Calls update and returns the layout template which calls render.
"""
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
# update_form() is what make a layout-aware form different from
# 'regular" layout-aware component.
self.update_form()
if self.request.response.getStatus() in (302, 303):
return
self.layout = zope.component.getMultiAdapter(
(self.request, self.context), ILayout)
return self.layout(self)


class Page(LayoutAware, grokcore.view.View):
"""A view class.
"""
Expand Down Expand Up @@ -153,43 +131,3 @@ class UnauthorizedPage(
):
grok.context(zope.security.interfaces.IUnauthorized)
grok.baseclass()


# Default forms for form without the html and body tags
default_form_template = grokcore.view.PageTemplateFile(
os.path.join('templates', 'default_edit_form.pt'))
default_form_template.__grok_name__ = 'default_edit_form'

default_display_template = grokcore.view.PageTemplateFile(
os.path.join('templates', 'default_display_form.pt'))
default_display_template.__grok_name__ = 'default_display_form'

grokcore.view.templatedir('templates')


class FormPage(LayoutAwareFormPage, grokcore.formlib.Form):
"""A form base class.
"""
grok.baseclass()
template = default_form_template


class AddFormPage(LayoutAwareFormPage, grokcore.formlib.AddForm):
"""Base add form.
"""
grok.baseclass()
template = default_form_template


class EditFormPage(LayoutAwareFormPage, grokcore.formlib.EditForm):
"""Base edit form.
"""
grok.baseclass()
template = default_form_template


class DisplayFormPage(LayoutAwareFormPage, grokcore.formlib.DisplayForm):
"""Base display form.
"""
grok.baseclass()
template = default_display_template
7 changes: 2 additions & 5 deletions src/grokcore/layout/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:grok="http://namespaces.zope.org/grok">

xmlns="http://namespaces.zope.org/zope"
xmlns:grok="http://namespaces.zope.org/grok">
<include package="grokcore.layout" file="meta.zcml" />
<include package="grokcore.view" />
<include package="grokcore.formlib" />

</configure>
8 changes: 0 additions & 8 deletions src/grokcore/layout/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ class IBaseClasses(Interface):

Layout = Attribute("Base class for layout.")

FormPage = Attribute("Base class for form page.")

AddFormPage = Attribute("Base class for add form page.")

EditFormPage = Attribute("Base class for edit form page.")

DisplayFormPage = Attribute("Base class for diplay form layout.")

UnauthorizedPage = Attribute("Base class for unauthorized page.")

NotFoundPage = Attribute("Base class for not found page.")
Expand Down
8 changes: 2 additions & 6 deletions src/grokcore/layout/meta.zcml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:grok="http://namespaces.zope.org/grok">

xmlns="http://namespaces.zope.org/zope"
xmlns:grok="http://namespaces.zope.org/grok">
<include package="grokcore.component" file="meta.zcml" />
<include package="grokcore.security" file="meta.zcml" />
<include package="grokcore.view" file="meta-minimal.zcml" />
<include package="grokcore.formlib" file="meta.zcml" />

<grok:grok package=".meta" />

</configure>

0 comments on commit cea06cc

Please sign in to comment.