Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quaive app merge, part 1 #307

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/osha/oira/content/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
xmlns:browser="http://namespaces.zope.org/browser"
>

<browser:resourceDirectory
name="osha.oira.content"
directory="resources"
layer="osha.oira.interfaces.IOSHAContentSkinLayer"
/>

<browser:page
name="manage-ldap-users"
for="euphorie.content.country.ICountry"
Expand Down Expand Up @@ -54,14 +60,6 @@
/>

<!-- SurveyGroup -->
<adapter
for="Products.CMFCore.interfaces.IFolderish
osha.oira.interfaces.IOSHAContentSkinLayer
plone.dexterity.interfaces.IDexterityFTI"
provides="zope.publisher.interfaces.browser.IBrowserPage"
factory=".surveygroup.AddView"
name="euphorie.surveygroup"/>

<configure package="plonetheme.nuplone.skin">
<browser:page
name="delete"
Expand All @@ -73,6 +71,22 @@
/>
</configure>

<browser:page
name="survey-group-image"
for="euphorie.content.surveygroup.ISurveyGroup"
class=".surveygroup.SurveyGroupImage"
permission="zope2.View"
layer="osha.oira.interfaces.IOSHAContentSkinLayer"
/>

<browser:page
name="survey-group-introduction"
for="euphorie.content.surveygroup.ISurveyGroup"
class=".surveygroup.SurveyGroupIntroduction"
permission="zope2.View"
layer="osha.oira.interfaces.IOSHAContentSkinLayer"
/>

<!-- Sector -->
<adapter
name="euphorie.sector"
Expand Down
6 changes: 6 additions & 0 deletions src/osha/oira/content/browser/resources/clipboard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 6 additions & 10 deletions src/osha/oira/content/browser/sector.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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"
)
90 changes: 80 additions & 10 deletions src/osha/oira/content/browser/surveygroup.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
from Acquisition import aq_parent
from euphorie.content import MessageFactory as _
from euphorie.content.browser import surveygroup
from plone import api
from plone.base.utils import base_hasattr
from plonetheme.nuplone.skin import actions
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile


class AddForm(surveygroup.AddForm):
template = ViewPageTemplateFile("templates/surveygroup_add.pt")


class AddView(surveygroup.AddView):
form = AddForm
from Products.Five import BrowserView


class Delete(actions.Delete):
Expand Down Expand Up @@ -47,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 ""
72 changes: 0 additions & 72 deletions src/osha/oira/content/browser/templates/sector_edit.pt

This file was deleted.

108 changes: 0 additions & 108 deletions src/osha/oira/content/browser/templates/surveygroup_add.pt

This file was deleted.