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

Ogc 1821 export surveys #1512

Merged
merged 5 commits into from
Sep 10, 2024
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
8 changes: 7 additions & 1 deletion src/onegov/org/forms/survey_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def load_submission_window(self) -> None:
return

self.submission_window.choices = [
(window.id.hex, layout.format_date_range(window.start, window.end))
(window.id.hex,
f'{layout.format_date_range(window.start, window.end)}, '
f'{window.title}')
for window in windows
]

if self.request.params.get('submission_window_id'):
self.submission_window.data = [
self.request.params['submission_window_id']]
2 changes: 1 addition & 1 deletion src/onegov/org/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ def editbar_links(self) -> list[Link | LinkGroup] | None:
change_url_link,
submission_windows_link,
qr_link,
results_link
results_link,
]


Expand Down
17 changes: 11 additions & 6 deletions src/onegov/org/views/survey_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
from onegov.form.models.definition import SurveyDefinition
from onegov.gis import Coordinates
from onegov.org import _, OrgApp
from onegov.org.elements import Link
from onegov.core.elements import Link
from onegov.org.forms.form_definition import SurveyDefinitionForm
from onegov.org.layout import FormEditorLayout, SurveySubmissionLayout
from onegov.org.layout import (FormEditorLayout,
SurveySubmissionLayout)


from typing import TypeVar, TYPE_CHECKING
Expand Down Expand Up @@ -183,10 +184,14 @@ def view_survey_results(
fields = all_fields.values()

layout = layout or SurveySubmissionLayout(self, request)
layout.breadcrumbs.append(
Link(_("Results"), request.link(self, name='results'))
)
layout.editbar_links = []
layout.breadcrumbs.append(Link(_('Results'), '#'))

layout.editbar_links = [
Link(
text=_("Export"),
url=request.link(self, name='export'),
attrs={'class': 'export-link'}
)]

return {
'layout': layout,
Expand Down
11 changes: 10 additions & 1 deletion src/onegov/org/views/survey_submission_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from onegov.core.security import Private
from onegov.core.security.permissions import Public
from onegov.core.utils import append_query_param
from onegov.form.collection import SurveyCollection
from onegov.form.models.definition import SurveyDefinition
from onegov.form.models.submission import SurveySubmission
Expand Down Expand Up @@ -109,7 +110,15 @@ def view_submission_window_results(
date_range = layout.format_date_range(self.start, self.end)
layout.breadcrumbs.append(Link(window_name, request.link(self)))
layout.breadcrumbs.append(Link(_('Results'), '#'))
layout.editbar_links = []

layout.editbar_links = [
Link(
text=_("Export"),
url=append_query_param(
request.link(self.survey, name='export'),
'submission_window_id', self.id.hex),
attrs={'class': 'export-link'}
)]

q = request.session.query(SurveySubmission)
submissions = q.filter_by(submission_window_id=self.id).all()
Expand Down
30 changes: 30 additions & 0 deletions src/onegov/town6/views/survey_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from onegov.core.security import Private
from onegov.form.models.definition import SurveyDefinition
from onegov.org.forms.survey_export import SurveySubmissionsExport
from onegov.org.views.survey_export import (
handle_form_submissions_export)
from onegov.town6 import TownApp
from onegov.town6.layout import SurveySubmissionLayout


from typing import TYPE_CHECKING
if TYPE_CHECKING:
from onegov.core.types import RenderData
from onegov.town6.request import TownRequest
from webob import Response


@TownApp.form(
model=SurveyDefinition,
name='export',
template='form.pt',
permission=Private,
form=SurveySubmissionsExport
)
def town_handle_form_submissions_export(
self: SurveyDefinition,
request: 'TownRequest',
form: SurveySubmissionsExport
) -> 'RenderData | Response':
return handle_form_submissions_export(
self, request, form, SurveySubmissionLayout(self, request))