Skip to content
This repository has been archived by the owner on Apr 9, 2019. It is now read-only.

Commit

Permalink
Feature: take group class from parent-form if given. If not given it …
Browse files Browse the repository at this point in the history
…uses the default class.
  • Loading branch information
jensens committed Jan 22, 2015
1 parent 9388b0d commit b5cf1cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -4,6 +4,10 @@ Changelog
0.8.1 (unreleased)
------------------

- Feature: take group class from parent-form if given. If not given it uses
the default class.
[jensens]

- Added Italian translation
[giacomos]

Expand Down
27 changes: 14 additions & 13 deletions src/plone/z3cform/fieldsets/group.py
@@ -1,12 +1,12 @@
from zope.interface import implements

from plone.z3cform.fieldsets.interfaces import IGroupFactory
# -*- coding: utf-8 -*-
from plone.z3cform.fieldsets.interfaces import IDescriptiveGroup

from plone.z3cform.fieldsets.interfaces import IGroupFactory
from z3c.form import group
from zope.interface import implementer


@implementer(IDescriptiveGroup)
class Group(group.Group):
implements(IDescriptiveGroup)

__name__ = u""
label = u""
Expand All @@ -16,20 +16,21 @@ def getContent(self):
# Default to sharing content with parent
return self.__parent__.getContent()


@implementer(IGroupFactory)
class GroupFactory(object):
implements(IGroupFactory)

def __init__(self, __name__, fields, label=None, description=None):
self.__name__ = __name__
self.fields = fields

self.label = label or __name__
self.description = description

def __call__(self, context, request, parentForm):
g = Group(context, request, parentForm)
g.__name__ = self.__name__
g.label = self.label
g.description = self.description
g.fields = self.fields
return g
groupclass = getattr(parentForm, 'group_class', Group)
group = groupclass(context, request, parentForm)
group.__name__ = self.__name__
group.label = self.label
group.description = self.description
group.fields = self.fields
return group

0 comments on commit b5cf1cd

Please sign in to comment.