From b60c074323ab903ab4db3699a25899824a8dab88 Mon Sep 17 00:00:00 2001 From: ale-rt Date: Tue, 21 May 2024 15:31:48 +0200 Subject: [PATCH 1/3] Move the custom html from the form template to a widget --- src/euphorie/content/browser/configure.zcml | 2 + src/euphorie/content/browser/surveygroup.py | 45 +++- .../browser/templates/surveygroup_add.pt | 204 ------------------ src/euphorie/content/widgets/configure.zcml | 8 + .../widgets/survey_source_selection.py | 103 +++++++++ .../templates/survey_source_selection.pt | 135 ++++++++++++ 6 files changed, 283 insertions(+), 214 deletions(-) delete mode 100644 src/euphorie/content/browser/templates/surveygroup_add.pt create mode 100644 src/euphorie/content/widgets/survey_source_selection.py create mode 100644 src/euphorie/content/widgets/templates/survey_source_selection.pt diff --git a/src/euphorie/content/browser/configure.zcml b/src/euphorie/content/browser/configure.zcml index 9d414e2506..b1dc0ae950 100644 --- a/src/euphorie/content/browser/configure.zcml +++ b/src/euphorie/content/browser/configure.zcml @@ -271,6 +271,8 @@ /> + + - -

This form will allow you to create a new OiRA Tool.

- -
-
- -
- How would you like to start - - - -
- - - - - - - -
- Choose a revision of the selected OiRA Tool - -
-
-
-
-
-
- - - - - - - - -
- Choose a revision of the selected OiRA Tool - -
-
-
-
- -
- ${widget/label} - * - - - - - -
-
- -
- - -
-
- diff --git a/src/euphorie/content/widgets/configure.zcml b/src/euphorie/content/widgets/configure.zcml index 6d5a089faa..60bfe5e9fd 100644 --- a/src/euphorie/content/widgets/configure.zcml +++ b/src/euphorie/content/widgets/configure.zcml @@ -22,5 +22,13 @@ + + + diff --git a/src/euphorie/content/widgets/survey_source_selection.py b/src/euphorie/content/widgets/survey_source_selection.py new file mode 100644 index 0000000000..b0de9fbccc --- /dev/null +++ b/src/euphorie/content/widgets/survey_source_selection.py @@ -0,0 +1,103 @@ +from euphorie import MessageFactory as _ +from z3c.form.interfaces import IFieldWidget +from z3c.form.interfaces import IFormLayer +from z3c.form.interfaces import IObjectWidget +from z3c.form.object import ObjectWidget +from z3c.form.widget import FieldWidget +from zope import schema +from zope.component import adapter +from zope.interface import classImplementsFirst +from zope.interface import implementer +from zope.interface import Interface +from zope.schema.vocabulary import SimpleTerm +from zope.schema.vocabulary import SimpleVocabulary + + +class ISurveySourceSchema(Interface): + source = schema.Choice( + title=_("label_source", default="How would you like to start"), + vocabulary=SimpleVocabulary( + [ + SimpleTerm( + "scratch", + title=_( + "survey_source_scratch", + default="Create a new OiRA Tool from scratch", + ), + ), + SimpleTerm( + "local", + title=_( + "survey_source_local", + default=( + "Base my new OiRA Tool " + "on an existing OiRA Tool of my organisation" + ), + ), + ), + SimpleTerm( + "other", + title=_( + "survey_source_other", + default=( + "Base my new OiRA Tool " + "on an existing OiRA Tool of another organisation" + ), + ), + ), + ] + ), + default="scratch", + ) + + country = schema.Choice( + title=_("label_choose_country", default="Choose a country"), + vocabulary=SimpleVocabulary([]), + required=False, + ) + + local_surveygroup = schema.Choice( + title=_("label_choose_surveygroup", default="Choose an OiRA Tool"), + required=False, + vocabulary=SimpleVocabulary([]), + ) + + local_revision = schema.Choice( + title=_( + "label_choose_survey", + default="Choose a revision for the selected OiRA Tool", + ), + required=False, + vocabulary=SimpleVocabulary([]), + ) + + +class ISurveySourceSelectionField(schema.interfaces.IObject): + """Interface for field that allows the user to select a source for the survey.""" + + +class SurveySourceSelectionField(schema.Object): + """A field that allows the user to select a source for the survey.""" + + def __init__(self, **kwargs): + super().__init__(schema=ISurveySourceSchema, **kwargs) + + +classImplementsFirst(SurveySourceSelectionField, ISurveySourceSelectionField) + + +class ISurveySourceSelectionWidget(IObjectWidget): + """A widget for the survey source selection field.""" + + +@implementer(ISurveySourceSelectionWidget) +class SurveySourceSelectionWidget(ObjectWidget): + klass = "survey-source-selection-widget" + css = "survey-source-selection" + + +@adapter(ISurveySourceSelectionField, IFormLayer) +@implementer(IFieldWidget) +def SurveySourceSelectionFieldWidget(field, request): + """IFieldWidget factory for IObjectWidget.""" + return FieldWidget(field, SurveySourceSelectionWidget(request)) diff --git a/src/euphorie/content/widgets/templates/survey_source_selection.pt b/src/euphorie/content/widgets/templates/survey_source_selection.pt new file mode 100644 index 0000000000..7074afb3ed --- /dev/null +++ b/src/euphorie/content/widgets/templates/survey_source_selection.pt @@ -0,0 +1,135 @@ +
+
+ How would you like to start + + + +
+ + + + + + + +
+ Choose a revision of the selected OiRA Tool + +
+
+
+
+
+
+ + + + + + + + +
+ Choose a revision of the selected OiRA Tool + +
+
+
+
+ +
From ccbc03c0e83690eb42615d82008b1704c795048f Mon Sep 17 00:00:00 2001 From: ale-rt Date: Fri, 24 May 2024 12:34:57 +0200 Subject: [PATCH 2/3] Run the tests with Plone 6.0.11.1 --- docs/changes.rst | 3 +++ requirements-6.0.txt | 2 +- versions-6.0.cfg | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index d50c4685a3..81501480e4 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -46,6 +46,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) ------------------- diff --git a/requirements-6.0.txt b/requirements-6.0.txt index a5b7efa374..2f870811b5 100644 --- a/requirements-6.0.txt +++ b/requirements-6.0.txt @@ -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 diff --git a/versions-6.0.cfg b/versions-6.0.cfg index c57af1a97f..1552d4c4f6 100644 --- a/versions-6.0.cfg +++ b/versions-6.0.cfg @@ -1,5 +1,5 @@ [buildout] -extends = https://dist.plone.org/release/6.0.10.1/versions.cfg +extends = https://dist.plone.org/release/6.0.11.1/versions.cfg [versions] NuPlone = 2.2.2 From aaec9dfd4feb058bdb31dc92a60a97007eb3b1c7 Mon Sep 17 00:00:00 2001 From: ale-rt Date: Fri, 24 May 2024 15:31:45 +0200 Subject: [PATCH 3/3] move_to_end is not available in Plone 5.2 --- src/euphorie/content/browser/surveygroup.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/euphorie/content/browser/surveygroup.py b/src/euphorie/content/browser/surveygroup.py index 56ddeaa7de..859aeedd69 100644 --- a/src/euphorie/content/browser/surveygroup.py +++ b/src/euphorie/content/browser/surveygroup.py @@ -68,7 +68,12 @@ def updateFields(self): self.fields = self.fields.omit("description", "obsolete") # Add a field with a radio widget to select a choice self.fields += Fields(ISurveySourceSelectionSchema) - self.fields.move_to_end("evaluation_algorithm") + 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()