Skip to content

Commit

Permalink
Org: Document forms
Browse files Browse the repository at this point in the history
Upload a PDF to be displayed in the forms view.

TYPE: Feature
LINK: OGC-2003
  • Loading branch information
BreathingFlesh authored Jan 23, 2025
1 parent 2eff06c commit 1a3e116
Show file tree
Hide file tree
Showing 18 changed files with 812 additions and 49 deletions.
57 changes: 57 additions & 0 deletions src/onegov/org/forms/document_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from __future__ import annotations

from onegov.core.utils import normalize_for_url
from onegov.form import Form
from onegov.form.core import DataRequired
from onegov.form.fields import HtmlField, UploadFileWithORMSupport
from onegov.org.models.document_form import DocumentFormFile
from onegov.form.validators import FileSizeLimit, WhitelistedMimeType
from onegov.org import _
from wtforms.fields import StringField
from wtforms.fields import TextAreaField
from wtforms.validators import InputRequired

from typing import Any, TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Collection


class DocumentForm(Form):

title = StringField(
label=_('Title'),
validators=[InputRequired()])

lead = TextAreaField(
label=_('Lead'),
description=_('Describes briefly what this form is about'),
validators=[],
render_kw={'rows': 4})

text = HtmlField(
label=_('Detailed Explanation'),
description=_('Describes in detail how this form is to be filled'))

pdf = UploadFileWithORMSupport(
label=_('Form PDF'),
file_class=DocumentFormFile,
validators=[
WhitelistedMimeType({'application/pdf'}),
FileSizeLimit(100 * 1024 * 1024),
DataRequired()
],)

group = StringField(
label=_('Group'),
description=_('Used to group this form in the overview'))

def get_useful_data(
self,
exclude: Collection[str] | None = None
) -> dict[str, Any]:

data = super().get_useful_data(exclude)
data['pdf'] = self.pdf.create()
data['name'] = normalize_for_url(self.title.data) # type: ignore

return data
77 changes: 76 additions & 1 deletion src/onegov/org/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from onegov.event import OccurrenceCollection
from onegov.file import File
from onegov.form import FormCollection, as_internal_id
from onegov.org.models.document_form import (
FormDocument,
FormDocumentCollection)
from onegov.newsletter import NewsletterCollection, RecipientCollection
from onegov.org import _
from onegov.org import utils
Expand Down Expand Up @@ -89,7 +92,8 @@
_T = TypeVar('_T')

AnyFormDefinitionOrCollection: TypeAlias = (
FormDefinition | FormCollection | SurveyCollection | SurveyDefinition)
FormDefinition | FormCollection | SurveyCollection | SurveyDefinition
| FormDocumentCollection | FormDocument)


capitalised_name = re.compile(r'[A-Z]{1}[a-z]+')
Expand Down Expand Up @@ -1222,6 +1226,10 @@ def external_forms(self) -> ExternalLinkCollection:
def form_definitions(self) -> FormCollection:
return FormCollection(self.request.session)

@property
def document_forms(self) -> FormDocumentCollection:
return FormDocumentCollection(self.request.session)

@property
def editbar_links(self) -> list[Link | LinkGroup] | None:
if self.request.is_manager:
Expand Down Expand Up @@ -1250,6 +1258,14 @@ def editbar_links(self) -> list[Link | LinkGroup] | None:
),
attrs={'class': 'new-form'}
),
Link(
text=_('Document form'),
url=self.request.link(
self.document_forms,
name='new'
),
attrs={'class': 'new-document-form'}
),
]
),
]
Expand Down Expand Up @@ -1479,6 +1495,65 @@ def editbar_links(self) -> list[Link | LinkGroup] | None:
return None


class FormDocumentLayout(DefaultLayout):

@cached_property
def breadcrumbs(self) -> list[Link]:
collection = FormCollection(self.request.session)

return [
Link(_('Homepage'), self.homepage_url),
Link(_('Forms'), self.request.link(collection)),
Link(self.model.title, self.request.link(self.model))
]

@cached_property
def editbar_links(self) -> list[Link | LinkGroup] | None:

if not self.request.is_manager:
return None

collection = FormCollection(self.request.session)

