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$)
 | 
			
		||||
 | 
			
		||||
  >>> from cybertools.composer.schema.schema import Schema
 | 
			
		||||
  >>> from cybertools.composer.schema.field import Field
 | 
			
		||||
  >>> from cybertools.composer.schema import Schema
 | 
			
		||||
  >>> from cybertools.composer.schema import Field
 | 
			
		||||
 | 
			
		||||
We start with setting up a schema with fields.
 | 
			
		||||
 | 
			
		||||
  >>> serviceSchema = Schema()
 | 
			
		||||
  >>> serviceSchema.components.append(Field(u'title'))
 | 
			
		||||
  >>> serviceSchema.components.append(Field(u'description'))
 | 
			
		||||
  >>> serviceSchema.components.append(Field(u'start'))
 | 
			
		||||
  >>> serviceSchema.components.append(Field(u'end'))
 | 
			
		||||
  >>> serviceSchema.components.append(Field(u'capacity'))
 | 
			
		||||
  >>> serviceSchema = Schema(
 | 
			
		||||
  ...     Field(u'title', renderFactory=None),
 | 
			
		||||
  ...     Field(u'description'),
 | 
			
		||||
  ...     Field(u'start'),
 | 
			
		||||
  ...     Field(u'end'),
 | 
			
		||||
  ...     Field(u'capacity'),
 | 
			
		||||
  ... )
 | 
			
		||||
 | 
			
		||||
For using a schema we need some class that we can use for creating
 | 
			
		||||
objects.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,6 @@
 | 
			
		|||
"""
 | 
			
		||||
$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):
 | 
			
		||||
 | 
			
		||||
    def __init__(self, name, title=None, **kw):
 | 
			
		||||
    def __init__(self, name, title=None, renderFactory=None, **kw):
 | 
			
		||||
        assert name
 | 
			
		||||
        self.name = self.__name__ = name
 | 
			
		||||
        title = title is None and name or title
 | 
			
		||||
        self.renderFactory = renderFactory  # use for rendering field content
 | 
			
		||||
        super(Field, self).__init__(title, __name__=name, **kw)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,6 +33,7 @@ class Editor(Instance):
 | 
			
		|||
 | 
			
		||||
    def applyTemplate(self, data={}, *args, **kw):
 | 
			
		||||
        for c in self.template.components:
 | 
			
		||||
            # TODO: implement the real stuff
 | 
			
		||||
            # save data (if available) in context
 | 
			
		||||
            # build sequence of fields with data from context
 | 
			
		||||
            # or directly use request...
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,7 +24,7 @@
 | 
			
		|||
          <tal:items repeat="row result/rows">
 | 
			
		||||
            <tal:item define="class python: repeat['row'].odd() and 'even' or 'odd'">
 | 
			
		||||
              <tr tal:attributes="class class">
 | 
			
		||||
                <td valign="top"
 | 
			
		||||
                <td valign="top" style="white-space: normal"
 | 
			
		||||
                    tal:repeat="cell row/cells">
 | 
			
		||||
                  <a href="#"
 | 
			
		||||
                     tal:omit-tag="not:cell/url"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -43,7 +43,7 @@ class DetailView(BaseView):
 | 
			
		|||
 | 
			
		||||
    @Lazy
 | 
			
		||||
    def resultSet(self):
 | 
			
		||||
        result = ResultSet()
 | 
			
		||||
        result = ResultSet(self.context)
 | 
			
		||||
        return result
 | 
			
		||||
 | 
			
		||||
    @Lazy
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,9 +44,12 @@ class Cell(object):
 | 
			
		|||
 | 
			
		||||
    @property
 | 
			
		||||
    def text(self):
 | 
			
		||||
        if isinstance(self.value, unicode):
 | 
			
		||||
            return self.value
 | 
			
		||||
        return unicode(str(self.value))
 | 
			
		||||
        value = self.value
 | 
			
		||||
        if value:
 | 
			
		||||
            if isinstance(value, unicode):
 | 
			
		||||
                return value
 | 
			
		||||
            return unicode(str(value))
 | 
			
		||||
        return u''
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def token(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -55,16 +58,7 @@ class Cell(object):
 | 
			
		|||
    def sortKey(self):
 | 
			
		||||
        return self.value
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    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 ''
 | 
			
		||||
    url = urlTitle = u''
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Row(object):
 | 
			
		||||
| 
						 | 
				
			
			@ -82,7 +76,8 @@ class Row(object):
 | 
			
		|||
    @property
 | 
			
		||||
    def cells(self):
 | 
			
		||||
        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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue