Merge branch 'bbmaster' of ssh://git.cy55.de/home/git/cybertools into bbmaster

This commit is contained in:
hplattner 2012-03-01 12:15:40 +01:00
commit d836613734
4 changed files with 30 additions and 15 deletions

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2011 Helmut Merz helmutm@cy55.de # Copyright (c) 2012 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -18,8 +18,6 @@
""" """
Implementation of report field definitions. Implementation of report field definitions.
$Id$
""" """
from datetime import datetime from datetime import datetime
@ -93,6 +91,14 @@ class Field(Component):
#return self.getValue(row) #return self.getValue(row)
class CalculatedField(Field):
def getRawValue(self, row):
return getattr(row, self.name)
# sample field
label = Field('label', u'Label', label = Field('label', u'Label',
u'A short text that identifies a row for humans.') u'A short text that identifies a row for humans.')

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de # Copyright (c) 2012 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -33,6 +33,7 @@ class BaseRow(object):
self.context = context self.context = context
self.parent = parent self.parent = parent
self.data = {} self.data = {}
self.sequenceNumber = 0
def __getattr__(self, attr): def __getattr__(self, attr):
f = self.parent.context.fields[attr] f = self.parent.context.fields[attr]
@ -54,7 +55,6 @@ class Row(BaseRow):
return getattr(obj.context, attr) return getattr(obj.context, attr)
class ResultSet(object): class ResultSet(object):
def __init__(self, context, data, rowFactory=Row, def __init__(self, context, data, rowFactory=Row,
@ -71,6 +71,8 @@ class ResultSet(object):
result = [row for row in result if self.queryCriteria.check(row)] result = [row for row in result if self.queryCriteria.check(row)]
if self.sortCriteria: if self.sortCriteria:
result.sort(key=lambda x: [f.getSortValue(x) for f in self.sortCriteria]) result.sort(key=lambda x: [f.getSortValue(x) for f in self.sortCriteria])
for idx, row in enumerate(result):
row.sequenceNumber = idx + 1
return result return result
def __iter__(self): def __iter__(self):

View file

@ -42,37 +42,43 @@
tal:define="fieldInstance python: field.getFieldInstance(view.instance); tal:define="fieldInstance python: field.getFieldInstance(view.instance);
columns fieldInstance/columnTypes; columns fieldInstance/columnTypes;
rows data/?name"> rows data/?name">
<table class="records"> <table class="records" style="width: auto">
<thead> <thead>
<tr> <tr>
<tal:header repeat="column columns"> <tal:header repeat="column columns">
<th tal:attributes="field column/name;" <th tal:attributes="class string:${column/baseField/cssClass|string:}"
tal:content="column/title">Column Title</th> tal:content="column/title">Column Title</th>
</tal:header> </tal:header>
</tr> </tr>
</thead> </thead>
<tbody tal:attributes="id string:tbody.$name"> <tbody tal:attributes="id string:tbody.$name">
<tr tal:repeat="row rows"> <tr tal:repeat="row rows">
<td tal:repeat="column columns"> <td tal:repeat="column columns"
<input type="text" tal:attributes="class string:${column/baseField/cssClass|string:}">
<input type="text" style="width: auto"
tal:define="cname column/name" tal:define="cname column/name"
tal:attributes="value row/?cname; tal:attributes="value row/?cname;
name string:$name.$cname:records;" /></td> name string:$name.$cname:records;
style string:width: ${column/baseField/width|string:auto};" /></td>
</tr> </tr>
<tal:empty condition="python: not field.cardinality <tal:empty condition="python: not field.cardinality
or field.cardinality > len(rows)"> or field.cardinality > len(rows)">
<tr> <tr>
<td tal:repeat="column columns"> <td tal:repeat="column columns"
tal:attributes="class string:${column/baseField/cssClass|string:}">
<input type="text" <input type="text"
tal:define="cname column/name" tal:define="cname column/name"
tal:attributes="name string:$name.$cname:records" /></td> tal:attributes="name string:$name.$cname:records;
style string:width: ${column/baseField/width|string:auto};" /></td>
</tr> </tr>
<tr style="display: none" <tr style="display: none"
tal:attributes="id string:$name.empty"> tal:attributes="id string:$name.empty">
<td tal:repeat="column columns"> <td tal:repeat="column columns"
<input type="text" tal:attributes="class string:${column/baseField/cssClass|string:}">
<input type="text" style="width: auto"
tal:define="cname column/name" tal:define="cname column/name"
tal:attributes="name string:$name.$cname:records" /></td> tal:attributes="name string:$name.$cname:records;
style string:width: ${column/baseField/width|string:auto};" /></td>
</tr> </tr>
</tal:empty> </tal:empty>
</tbody> </tbody>

View file

@ -46,6 +46,7 @@ class Records(Grid):
__typeInfo__ = ('records', __typeInfo__ = ('records',
FieldType('records', 'records', FieldType('records', 'records',
u'A series of records or rows.', u'A series of records or rows.',
displayRenderer='display_records',
instanceName='records',)) instanceName='records',))