edit_link = Link(
text=_('Edit'),
url=self.request.link(self.model, name='edit'),
attrs={'class': 'edit-link'}
)

qr_link = QrCodeLink(
text=_('QR'),
url=self.request.link(self.model),
attrs={'class': 'qr-code-link'}
)

delete_link = Link(
text=_('Delete'),
url=self.csrf_protected_url(
self.request.link(self.model)
),
attrs={'class': 'delete-link'},
traits=(
Confirm(
_('Do you really want to delete this form?'),
_('This cannot be undone.'),
_('Delete form'),
_('Cancel')
),
Intercooler(
request_method='DELETE',
redirect_after=self.request.link(collection)
)
)
)

return [
edit_link,
delete_link,
qr_link
]


class PersonCollectionLayout(DefaultLayout):

@cached_property
Expand Down
75 changes: 60 additions & 15 deletions src/onegov/org/locale/de_CH/LC_MESSAGES/onegov.org.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE 1.0\n"
"POT-Creation-Date: 2025-01-08 16:47+0100\n"
"POT-Creation-Date: 2025-01-22 08:59+0100\n"
"PO-Revision-Date: 2022-03-15 10:21+0100\n"
"Last-Translator: Marc Sommerhalder <[email protected]>\n"
"Language-Team: German\n"
Expand Down Expand Up @@ -593,6 +593,24 @@ msgstr "Ein Eintrag mit diesem Namen existiert bereits"
msgid "E-Mail"
msgstr "E-Mail"

msgid "Describes briefly what this form is about"
msgstr "Beschreibt kurz um was es bei diesem Formular geht"

msgid "Detailed Explanation"
msgstr "Detaillierte Erklärung"

msgid "Describes in detail how this form is to be filled"
msgstr "Beschreibt detailliert wie dieses Formular ausgefüllt werden soll"

msgid "Form PDF"
msgstr "Formular PDF"

msgid "Group"
msgstr "Gruppe"

msgid "Used to group this form in the overview"
msgstr "Dient zur Gruppierung in der Übersicht"

msgid "Art"
msgstr "Kunst"

Expand Down Expand Up @@ -844,9 +862,6 @@ msgstr "URL"
msgid "Url pointing to another website"
msgstr "Url, der auf eine andere Website zeigt"

msgid "Group"
msgstr "Gruppe"

msgid "Used to group this link in the overview"
msgstr "Wird benutzt, um diesen Link in der Übersicht zu gruppieren"

Expand Down Expand Up @@ -1032,6 +1047,15 @@ msgstr "Nach Zeitpunkt der letzten Änderung"
msgid "Show images on homepage"
msgstr "Bilder auf der Startseite zeigen"

msgid "By filename"
msgstr "Nach Dateiname"

msgid "By caption"
msgstr "Nach Beschreibung"

msgid "By last change"
msgstr "Nach Zeitpunkt der letzten Änderung"

msgid "Used in the overview and the e-mail subject"
msgstr "Wird in der Übersicht und als E-Mail Subjekt verwendet"

Expand Down Expand Up @@ -1694,10 +1718,10 @@ msgid "JavaScript for web statistics support"
msgstr "JavaScript für Web-Statistik"

msgid "Analytics URL"
msgstr ""
msgstr "Analytics URL"

msgid "URL pointing to the analytics page"
msgstr ""
msgstr "Link zur Analytics Seite"

msgid "Cantonal holidays"
msgstr "Kantonale Feiertage"
Expand Down Expand Up @@ -2307,12 +2331,17 @@ msgstr "Externes Formular"
msgid "New external form"
msgstr "Neues externes Formular"

msgid "Document form"
msgstr "Dokumentenformular"

msgid "Do you really want to delete this submission window?"
msgstr "Möchten Sie diesen Befragungszeitraum wirklich löschen?"

msgid ""
"Submissions associated with this submission window will be deleted as well."
msgstr ""
"Eingaben, die mit diesem Befragungszeitraum verknüpft sind, werden ebenfalls "
"gelöscht."

msgid "Delete submission window"
msgstr "Befragungszeitraum löschen"
Expand Down Expand Up @@ -3296,6 +3325,9 @@ msgstr "Bestätigen"
msgid "There was an error while importing your directory!"
msgstr "Beim Verzeichnisimport ist ein Fehler aufgetreten!"

msgid "Download Form"
msgstr "Formular herunterladen"

msgid "Embed iFrame"
msgstr "iFrame einbetten"

Expand Down Expand Up @@ -4278,7 +4310,7 @@ msgid "There are currently ${count} recipients registered."
msgstr "Zur Zeit sind ${count} Abonnenten registriert."

msgid "To update your subscription, please use this ${Link}"
msgstr ""
msgstr "Um Ihr Abonnement zu aktualisieren, verwenden Sie bitte diesen ${Link}"

msgid "Archive"
msgstr "Archiv"
Expand Down Expand Up @@ -4589,6 +4621,8 @@ msgid ""
"Thank you for filling out this survey. If there's anything you'd like to "
"change, click on the \"Edit\"-Button below."
msgstr ""
"Vielen Dank für das Ausfüllen dieser Umfrage. Falls Sie noch etwas ändern "
"möchten, klicken Sie auf den \"Bearbeiten\"-Button unten."

msgid "No surveys defined yet."
msgstr "Es wurden noch keine Umfragen definiert."
Expand Down Expand Up @@ -4863,6 +4897,8 @@ msgid ""
"Rule updated. ${deleted} allocations removed, ${created} new allocations "
"created."
msgstr ""
"Regel aktualisiert. ${deleted} Einteilungen entfernt, ${created} neue "
"Einteilungen erstellt."

msgid "Rule not found"
msgstr "Regel nicht gefunden"
Expand Down Expand Up @@ -5172,6 +5208,15 @@ msgstr "${address} wurde erfolgreich abgemeldet"
msgid "${address} could not be unsubscribed, wrong token"
msgstr "${address} konnte nicht abgemeldet werden - falsches Token"

msgid "Added a new form"
msgstr "Ein neues Formular wurd hinzugefügt"

msgid "New Document Form"
msgstr "Neues Dokumentenformular"

msgid "Edit Document Form"
msgstr "Dokumentenformular bearbeiten"

msgid "Moves the topic and all its sub topics to the given destination."
msgstr "Verschiebt das Thema mit allen Unterthemen an den gewählten Ort."

Expand Down Expand Up @@ -5309,9 +5354,6 @@ msgstr "Es sind noch ${count} Plätze verfügbar"
msgid "A form with this name already exists"
msgstr "Ein Formular mit diesem Namen existiert bereits"

msgid "Added a new form"
msgstr "Ein neues Formular wurd hinzugefügt"

msgid "New Form"
msgstr "Neues Formular"

Expand Down Expand Up @@ -5936,16 +5978,16 @@ msgstr ""
"Einträge."

msgid "Delete Submissions"
msgstr ""
msgstr "Einträge löschen"

msgid "Do you really want to delete all submissions?"
msgstr ""
msgstr "Möchten Sie wirklich alle Einträge löschen?"

msgid "All submissions associated with this survey will be deleted."
msgstr ""
msgstr "Alle mit dieser Umfrage verbundenen Einträge werden gelöscht."

msgid "Delete submissions"
msgstr ""
msgstr "Einträge löschen"

msgid "Exports the submissions of the survey."
msgstr "Exportiert die Umfrageeinträge."
Expand All @@ -5972,7 +6014,7 @@ msgid "Edit Submission Window"
msgstr "Befragungszeitraum bearbeiten"

msgid "The submission window and all associated submissions were deleted"
msgstr ""
msgstr "Der Befragungszeitraum und alle zugehörigen Einträge wurden gelöscht"

msgid "Added a new text module"
msgstr "Textbaustein hinzugefügt"
Expand Down Expand Up @@ -6195,6 +6237,9 @@ msgstr "Ein Konto wurde für Sie erstellt"
msgid "The user was created successfully"
msgstr "Der Benutzer wurde erfolgreich erstellt"

#~ msgid "Describes in detail how this form is to be used"
#~ msgstr "Beschreibt detailliert wie dieses Formular benutzt werden soll"

#~ msgid "Photo album. Will be shown at the end of content."
#~ msgstr "Fotoalbum. Wird am Ende des Inhalts angezeigt."

Expand Down
Loading

0 comments on commit 1a3e116

Please sign in to comment.