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

Commit

Permalink
Adds the ability to create reservations and to accept/reject them
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krienbühl committed Aug 28, 2015
1 parent 5ed9071 commit 16f0338
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 13 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
Unreleased
~~~~~~~~~~

- Adds the ability to create reservations and to accept/reject them.
[href]

- The edit links for the model shown on the ticket view are now only visible
if the ticket is in 'pending' state. To change something on the model, the
ticket needs to be accepted/reopened.
Expand Down
26 changes: 25 additions & 1 deletion onegov/town/locale/de/LC_MESSAGES/onegov.town.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2015-08-27 14:55+0200\n"
"POT-Creation-Date: 2015-08-27 16:48+0200\n"
"PO-Revision-Date: \n"
"Last-Translator: Fabian Reinhard <fabian.reinhard@seantis.ch>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -423,6 +423,15 @@ msgstr "Älter"
msgid "Edit submission"
msgstr "Eingabe bearbeiten"

msgid "Reject reservation"
msgstr "Reservation absagen"

msgid "Do you really want to reject this reservation?"
msgstr "Möchten Sie diese Reservation wirklich absagen?"

msgid "Rejecting this reservation can't be undone."
msgstr "Eine Absage kann nicht rückgängig gemacht werden."

msgid "Details about the reservation"
msgstr "Details zu Ihrer Reservation"

Expand Down Expand Up @@ -622,6 +631,9 @@ msgstr ""
msgid "Your reservation has been accepted:"
msgstr "Ihre Reservation wurde angenommen:"

msgid "Your reservation has unfortunately been rejected:"
msgstr "Ihre Reservation musste leider abgesagt werden:"

msgid "Your ticket has been closed"
msgstr "Ihr Ticket wurde geschlossen"

Expand Down Expand Up @@ -708,6 +720,12 @@ msgstr "Möchten Sie die Eingabe wirklich löschen?"
msgid "Delete Submission"
msgstr "Eingabe Löschen"

msgid ""
"The record behind this ticket was removed. The following information is a "
"snapshot kept for future reference."
msgstr "Der hinterlegte Datensatz wurde entfernt. Die folgenden Informationen "
"sind eine Momentaufnahme, erstellt vor der Löschung."

msgid "Ticket Number"
msgstr "Referenz"

Expand Down Expand Up @@ -825,6 +843,9 @@ msgstr "Neue Reservation für ${title}"
msgid "Continue"
msgstr "Weiter"

msgid "The reservation was rejected"
msgstr "Die Reservation wurde abgesagt"

msgid "Thank you for your reservation!"
msgstr "Vielen Dank für Ihre Reservation!"

Expand All @@ -834,6 +855,9 @@ msgstr "Die Reservation wurde angenommen"
msgid "The reservation has already been accepted"
msgstr "Die Reservation wurde bereits angenommen"

msgid "Your reservation was rejected"
msgstr "Ihre Reservation wurde abgesagt"

msgid "The reservation could not be completed"
msgstr "Ihre Reservation konnte nicht abgeschlossen werden"

Expand Down
28 changes: 26 additions & 2 deletions onegov/town/models/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from onegov.libres import Resource
from onegov.ticket import Ticket, Handler, handlers
from onegov.town import _
from onegov.town.elements import Link
from onegov.town.elements import Link, DeleteLink
from onegov.town.layout import DefaultLayout
from purl import URL

Expand Down Expand Up @@ -33,6 +33,10 @@ def submission(self):
def form(self):
return self.submission.form_class(data=self.submission.data)

@property
def deleted(self):
return self.submission is None

@property
def email(self):
return self.submission.email
Expand Down Expand Up @@ -91,6 +95,10 @@ def reservations(self):
def submission(self):
return FormSubmissionCollection(self.session).by_id(self.id)

@property
def deleted(self):
return False if self.reservations else True

@property
def email(self):
# the e-mail is the same over all reservations
Expand Down Expand Up @@ -157,12 +165,28 @@ def get_links(self, request):

links.append(
Link(
text=_('Accept reservation'),
text=_("Accept reservation"),
url=link.as_string(),
classes=('accept-link', )
)
)

link = URL(request.link(self.reservations[0], 'absagen'))
link = link.query_param('return-to', request.url)
links.append(
DeleteLink(
text=_("Reject reservation"),
url=link.as_string(),
confirm=_("Do you really want to reject this reservation?"),
extra_information=_(
"Rejecting this reservation can't be undone."
),
yes_button_text=_("Reject reservation"),
request_method='GET',
redirect_after=request.url
)
)

