From b055b848698b7a832bbff1d460ba9f7d9aae74a4 Mon Sep 17 00:00:00 2001 From: ale-rt Date: Wed, 22 May 2024 09:47:31 +0200 Subject: [PATCH 1/3] We do not have a customized add form for a survey group anymore --- src/osha/oira/content/browser/configure.zcml | 8 -- src/osha/oira/content/browser/surveygroup.py | 10 -- .../browser/templates/surveygroup_add.pt | 108 ------------------ 3 files changed, 126 deletions(-) delete mode 100644 src/osha/oira/content/browser/templates/surveygroup_add.pt diff --git a/src/osha/oira/content/browser/configure.zcml b/src/osha/oira/content/browser/configure.zcml index f6bbc3f20..bf9b5006e 100644 --- a/src/osha/oira/content/browser/configure.zcml +++ b/src/osha/oira/content/browser/configure.zcml @@ -54,14 +54,6 @@ /> - - - -

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} * - - This method involves risk assessment by Severity x Exposure x Probability, whereas these have to be understood as follows; Severity of injury linked to hazard - Exposure (Frequency) to the hazard - Probability of the hazard occuring when exposed - - -
- - This method involves risk assessment by Severity x Exposure, whereas these have to be understood as follows; Severity of injury linked to hazard - Exposure (Frequency) to the hazard - -
- - - -
-
- -
- - -
-
- From 02ca5b2cdc5bdb557bcffeadb222287ccf90ea08 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 31 Jan 2025 12:10:31 +0100 Subject: [PATCH 2/3] Remove no longer needed template for sector edit. We omit the fields in `updateFields`. Here is the original commit from the quaive-app branch: https://github.com/euphorie/osha.oira/commit/f77fb25ea261421444d01913fb8e0e03ed2432fc Here the `sector_edit.pt` template was reformatted, even though the commit message said it was removed. It was no longer being used though. --- src/osha/oira/content/browser/sector.py | 16 ++--- .../content/browser/templates/sector_edit.pt | 72 ------------------- 2 files changed, 6 insertions(+), 82 deletions(-) delete mode 100644 src/osha/oira/content/browser/templates/sector_edit.pt diff --git a/src/osha/oira/content/browser/sector.py b/src/osha/oira/content/browser/sector.py index c903426d3..c791ca706 100644 --- a/src/osha/oira/content/browser/sector.py +++ b/src/osha/oira/content/browser/sector.py @@ -1,7 +1,6 @@ from euphorie.content.browser import sector from plone.dexterity.browser.add import DefaultAddForm from plone.dexterity.browser.add import DefaultAddView -from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile class AddForm(DefaultAddForm): @@ -20,12 +19,9 @@ class AddView(DefaultAddView): class EditForm(sector.EditForm): - template = ViewPageTemplateFile("templates/sector_edit.pt") - - def extractData(self): - unwanted_fields = ("locked", "password", "contact_name", "contact_email") - self.fields = self.fields.omit(*unwanted_fields) - for key in unwanted_fields: - if key in self.widgets: - del self.widgets[key] - return super().extractData() + + def updateFields(self): + super().updateFields() + self.fields = self.fields.omit( + "title", "login", "locked", "password", "contact_name", "contact_email" + ) diff --git a/src/osha/oira/content/browser/templates/sector_edit.pt b/src/osha/oira/content/browser/templates/sector_edit.pt deleted file mode 100644 index 62816c87f..000000000 --- a/src/osha/oira/content/browser/templates/sector_edit.pt +++ /dev/null @@ -1,72 +0,0 @@ - - - - Settings - -
-

status

-
    -
  • - field: - message -
  • -
-
-
-
- - -
- -
-

Logo

-
- The logo will appear on the client side app that your user group will see. Make sure your image is of format png, jpg or gif and does not contain any special characters. The new logo will only become visible after you've saved your changes and published the OiRA tool. - -
-

Which logo you would like to display in the lower left corner?

- - - - -
-
- -
- -
-

- You may get the best results if you upload a logo as a transparent PNG file of at least 100 pixels in height. Uploading larger images is fine, the logo will be scaled down to the right size automatically. -

-
- -
- - -
-
-
- - From a1c0bdfc7f888b0c3b26aa5302d150aeeb40c8ae Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 31 Jan 2025 12:12:51 +0100 Subject: [PATCH 3/3] Add survey-group-image and survey-group-introduction views. --- src/osha/oira/content/browser/configure.zcml | 22 +++++ .../content/browser/resources/clipboard.svg | 6 ++ src/osha/oira/content/browser/surveygroup.py | 80 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 src/osha/oira/content/browser/resources/clipboard.svg diff --git a/src/osha/oira/content/browser/configure.zcml b/src/osha/oira/content/browser/configure.zcml index bf9b5006e..f63c25236 100644 --- a/src/osha/oira/content/browser/configure.zcml +++ b/src/osha/oira/content/browser/configure.zcml @@ -3,6 +3,12 @@ xmlns:browser="http://namespaces.zope.org/browser" > + +
+ + + + + + + + + diff --git a/src/osha/oira/content/browser/surveygroup.py b/src/osha/oira/content/browser/surveygroup.py index 897276840..571255398 100644 --- a/src/osha/oira/content/browser/surveygroup.py +++ b/src/osha/oira/content/browser/surveygroup.py @@ -1,7 +1,9 @@ from Acquisition import aq_parent from euphorie.content import MessageFactory as _ from plone import api +from plone.base.utils import base_hasattr from plonetheme.nuplone.skin import actions +from Products.Five import BrowserView class Delete(actions.Delete): @@ -37,3 +39,81 @@ def verify(self, container, context): self.request.response.redirect(context.absolute_url()) return False return True + + +class SurveyGroupAttribute(BrowserView): + """Base view to return an attribute of a surveygroup from its surveys. + + We want to show both an 'image' and 'introduction' for a survey group, + and we can get them from one of its surveys. + """ + + attribute_name = "" + + @property + def surveys(self): + """Iterator over the surveys contained in the surveygroup. + + The published survey (if it exists) comes first. + """ + published = self.context.published + if published: + published_obj = self.context.get(published) + if published_obj: + yield published_obj + + for obj in self.context.listFolderContents({"portal_type": "Survey"}): + if obj.getId() != published: + yield obj + + def get_obj_attribute(self, obj): + """Return the attribute of the given object.""" + if not obj: + return + if not base_hasattr(obj, self.attribute_name): + return + return getattr(obj, self.attribute_name) + + +class SurveyGroupImage(SurveyGroupAttribute): + """Return the image of the surveygroup.""" + + attribute_name = "image" + + def __call__(self): + """Check all the surveys, if they have an image, redirect to that image. + + The image is set by a cron script, + see e.g. https://github.com/syslabcom/scrum/issues/2552. + + This might change in the future. + + Return a fallback if it does not exist. + """ + for survey in self.surveys: + if self.get_obj_attribute(survey): + image_url = f"{survey.absolute_url()}/@@images/image" + return self.request.response.redirect(image_url) + + self.request.response.redirect( + f"{api.portal.get().absolute_url()}" + f"/++resource++osha.oira.content/clipboard.svg" + ) + + +class SurveyGroupIntroduction(SurveyGroupAttribute): + """Return the introduction of the surveygroup.""" + + attribute_name = "introduction" + + def __call__(self): + """Check all the surveys, if they have an introduction, show it. + + We only need to return the contents of the field, which is expected + to be html. + """ + for survey in self.surveys: + value = self.get_obj_attribute(survey) + if value: + return value + return ""