Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

z3c.tabular

Package Overview
Dependencies
Maintainers
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

z3c.tabular

Table with form support based on z3c.form and z3c.table for Zope3

  • 0.6.2
  • PyPI
  • Socket score

Maintainers
10

This package provides a table implementation including form support for Zope3 based on z3c.form and z3c.table.

.. contents::

======== Issues

  • There is still an issue in README.txt sample, the samples are using nested <form> tags. Fix the sample and use real subform templates.

======= CHANGES

0.6.2 (2012-06-19)

  • Made the pagetemplates provide macros to make it easier to replace specific contents

0.6.1 (2012-06-19)

  • Fixed package metadata (home page and author e-mail).

  • Added a default supportsCancel = False to TableBase

0.6.0 (2010-10-28)

  • Using registerType from zope.browserpage instead from zope.app.pagetemplate

  • Adjusted test output.

  • Updated test dependencies so tests run with current z3c.form versions.

  • Added doctests to long_description so they show up on PyPI.

0.5.2 (2009-10-19)

  • Fixed my bug introduced in 0.5.1.

0.5.1 (2009-10-19)

  • Added allowEdit property to SubFormTable

0.5.0 (2009-02-22)

  • Initial release.

========== Form Table

The goal of this package is to offer a modular table rendering library which includes built in support for update forms. This will allow us to adapt items rendered as table row items to forms. This could prevent to use traversable exposed forms for such items. But this is just one of the benefits. See more below.

Form support

We need to setup the form defaults first:

from z3c.form.testing import setupFormDefaults setupFormDefaults()

And load the formui confguration, which will make sure that all macros get registered correctly.

from zope.configuration import xmlconfig import zope.component import zope.viewlet import zope.component import zope.app.publisher.browser import z3c.macro import z3c.template import z3c.formui xmlconfig.XMLConfig('meta.zcml', zope.component)() xmlconfig.XMLConfig('meta.zcml', zope.viewlet)() xmlconfig.XMLConfig('meta.zcml', zope.app.publisher.browser)() xmlconfig.XMLConfig('meta.zcml', z3c.macro)() xmlconfig.XMLConfig('meta.zcml', z3c.template)() xmlconfig.XMLConfig('configure.zcml', z3c.formui)()

And load the z3c.tabular configure.zcml:

import z3c.tabular xmlconfig.XMLConfig('configure.zcml', z3c.tabular)()

Sample data setup

Let's create a sample container which we can use as our iterable context:

from zope.container import btree class Container(btree.BTreeContainer): ... """Sample container.""" ... name = u'container' container = Container()

and set a parent for the container:

root['container'] = container

and create a sample content object which we use as container item:

import zope.interface import zope.schema class IContent(zope.interface.Interface): ... """Content interface.""" ... ... title = zope.schema.TextLine(title=u'Title') ... number = zope.schema.Int(title=u'Number')

class Content(object): ... """Sample content.""" ... zope.interface.implements(IContent) ... def init(self, title, number): ... self.name = title.lower() ... self.title = title ... self.number = number

Now setup some items:

container[u'first'] = Content('First', 1) container[u'second'] = Content('Second', 2) container[u'third'] = Content('Third', 3)

FormTable setup

The FormTable offers a sub form setup for rendering items within a form. Let's first define a form for our used items:

from z3c.form import form from z3c.form import field class ContentEditForm(form.EditForm): ... fields = field.Fields(IContent)

Now we can define our FormTable including the SelectedItemColumn:

from z3c.table import column import z3c.tabular.table class ContentFormTable(z3c.tabular.table.SubFormTable): ... ... subFormClass = ContentEditForm ... ... def setUpColumns(self): ... return [ ... column.addColumn(self, column.SelectedItemColumn, ... u'selectedItem', weight=1), ... ]

And support the div form layer for our request:

from z3c.formui.interfaces import IDivFormLayer from zope.interface import alsoProvides from z3c.form.testing import TestRequest request = TestRequest() alsoProvides(request, IDivFormLayer)

Now we can render our table. As you can see the SelectedItemColumn renders a link which knows hot to select the item:

contentSubFormTable = ContentFormTable(container, request) contentSubFormTable.name = 'view.html' contentSubFormTable.update() print contentSubFormTable.render()

Name
first
second
third

Now we are ready to select an item by click on the link. We simulate this by set the relevant data in the request:

selectRequest = TestRequest(form={ ... 'subFormTable-selectedItem-0-selectedItems': 'second'}) alsoProvides(selectRequest, IDivFormLayer) selectedItemTable = ContentFormTable(container, selectRequest) selectedItemTable.name = 'view.html' selectedItemTable.update() print selectedItemTable.render()

*– required
Title *
Number *

Clicking the Edit button at the same time should hold the same result:

selectRequest = TestRequest(form={ ... 'subFormTable-selectedItem-0-selectedItems': 'second', ... 'subFormTable.buttons.edit': 'Edit'}) alsoProvides(selectRequest, IDivFormLayer) selectedItemTable = ContentFormTable(container, selectRequest) selectedItemTable.name = 'view.html' selectedItemTable.update() print selectedItemTable.render()

*– required
Title *
Number *

Unless allowEdit is False. In this case the editform won't appear.

selectRequest = TestRequest(form={ ... 'subFormTable-selectedItem-0-selectedItems': 'second', ... 'subFormTable.buttons.edit': 'Edit'}) alsoProvides(selectRequest, IDivFormLayer) selectedItemTable = ContentFormTable(container, selectRequest) selectedItemTable.name = 'view.html' selectedItemTable.allowEdit = False selectedItemTable.update() print selectedItemTable.render()

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc