Skip to content

Commit

Permalink
Merge pull request #745 from euphorie/better-z3c-form-support
Browse files Browse the repository at this point in the history
Move the custom html from the form template to a widget
  • Loading branch information
ale-rt committed May 27, 2024
2 parents 28c5357 + aaec9df commit 36c0c34
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 216 deletions.
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Changelog
- Show organisation logo on training certificate
Ref: scrum-2142

- Run the tests with Plone 6.0.11.1
[ale-rt]


16.1.2 (2024-03-20)
-------------------
Expand Down
2 changes: 1 addition & 1 deletion requirements-6.0.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-r https://dist.plone.org/release/6.0.10.1/requirements.txt
-r https://dist.plone.org/release/6.0.11.1/requirements.txt
2 changes: 2 additions & 0 deletions src/euphorie/content/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@
/>
</class>

<adapter factory=".surveygroup.SurveySourceSelectionAdaptedContext" />

<browser:page
name="unpublish"
for="euphorie.content.surveygroup.ISurveyGroup"
Expand Down
50 changes: 40 additions & 10 deletions src/euphorie/content/browser/surveygroup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from ..surveygroup import ISurveyGroup
from Acquisition import aq_inner
from Acquisition import aq_parent
from euphorie.content import MessageFactory as _
from euphorie.content.interfaces import SurveyUnpublishEvent
from euphorie.content.survey import ISurvey
from euphorie.content.widgets.survey_source_selection import SurveySourceSelectionField
from OFS.event import ObjectClonedEvent
from plone import api
from plone.dexterity.browser.add import DefaultAddForm
Expand All @@ -12,11 +12,14 @@
from plone.uuid.handlers import addAttributeUUID
from Products.CMFCore.interfaces import ISiteRoot
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from urllib.parse import urlencode
from z3c.form.field import Fields
from ZODB.POSException import ConflictError
from zope.component import adapter
from zope.component import getUtility
from zope.event import notify
from zope.interface import implementer
from zope.interface import Interface
from zope.lifecycleevent import ObjectCopiedEvent

import datetime
Expand All @@ -36,17 +39,41 @@ def surveys(self):
return templates


class ISurveySourceSelectionSchema(Interface):
source_selection = SurveySourceSelectionField(
title=_("label_source_selection", default="Choose a source"),
required=False,
)


@implementer(ISurveySourceSelectionSchema)
@adapter(Interface)
class SurveySourceSelectionAdaptedContext:
def __init__(self, context):
pass


class AddForm(DefaultAddForm):
"""Custom add form for :obj:`Survey` instances.
"""This add form allows you to create a new OiRA Tool from a template"""

This add form adds a the :obj:`ITemplateSchema` schema, which allows
users to pick a template survey to use as a basis for the new
survey.
"""
description = _(
"intro_add_surveygroup",
default="This form will allow you to create a new OiRA Tool.",
)

portal_type = "euphorie.surveygroup"
schema = ISurveyGroup
template = ViewPageTemplateFile("templates/surveygroup_add.pt")

def updateFields(self):
super().updateFields()
self.fields = self.fields.omit("description", "obsolete")
# Add a field with a radio widget to select a choice
self.fields += Fields(ISurveySourceSelectionSchema)
try:
self.fields.move_to_end("evaluation_algorithm")
except AttributeError:
self.fields = self.fields.omit("evaluation_algorithm") + self.fields.select(
"evaluation_algorithm"
)

def update(self):
super().update()
Expand Down Expand Up @@ -164,7 +191,10 @@ def copyTemplate(self, source, target):
source_algorithm = aq_parent(source).evaluation_algorithm
target_algorithm = self.request.form.get(
"form.widgets.evaluation_algorithm", [source_algorithm]
).pop()
)
if not isinstance(target_algorithm, str):
target_algorithm = target_algorithm.pop()

target.evaluation_algorithm = target_algorithm
target._setObject(copy.id, copy)
if source_algorithm != target_algorithm:
Expand Down
204 changes: 0 additions & 204 deletions src/euphorie/content/browser/templates/surveygroup_add.pt

This file was deleted.

8 changes: 8 additions & 0 deletions src/euphorie/content/widgets/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@
</configure>

<adapter factory=".password.PasswordWithConfirmationValidator" />
<adapter factory=".survey_source_selection.SurveySourceSelectionFieldWidget" />

<z3c:widgetTemplate
widget=".survey_source_selection.ISurveySourceSelectionWidget"
template="templates/survey_source_selection.pt"
layer="plonetheme.nuplone.z3cform.interfaces.INuPloneFormLayer"
mode="input"
/>

</configure>
Loading

0 comments on commit 36c0c34

Please sign in to comment.