This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Note

megrok.layout has been promoted to grokcore.layout and will be a part of the Grok from the upcomming Grok release on. The grokcore.layout package can already be included in your own projects in the meantime. This means this package most likely will not see any further updates.

The megrok.layout package provides a simple way to write view components which can be included into a defined layout. It turns around two main components : the Page and the Layout.

Layout

The layout is a component allowing you to design your site. Often, it’s the common structure shared between all the pages. Technically, it is a class based on the view components interface, providing a ‘render’ and ‘update’ method.

Let’s implement a simple Layout:

>>> from megrok.layout import Layout
>>> from zope.interface import Interface
>>> import grokcore.component as grok
>>> class MyLayout(Layout):
...     grok.name('mylayout')
...     grok.context(Interface)
...
...     def render(self):
...         return u"a simple layout"

We grok our component:

>>> grok_component('MyLayout', MyLayout)
True

We check it has been correctly registered:

>>> from megrok.layout import ILayout
>>> from zope.component import getMultiAdapter
>>> from zope.publisher.browser import TestRequest
>>> layout = getMultiAdapter((TestRequest(), Interface), ILayout)
>>> isinstance(layout, MyLayout)
True
>>> layout.render()
u'a simple layout'

Now let’s see how to use this Layout in a specific context using a Page.

Page

The page is the specific code that you want to control. It is based on the grokcore.View browser page implementation and therefore provides a render and update method. The render method will simply return the specific HTML code generated by the template or the render method code while __call__ will lookup for a Layout component and renders itself inside it.

First, we’ll create 2 models that will serve as exemples.

>>> class Aurochs(grok.Context):
...    description = u'Looks like a bull'
>>> class Mammoth(grok.Context):
...    description = u'Looks like an elephant'

Let’s create now a page that will display their description.

>>> from megrok.layout import Page
>>> class AnimalDisplay(Page):
...    grok.name('display')
...    grok.context(Interface)
...
...    def render(self):
...        return self.context.description

Grokking our Page will let us use it.

>>> grok_component('AnimalDisplay', AnimalDisplay)
True
>>> wooly = Mammoth()
>>> page = getMultiAdapter((wooly, TestRequest()), name='display')
>>> page.content()
u'Looks like an elephant'
>>> page()
u'a simple layout'

As we can see, the page is using the layout, on the __call__ to render. Of course, this example Layout doesn’t provide any interesting feature. Let’s create something more interesting, by using our page with the help of the ‘content’ method:

>>> class MammothLayout(Layout):
...     grok.context(Mammoth)
...
...     def render(self):
...         return u'Header. Page: %s. Footer' % self.view.content()
>>> grok_component('MammothLayout', MammothLayout)
True
>>> page()
u'Header. Page: Looks like an elephant. Footer'

Forms & Errorpages

Baseclasses for Form views (Form, AddForm, EditForm and DisplayForm) and Error views (NotFoundPage, ExceptionPage, UnauthorizedPage) are available which are all aware of Layout components like Page is.

Changelog

Note

megrok.layout has been promoted to grokcore.layout and will be a part of the Grok from the upcomming Grok release on. The grokcore.layout package can already be included in your own projects in the meantime. This means this package most likely will not see any further updates.

1.3 (2011-01-12)

  • Compatibility with grokcore.view 2.3.

1.2.0 (2010-12-16)

  • Update to use the new TemplateGrokker from grokcore.view.

1.1.0 (2010-03-03)

  • z3c.flashmessage has been dropped in favor of grokcore.message. This new package takes in charge the registration of the utilities and retains the existing API. The back-compatibility is assured.

1.0.2 (2010-02-26)

  • The existence test for the application_url site-lookup was wrongly using a “if not” statement. In a case of a container, the object is evaluated to False if it’s empty. We now use a proper “if .. is None”. [trollfot]

1.0.1 (2010-02-25)

  • Forms now inherit from UtilityView and therefore get the application_url and flash methods. Tests have been added to garanty the behavior. [trollfot]

1.0 (2010-02-25)

  • The dependencies have been heavily cleaned up. All zope.app packages have been removed. We are now running with minimal dependencies and using the latest ZTK. This release will probably not run on Grok 1.0. You will need Grok 1.1rc1 to be able to use it. [trollfot]
  • Added a component called UtilityView that provides two useful methods : application_url, flash. These methods are almost a copy of what can be found in the Grok package. The application_url is using a simple getSite hook to get the root of the application. This might be irrelevant for some applications and can be overriden. [trollfot]
  • Added a module called ‘messages’ that contains the flash messages utilities. This module is NOT grokked and must be grokked manually. This prevents conflicts with grokui.admin’s own definitions of the very same components. It also allows you to override the flash method to use something else than z3c.flashmessage and then not be bothered by useless utilities. The flash messages utilities can be registered by including the messages.zcml file in your own project or package ZCML file. [trollfot]

0.9 (2009-09-26)

  • Add default templates to form which doesn’t contain an html and body tag. [sylvain]
  • Add an AddForm, EditForm and DisplayForm, all aware of the layout component. [sylvain]

0.8 (2009-09-17)

  • Remove the CodePage, since CodeView have been removed from grokcore.view. [sylvain]

0.7 (2009-09-15)

  • Add a CodePage to be compatible with the last version of grokcore.view (higher than 1.9). This breaks compatibility with previous release. You need to change any Page using a render method to a CodePage. [sylvain]
  • The content property on a Page is no longer a property, but a method as it’s hidding exceptions. You might need to update your code to reflect that change as well. [sylvain]
  • Fix MANIFEST.in. [sylvain]

0.6 (2009-09-14)

  • switch the arguments order in calling the layout [cklinger, sylvain]
  • add the CHANGES.txt [cklinger]

0.5 (2009-07-24)

  • remove the grok dependency [cklinger trollfot]
Release History

Release History

1.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.9

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
megrok.layout-1.3.tar.gz (16.4 kB) Copy SHA256 Checksum SHA256 Source Jan 12, 2011

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting