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

Commit

Permalink
Merge pull request #5 from zopefoundation/group-from-parent
Browse files Browse the repository at this point in the history
Feature: take group class from parent-form if given. If not given it uses the default class.
  • Loading branch information
thet committed Jan 22, 2015
2 parents f77782e + 6632253 commit 7da075e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
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 Ukrainian translation
[kroman0]

Expand Down
27 changes: 14 additions & 13 deletions src/plone/z3cform/fieldsets/group.py
Original file line number Diff line number Diff line change
@@ -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 7da075e

Please sign in to comment.