if self.submission:
link = URL(request.link(self.submission))
link = link.query_param('edit', '')
Expand Down
12 changes: 12 additions & 0 deletions onegov/town/templates/mail_reservation_rejected.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div metal:use-macro="layout.base" i18n:domain="onegov.town">
<tal:block metal:fill-slot="title">
${title}
</tal:block>
<tal:block metal:fill-slot="body">
<p i18n:translate>Dear Sir or Madam,</p>
<p i18n:translate>Your reservation has unfortunately been rejected:</p>

<p>${resource.title}</p>
<tal:block metal:use-macro="layout.macros['reservations']"></tal:block>
</tal:block>
</div>
6 changes: 5 additions & 1 deletion onegov/town/templates/ticket.pt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
<tal:block metal:fill-slot="content">
<div class="row">
<div class="columns small-12 medium-8">
<div tal:condition="deleted" class="panel callout" i18n:translate>
The record behind this ticket was removed. The following information
is a snapshot kept for future reference.
</div>
<div class="ticket-summary">
<tal:block replace="structure ticket.handler.get_summary(request)" />
<tal:block replace="structure summary" />
</div>
</div>
<div class="columns small-12 medium-4">
Expand Down
40 changes: 39 additions & 1 deletion onegov/town/views/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def finalize_reservation(self, request):

with forms.session.no_autoflush:
ticket = TicketCollection(request.app.session()).open_ticket(
handler_code='RSV', handler_id=self.token
handler_code='RSV', handler_id=self.token.hex
)

send_html_mail(
Expand Down Expand Up @@ -215,3 +215,41 @@ def accept_reservation(self, request):
request.warning(_("The reservation has already been accepted"))

return morepath.redirect(request.params['return-to'])


@TownApp.view(model=Reservation, name='absagen', permission=Private)
def reject_reservation(self, request):
collection = ResourceCollection(request.app.libres_context)
resource = collection.by_id(self.resource)
scheduler = resource.get_scheduler(request.app.libres_context)
reservations = scheduler.reservations_by_token(self.token.hex)
forms = FormCollection(request.app.session())
submission = forms.submissions.by_id(self.token.hex)

send_html_mail(
request=request,
template='mail_reservation_rejected.pt',
subject=_("Your reservation was rejected"),
receivers=(self.email, ),
content={
'model': self,
'resource': resource,
'reservations': reservations
}
)

# create a snapshot of the ticket to keep the useful information
tickets = TicketCollection(request.app.session())
ticket = tickets.by_handler_id(self.token.hex)
ticket.create_snapshot(request)

scheduler.remove_reservation(self.token.hex)

if submission:
forms.submissions.delete(submission)

request.success(_("The reservation was rejected"))

# return none on intercooler js requests
if not request.headers.get('X-IC-Request'):
return morepath.redirect(request.params['return-to'])
28 changes: 20 additions & 8 deletions onegov/town/views/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@
@TownApp.html(model=Ticket, template='ticket.pt', permission=Private)
def view_ticket(self, request):

# XXX this is very to do here, much harder when the ticket is updated
# because there's no good link to the ticket at that point - so when
# viewing the ticket we commit the sin of possibly changing data in a
# GET request.
self.handler.refresh()
handler = self.handler

if handler.deleted:
summary = self.snapshot.get('summary')
else:
# XXX this is very to do here, much harder when the ticket is updated
# because there's no good link to the ticket at that point - so when
# viewing the ticket we commit the sin of possibly changing data in a
# GET request.
handler.refresh()
summary = handler.get_summary(request)

return {
'title': self.number,
'layout': TicketLayout(self, request),
'ticket': self
'ticket': self,
'summary': summary,
'deleted': handler.deleted
}


Expand Down Expand Up @@ -49,11 +57,13 @@ def close_ticket(self, request):
'number': self.number
}))

email = self.snapshot.get('email') or self.handler.email

send_html_mail(
request=request,
template='mail_ticket_closed.pt',
subject=_("Your ticket has been closed"),
receivers=(self.handler.email, ),
receivers=(email, ),
content={
'model': self
}
Expand All @@ -76,11 +86,13 @@ def reopen_ticket(self, request):
'number': self.number
}))

email = self.snapshot.get('email') or self.handler.email

send_html_mail(
request=request,
template='mail_ticket_reopened.pt',
subject=_("Your ticket has been reopened"),
receivers=(self.handler.email, ),
receivers=(email, ),
content={
'model': self
}
Expand Down

0 comments on commit 16f0338

Please sign in to comment.