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

Commit

Permalink
Merge branch 'pdf'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Sommerhalder committed Dec 11, 2017
2 parents 4322b4f + 1e9c9e7 commit 3d7eb8f
Show file tree
Hide file tree
Showing 34 changed files with 1,559 additions and 113 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
---------

- Allows to publish notices and to generate weekly PDFs.
[msom]

1.12.1 (2017-12-11)
~~~~~~~~~~~~~~~~~~~

Expand Down
22 changes: 21 additions & 1 deletion onegov/gazette/collections/issues.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from onegov.gazette.models import Issue
from collections import OrderedDict
from onegov.core.collection import GenericCollection
from onegov.gazette.models import Issue
from sedate import utcnow
from sqlalchemy import extract


class IssueCollection(GenericCollection):
Expand All @@ -17,3 +19,21 @@ def query(self):
@property
def current_issue(self):
return self.query().filter(Issue.deadline > utcnow()).first()

def by_name(self, name):
return self.query().filter(Issue.name == name).first()

@property
def years(self):
years = self.session.query(extract('year', Issue.date).distinct())
years = sorted([int(year[0]) for year in years])
return years

def by_years(self, desc=False):
issues = OrderedDict()
for year in sorted(self.years, reverse=desc):
query = self.query().filter(extract('year', Issue.date) == year)
if desc:
query = query.order_by(None).order_by(Issue.date.desc())
issues[year] = query.all()
return issues
12 changes: 11 additions & 1 deletion onegov/gazette/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def __init__(self, *args, **kwargs):

class MultiCheckboxField(MultiCheckboxFieldBase):
""" A multi checkbox field where only the first elements are display and
the the rest can be shown when needed. """
the the rest can be shown when needed.
Also, disables all the options if the whole field is disabled.
"""

def __init__(self, *args, **kwargs):
render_kw = kwargs.pop('render_kw', {})
Expand All @@ -36,6 +39,13 @@ def translate(self, request):
self.render_kw['data-fold-title']
)

def __iter__(self):
for opt in super(MultiCheckboxField, self).__iter__():
if 'disabled' in self.render_kw:
opt.render_kw = opt.render_kw or {}
opt.render_kw['disabled'] = self.render_kw['disabled']
yield opt


class DateTimeLocalField(DateTimeLocalFieldBase):
""" A custom implementation of the DateTimeLocalField to fix issues with
Expand Down
17 changes: 17 additions & 0 deletions onegov/gazette/forms/notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class UnrestrictedNoticeForm(NoticeForm):
""" Edit an official notice without limitations on the issues, categories
and organiaztions.
Optionally disables the issues (e.g. if the notice is already published).
"""

def on_request(self):
Expand Down Expand Up @@ -202,3 +204,18 @@ def title(item):

# translate the string of the mutli select field
self.issues.translate(self.request)

def disable_issues(self):
self.issues.validators = []
self.issues.render_kw['disabled'] = True

def update_model(self, model):
model.title = self.title.data
model.organization_id = self.organization.data
model.category_id = self.category.data
model.text = self.text.data
model.at_cost = self.at_cost.data
if model.state != 'published':
model.issues = self.issues.data

model.apply_meta(self.request.app.session())
38 changes: 27 additions & 11 deletions onegov/gazette/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ def menu(self):

active = isinstance(self.model, GazetteNoticeCollection)
link = self.request.link(
GazetteNoticeCollection(self.session, state='accepted')
GazetteNoticeCollection(self.session, state='published')
)
result.append((
_("My Accepted Official Notices"),
_("My Published Official Notices"),
link,
active
))
Expand Down Expand Up @@ -222,17 +222,33 @@ def format_date(self, dt, format):
dt = to_timezone(dt, self.principal.time_zone)
return super(Layout, self).format_date(dt, format)

def format_issue(self, issue, date_format='date'):
""" Returns the issues number and date. """
def format_issue(self, issue, date_format='date', notice=None):
""" Returns the issues number and date and optionally the publication
number of the given notice. """

assert isinstance(issue, Issue)

return self.request.translate(_(
"No. ${number}, ${issue_date}",
mapping={
'number': issue.number or '',
'issue_date': self.format_date(issue.date, date_format)
}
))
issue_number = issue.number or ''
issue_date = self.format_date(issue.date, date_format)
notice_number = notice.issues.get(issue.name, None) if notice else None

if notice_number:
return self.request.translate(_(
"No. ${issue_number}, ${issue_date} / ${notice_number}",
mapping={
'issue_number': issue_number,
'issue_date': issue_date,
'notice_number': notice_number
}
))
else:
return self.request.translate(_(
"No. ${issue_number}, ${issue_date}",
mapping={
'issue_number': issue_number,
'issue_date': issue_date
}
))

