Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Allows to create the root PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
msom committed Nov 15, 2018
1 parent c9c04d9 commit 0cef50a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions onegov/agency/layouts/agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def breadcrumbs(self):
def editbar_links(self):
if self.request.is_manager:
return [
Link(
text=_("Create PDF"),
url=self.request.link(self.model, 'create-pdf'),
attrs={'class': 'create-pdf'}
),
LinkGroup(
title=_("Add"),
links=[
Expand Down
1 change: 1 addition & 0 deletions onegov/agency/tests/test_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_agency_collection_layout():
request.is_manager = True
layout = AgencyCollectionLayout(model, request)
assert list(hrefs(layout.editbar_links)) == [
'ExtendedAgencyCollection/create-pdf',
'ExtendedAgencyCollection/new'
]

Expand Down
5 changes: 2 additions & 3 deletions onegov/agency/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ def test_views(client):
assert pdf.content_type == 'application/pdf'
assert pdf.content_length

client.app.root_pdf = BytesIO(pdf.body)

agencies = client.get('/organizations')
agencies = agencies.click("PDF erstellen").form.submit().follow()

pdf = agencies.click("Gesamter Staatskalender als PDF")
pdf = bund.click("Organisation als PDF speichern")
assert pdf.content_type == 'application/pdf'
assert pdf.content_length

Expand Down
34 changes: 34 additions & 0 deletions onegov/agency/views/agencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,40 @@ def get_root_pdf(self, request):
)


@AgencyApp.form(
model=ExtendedAgencyCollection,
name='create-pdf',
template='form.pt',
permission=Private,
form=Form
)
def create_root_pdf(self, request, form):

if form.submitted(request):
request.app.root_pdf = DefaultAgencyPdf.from_agencies(
agencies=self.roots,
author=request.app.org.name,
title=request.app.org.name,
toc=True,
exclude=request.app.org.hidden_people_fields
)
request.success(_("PDF created"))
return redirect(request.link(self))

layout = AgencyCollectionLayout(self, request)
layout.breadcrumbs.append(Link(_("Create PDF"), '#'))

return {
'layout': layout,
'title': _("Create PDF"),
'helptext': _(
"Create a PDF of this agency and all its suborganizations. "
"This may take a while."
),
'form': form
}


@AgencyApp.form(
model=ExtendedAgency,
name='create-pdf',
Expand Down

0 comments on commit 0cef50a

Please sign in to comment.