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

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Feb 23, 2015
1 parent 7beafa8 commit 8597758
Show file tree
Hide file tree
Showing 18 changed files with 265 additions and 198 deletions.
6 changes: 3 additions & 3 deletions src/plone/z3cform/converter.py
@@ -1,9 +1,9 @@
import ZPublisher.HTTPRequest
import cgi
import z3c.form.converter
import z3c.form.interfaces
import zope.publisher.browser
import ZPublisher.HTTPRequest

import z3c.form.interfaces
import z3c.form.converter

class FileUploadDataConverter(z3c.form.converter.FileUploadDataConverter):
"""Although ZPublisher's and zope.publisher's FileUpload
Expand Down
1 change: 0 additions & 1 deletion src/plone/z3cform/crud/__init__.py
@@ -1 +0,0 @@
#
50 changes: 27 additions & 23 deletions src/plone/z3cform/crud/crud.py
@@ -1,22 +1,19 @@
import sys

from ZODB.POSException import ConflictError
from zope import interface
import zope.event
import zope.lifecycleevent
import zope.publisher.browser
from plone.batching import Batch
from plone.batching.browser import BatchView
from plone.z3cform import MessageFactory as _
from plone.z3cform.widget import singlecheckboxwidget_factory
from z3c.form import button
from z3c.form import field
from z3c.form import form
import z3c.form.widget
from z3c.form.interfaces import DISPLAY_MODE, INPUT_MODE, NOVALUE
from zope import interface
from zope.browserpage import viewpagetemplatefile

from plone.batching import Batch
from plone.batching.browser import BatchView

from plone.z3cform.widget import singlecheckboxwidget_factory
from plone.z3cform import MessageFactory as _
import sys
import z3c.form.widget
import zope.event
import zope.lifecycleevent
import zope.publisher.browser


class ICrudForm(interface.Interface):
Expand Down Expand Up @@ -98,7 +95,8 @@ def get_items(self):
def add(self, data):
raise NotImplementedError

def remove(self, (id, item)):
def remove(self, xxx_todo_changeme1):
(id, item) = xxx_todo_changeme1
raise NotImplementedError

def before_update(self, item, data):
Expand All @@ -109,11 +107,11 @@ def link(self, item, field):


class CrudBatchView(BatchView):

prefix = ''

def make_link(self, pagenumber):
return "%s?%spage=%s" % (self.request.getURL(), self.prefix, pagenumber)
return "%s?%spage=%s" % (
self.request.getURL(), self.prefix, pagenumber)


class EditSubForm(form.EditForm):
Expand Down Expand Up @@ -199,7 +197,7 @@ class EditForm(form.Form):
label = _(u"Edit")
template = viewpagetemplatefile.ViewPageTemplateFile('crud-table.pt')

#exposes the edit sub form for your own derivatives
# exposes the edit sub form for your own derivatives
editsubform_factory = EditSubForm

@property
Expand All @@ -223,9 +221,9 @@ def _update_subforms(self):
@property
def batch(self):
items = self.context.get_items()
batch_size = self.context.batch_size or sys.maxint
batch_size = self.context.batch_size or sys.maxsize
page = int(self.request.get('%spage' % self.prefix, 0))
return Batch.fromPagenumber(items, batch_size, page+1)
return Batch.fromPagenumber(items, batch_size, page + 1)

def render_batch_navigation(self):
bv = CrudBatchView(self.context, self.request)
Expand Down Expand Up @@ -265,10 +263,11 @@ def handle_edit(self, action):

# If there were changes, we'll update the view widgets
# again, so that they'll actually display the changes
for widget in subform.widgets.values():
for widget in subform.widgets.values():
if widget.mode == DISPLAY_MODE:
widget.update()
zope.event.notify(z3c.form.widget.AfterWidgetUpdateEvent(widget))
zope.event.notify(
z3c.form.widget.AfterWidgetUpdateEvent(widget))
self.status = status

@button.buttonAndHandler(_('Delete'), name='delete')
Expand All @@ -288,7 +287,8 @@ def handle_delete(self, action):
self.status = _(u'Unable to remove one or more items.')
break

# We changed the amount of entries, so we update the subforms again.
# We changed the amount of entries, so we update the subforms
# again.
self._update_subforms()
else:
self.status = _(u"Please select items to delete.")
Expand All @@ -303,6 +303,7 @@ def selected_items(self):
tuples.append((subform.content_id, subform.content))
return tuples


class AddForm(form.Form):
template = viewpagetemplatefile.ViewPageTemplateFile('crud-add.pt')

Expand All @@ -327,13 +328,15 @@ def handle_add(self, action):
return
try:
item = self.context.add(data)
except zope.schema.ValidationError, e:
except zope.schema.ValidationError as e:
self.status = e
else:
zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(item))
self.status = _(u"Item added successfully.")


class NullForm(object):

def __init__(self, context, request):
self.context = context
self.request = request
Expand All @@ -345,6 +348,7 @@ def render(self):
return ''
__call__ = render


class CrudForm(AbstractCrudForm, form.Form):
template = viewpagetemplatefile.ViewPageTemplateFile('crud-master.pt')
description = u''
Expand Down
29 changes: 19 additions & 10 deletions src/plone/z3cform/fieldsets/extensible.py
@@ -1,18 +1,16 @@
from zope.interface import implements
from zope.component import getAdapters

from plone.z3cform import MessageFactory as _
from plone.z3cform.fieldsets import utils
from plone.z3cform.fieldsets.interfaces import IExtensibleForm
from plone.z3cform.fieldsets.interfaces import IFormExtender

from z3c.form.group import GroupForm
from zope.component import getAdapters
from zope.interface import implements

from plone.z3cform.fieldsets import utils

from plone.z3cform import MessageFactory as _

def order_key(adapter_tuple):
return adapter_tuple[1].order


class FormExtender(object):
"""Base class for IFormExtender adapters with convenience APIs
"""
Expand Down Expand Up @@ -41,12 +39,19 @@ def remove(self, field_name, prefix=None):

return utils.remove(self.form, field_name, prefix=prefix)

def move(self, field_name, before=None, after=None, prefix=None, relative_prefix=None):
def move(
self,
field_name,
before=None,
after=None,
prefix=None,
relative_prefix=None):
"""Move the field with the given name before or after another field.
"""

utils.move(self.form, field_name, before=before, after=after,
prefix=prefix, relative_prefix=relative_prefix)
prefix=prefix, relative_prefix=relative_prefix)


class ExtensibleForm(GroupForm):
implements(IExtensibleForm)
Expand All @@ -59,6 +64,10 @@ def update(self):
super(ExtensibleForm, self).update()

def updateFields(self):
extenders = getAdapters((self.context, self.request, self), IFormExtender)
extenders = getAdapters(
(self.context,
self.request,
self),
IFormExtender)
for name, extender in sorted(extenders, key=order_key):
extender.update()
1 change: 0 additions & 1 deletion src/plone/z3cform/fieldsets/group.py
Expand Up @@ -7,7 +7,6 @@

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

__name__ = u""
label = u""
description = u""
Expand Down
41 changes: 26 additions & 15 deletions src/plone/z3cform/fieldsets/interfaces.py
@@ -1,18 +1,20 @@
from zope.interface import Interface
from z3c.form.interfaces import IFields
from z3c.form.interfaces import IGroup
from zope import schema
from zope.interface import Interface

from z3c.form.interfaces import IFields, IGroup, IGroupForm

class IFormExtender(Interface):
"""A component that can add, modify, sort and group fields in a form.
This should be a named multi adapter from (context, request, form).
"""

order = schema.Int(title=u"Order",
description=u"Use this property to order the sorter. " +
u"Low numbers are executed before high ones.",
required=True)
order = schema.Int(
title=u"Order",
description=u"Use this property to order the sorter. " +
u"Low numbers are executed before high ones.",
required=True)

def update():
"""Modify the form in place. Supported operations include:
Expand All @@ -22,44 +24,53 @@ def update():
- modify the 'fields' property of a given group
"""


class IDescriptiveGroup(IGroup):
"""Extension to z3c.form's Group class that can separate out a name,
a label and a description.
"""

__name__ = schema.TextLine(title=u"Name of this group")

label = schema.TextLine(title=u"Fieldset title",
description=u"The __name__ will be used if this is not given",
required=False)
label = schema.TextLine(
title=u"Fieldset title",
description=u"The __name__ will be used if this is not given",
required=False)

description = schema.Text(title=u"Fieldset description",
required=False)


class IGroupFactory(Interface):
"""An object that can be used to create a z3c.form.group.Group.
"""

__name__ = schema.TextLine(title=u"Name of this group")

label = schema.TextLine(title=u"Fieldset title",
description=u"The __name__ will be used if this is not given",
required=False)
label = schema.TextLine(
title=u"Fieldset title",
description=u"The __name__ will be used if this is not given",
required=False)

description = schema.Text(title=u"Fieldset description",
required=False)

fields = schema.Object(title=u"Fields in this form", schema=IFields)


class IExtensibleForm(Interface):
"""A special version of the IGroupForm that is extensible via
IFormExtender adapters.
"""

groups = schema.List(title=u'Groups',
value_type=schema.Object(title=u"Group", schema=IGroupFactory))
groups = schema.List(
title=u'Groups',
value_type=schema.Object(
title=u"Group",
schema=IGroupFactory))

default_fieldset_label = schema.TextLine(title=u"Label of the default fieldset")
default_fieldset_label = schema.TextLine(
title=u"Label of the default fieldset")

def updateFields():
"""Called during form update to allow updating of self.fields
Expand Down
19 changes: 14 additions & 5 deletions src/plone/z3cform/fieldsets/utils.py
@@ -1,7 +1,7 @@
from plone.z3cform.fieldsets.group import GroupFactory
from z3c.form.field import Fields
from z3c.form.util import expandPrefix