def format_text(self, text):
return '<br>'.join((text or '').splitlines())
Expand Down
75 changes: 61 additions & 14 deletions onegov/gazette/locale/de_CH/LC_MESSAGES/onegov.gazette.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE 1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-12-04 15:47+0100\n"
"POT-Creation-Date: 2017-12-11 10:20+0100\n"
"PO-Revision-Date: 2017-12-04 15:47+0100\n"
"Last-Translator: Marc Sommerhalder <[email protected]>\n"
"Language-Team: German\n"
Expand Down Expand Up @@ -33,8 +33,12 @@ msgid "Show less"
msgstr "Weniger anzeigen"

#, python-format
msgid "No. ${number}, ${issue_date}"
msgstr "Nr. ${number}, ${issue_date}"
msgid "No. ${issue_number}, ${issue_date} / ${notice_number}"
msgstr "Nr. ${issue_number}, ${issue_date} / ${notice_number}"

#, python-format
msgid "No. ${issue_number}, ${issue_date}"
msgstr "Nr. ${issue_number}, ${issue_date}"

msgid "Official Notices"
msgstr "Meldungen"
Expand All @@ -60,8 +64,11 @@ msgstr "Gruppen"
msgid "My Drafted and Submitted Official Notices"
msgstr "Offene Meldungen"

msgid "My Accepted Official Notices"
msgstr "Angenommene Meldungen"
msgid "My Published Official Notices"
msgstr "Veröffentlichte Meldungen"

msgid "Gazette"
msgstr "Amtsblatt"

msgid "This value already exists."
msgstr "Dieser Wert ist bereits vorhanden."
Expand Down Expand Up @@ -217,18 +224,24 @@ msgstr "Kommende Ausgaben"
msgid "Issue"
msgstr "Ausgabe"

msgid "PDF"
msgstr "PDF"

msgid "No upcoming issues."
msgstr "Keine kommenden Ausgaben."

msgid "Publish"
msgstr "Veröffentlichen"

msgid "Generate"
msgstr "Erzeugen"

msgid "Past Issues"
msgstr "Vergangene Ausgaben"

msgid "No past issues."
msgstr "Keine vergangenen Ausgaben."

msgid "Gazette"
msgstr "Amtsblatt"

msgid "homepage"
msgstr "Startseite"

Expand Down Expand Up @@ -472,6 +485,20 @@ msgstr "Ausgabe bearbeiten"
msgid "Delete Issue"
msgstr "Ausgabe löschen"

msgid "Publish all notices"
msgstr "Alle Meldungen veröffentlichen"

#, python-format
msgid ""
"Do you really want to publish all notices of \"${item}\"? This will assign "
"the publication numbers for ${number} notice(s)."
msgstr ""
"Alle Meldungen von \"${item}\" veröffentlichen? Es werden "
"Publikationsnummern für ${number} Meldung(en) vergeben."

msgid "Generate PDF"
msgstr "PDF erstellen"

msgid "Issue added."
msgstr "Ausgabe hinzugefügt."

Expand All @@ -484,6 +511,15 @@ msgstr "Es können nur unbenutzte Ausgaben gelöscht werden."
msgid "Issue deleted."
msgstr "Ausgabe gelöscht."

msgid "There are submitted notices for this issue!"
msgstr "Diese Ausgabe hat eingereichte Meldungen!"

msgid "All notices published."
msgstr "Alle Meldungen veröffentlicht."

msgid "PDF generated."
msgstr "PDF erstellt."

msgid "Edit Official Notice"
msgstr "Meldung bearbeiten"

Expand All @@ -499,9 +535,6 @@ msgstr "Kopieren"
msgid "Preview"
msgstr "Vorschau"

msgid "Publish"
msgstr "Veröffentlichen"

msgid "Reject"
msgstr "Zurückweisen"

Expand Down Expand Up @@ -578,6 +611,17 @@ msgstr "\"${item}\" zurückweisen?"
msgid "Reject Official Note"
msgstr "Meldung zurückweisen"

#, python-format
msgid ""
"Do you really want to publish \"${item}\"? This will assign the publication "
"numbers for the following issues: ${issues}."
msgstr ""
"\"${item}\" veröffentlichen? Es werden Publikationsnummern für die folgenden "
"Ausgaben vergeben: ${issues}."

msgid "Publish Official Note"
msgstr "Meldung veröffentlichen"

msgid "Only drafted or rejected official notices may be submitted."
msgstr ""
"Es können nur zurückgewiesene Meldungen oder Meldungen in Arbeit eingereicht "
Expand All @@ -598,6 +642,12 @@ msgstr "Es können nur eingereichte Meldungen zurückgewiesen werden."
msgid "Official notice rejected."
msgstr "Meldung zurückgewiesen."

msgid "Only accepted official notices may be published."
msgstr "Es können nur angenommene Meldungen veröffentlicht werden."

msgid "Official notice published."
msgstr "Meldung veröffentlicht."

msgid "mail sent"
msgstr "Druck beauftragt"

Expand Down Expand Up @@ -680,6 +730,3 @@ msgstr "Benutzer gelöscht."

msgid "User account created"
msgstr "Benutzerkonto Amtsblattredaktion erstellt"

#~ msgid "Do you really want to delete the attachment?"
#~ msgstr "Anhang löschen?"
Loading

0 comments on commit 3d7eb8f

Please sign in to comment.