allow definition of field groups that may be used for controlling layout of records fields

This commit is contained in:
Helmut Merz 2014-09-20 11:16:54 +02:00
parent 249d507a72
commit 6e1333076b
3 changed files with 33 additions and 5 deletions

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de # Copyright (c) 2014 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
@ -41,6 +41,13 @@ from cybertools.composer.schema.schema import formErrors
from cybertools.util.format import toStr, toUnicode from cybertools.util.format import toStr, toUnicode
class FieldGroup(object):
def __init__(self, name, label):
self.name = name
self.label = label
class Field(Component): class Field(Component):
implements(IField) implements(IField)

View file

@ -42,7 +42,30 @@ class GridFieldInstance(ListFieldInstance):
@Lazy @Lazy
def columnTypes(self): def columnTypes(self):
return [createField(t) for t in self.context.column_types] fields = [createField(t) for t in self.context.column_types]
for f in fields:
f.linkedFields = [createField(sf)
for sf in getattr(f.baseField, 'linkedFields', [])]
return fields
#@Lazy
def columnTypesForLayout(self):
result = []
groups = {}
for f in self.columnTypes:
group = getattr(f.baseField, 'group', None)
if group is None:
result.append(dict(name=f.name,
label=(f.description or f.title), fields=[f]))
else:
g = groups.get(group.name)
if g is None:
g = dict(name=group.name, label=group.label, fields=[f])
groups[group.name] = g
result.append(g)
else:
g['fields'].append(f)
return result
@Lazy @Lazy
def columnFieldInstances(self): def columnFieldInstances(self):

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de # Copyright (c) 2014 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
@ -19,8 +19,6 @@
""" """
Basic classes for schemas, i.e. sets of fields that may be used for creating Basic classes for schemas, i.e. sets of fields that may be used for creating
editing forms or display views for objects. editing forms or display views for objects.
$Id$
""" """
from zope.interface import implements from zope.interface import implements