from plone.z3cform.fieldsets.group import GroupFactory

def add(form, *args, **kwargs):
"""Add one or more fields. Keyword argument 'index' can be used to
Expand Down Expand Up @@ -29,8 +29,9 @@ def add(form, *args, **kwargs):
else:
field_names = source.fields.keys()
source.fields = source.fields.select(*field_names[:index]) + \
new_fields + \
source.fields.select(*field_names[index:])
new_fields + \
source.fields.select(*field_names[index:])


def remove(form, field_name, prefix=None):
"""Get rid of a field. The omitted field will be returned.
Expand All @@ -50,7 +51,14 @@ def remove(form, field_name, prefix=None):
group.fields = group.fields.omit(field_name)
return field

def move(form, field_name, before=None, after=None, prefix=None, relative_prefix=None):

def move(
form,
field_name,
before=None,
after=None,
prefix=None,
relative_prefix=None):
"""Move the field with the given name before or after another field.
"""
if prefix:
Expand Down Expand Up @@ -111,7 +119,8 @@ def move(form, field_name, before=None, after=None, prefix=None, relative_prefix
if index is None:
raise KeyError("Field %s not found" % relative)

add(form, field, group=group, index=index+offset)
add(form, field, group=group, index=index + offset)


def find_source(form, group=None):
if group is not None:
Expand Down

0 comments on commit 8597758

Please sign in to comment.