more on cybertools.reporter: control via the field's renderFactory
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1760 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
5c1a1a3544
commit
7f194965a1
8 changed files with 27 additions and 26 deletions
|
@ -4,17 +4,18 @@ Schema and Field Management
|
||||||
|
|
||||||
($Id$)
|
($Id$)
|
||||||
|
|
||||||
>>> from cybertools.composer.schema.schema import Schema
|
>>> from cybertools.composer.schema import Schema
|
||||||
>>> from cybertools.composer.schema.field import Field
|
>>> from cybertools.composer.schema import Field
|
||||||
|
|
||||||
We start with setting up a schema with fields.
|
We start with setting up a schema with fields.
|
||||||
|
|
||||||
>>> serviceSchema = Schema()
|
>>> serviceSchema = Schema(
|
||||||
>>> serviceSchema.components.append(Field(u'title'))
|
... Field(u'title', renderFactory=None),
|
||||||
>>> serviceSchema.components.append(Field(u'description'))
|
... Field(u'description'),
|
||||||
>>> serviceSchema.components.append(Field(u'start'))
|
... Field(u'start'),
|
||||||
>>> serviceSchema.components.append(Field(u'end'))
|
... Field(u'end'),
|
||||||
>>> serviceSchema.components.append(Field(u'capacity'))
|
... Field(u'capacity'),
|
||||||
|
... )
|
||||||
|
|
||||||
For using a schema we need some class that we can use for creating
|
For using a schema we need some class that we can use for creating
|
||||||
objects.
|
objects.
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
"""
|
"""
|
||||||
$Id$
|
$Id$
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from cybertools.composer.schema.schema import Schema
|
||||||
|
from cybertools.composer.schema.field import Field
|
||||||
|
|
|
@ -31,9 +31,10 @@ from cybertools.composer.base import Template
|
||||||
|
|
||||||
class Field(Component, schema.Field):
|
class Field(Component, schema.Field):
|
||||||
|
|
||||||
def __init__(self, name, title=None, **kw):
|
def __init__(self, name, title=None, renderFactory=None, **kw):
|
||||||
assert name
|
assert name
|
||||||
self.name = self.__name__ = name
|
self.name = self.__name__ = name
|
||||||
title = title is None and name or title
|
title = title is None and name or title
|
||||||
|
self.renderFactory = renderFactory # use for rendering field content
|
||||||
super(Field, self).__init__(title, __name__=name, **kw)
|
super(Field, self).__init__(title, __name__=name, **kw)
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ class Editor(Instance):
|
||||||
|
|
||||||
def applyTemplate(self, data={}, *args, **kw):
|
def applyTemplate(self, data={}, *args, **kw):
|
||||||
for c in self.template.components:
|
for c in self.template.components:
|
||||||
|
# TODO: implement the real stuff
|
||||||
# save data (if available) in context
|
# save data (if available) in context
|
||||||
# build sequence of fields with data from context
|
# build sequence of fields with data from context
|
||||||
# or directly use request...
|
# or directly use request...
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<tal:items repeat="row result/rows">
|
<tal:items repeat="row result/rows">
|
||||||
<tal:item define="class python: repeat['row'].odd() and 'even' or 'odd'">
|
<tal:item define="class python: repeat['row'].odd() and 'even' or 'odd'">
|
||||||
<tr tal:attributes="class class">
|
<tr tal:attributes="class class">
|
||||||
<td valign="top"
|
<td valign="top" style="white-space: normal"
|
||||||
tal:repeat="cell row/cells">
|
tal:repeat="cell row/cells">
|
||||||
<a href="#"
|
<a href="#"
|
||||||
tal:omit-tag="not:cell/url"
|
tal:omit-tag="not:cell/url"
|
||||||
|
|
|
@ -43,7 +43,7 @@ class DetailView(BaseView):
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def resultSet(self):
|
def resultSet(self):
|
||||||
result = ResultSet()
|
result = ResultSet(self.context)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
|
|
|
@ -44,9 +44,12 @@ class Cell(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self):
|
def text(self):
|
||||||
if isinstance(self.value, unicode):
|
value = self.value
|
||||||
return self.value
|
if value:
|
||||||
return unicode(str(self.value))
|
if isinstance(value, unicode):
|
||||||
|
return value
|
||||||
|
return unicode(str(value))
|
||||||
|
return u''
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def token(self):
|
def token(self):
|
||||||
|
@ -55,16 +58,7 @@ class Cell(object):
|
||||||
def sortKey(self):
|
def sortKey(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
@property
|
url = urlTitle = u''
|
||||||
def url(self):
|
|
||||||
view = self.row.resultSet.view
|
|
||||||
if view is None:
|
|
||||||
return ''
|
|
||||||
return IAbsoluteURL(self.row, view.request, name=field.__name__)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def urlTitle(self):
|
|
||||||
return ''
|
|
||||||
|
|
||||||
|
|
||||||
class Row(object):
|
class Row(object):
|
||||||
|
@ -82,7 +76,8 @@ class Row(object):
|
||||||
@property
|
@property
|
||||||
def cells(self):
|
def cells(self):
|
||||||
for f in self.resultSet.schema.fields:
|
for f in self.resultSet.schema.fields:
|
||||||
yield Cell(f, getattr(self.context, f.name), self)
|
rf = f.renderFactory or Cell
|
||||||
|
yield rf(f, getattr(self.context, f.name), self)
|
||||||
|
|
||||||
|
|
||||||
class ResultSet(object):
|
class ResultSet(object):
|
||||||
|
|
Loading…
Add table
Reference in a new issue