Skip to content

Commit

Permalink
Ticket: Adds translations for handler codes
Browse files Browse the repository at this point in the history
Render a better translation for each handler code if it is used by the app and translations exist.

Type: Feature
Link: SEA-364
  • Loading branch information
Lukas Burkhard committed Jun 1, 2021
1 parent 644a67e commit 085924d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/onegov/agency/models/ticket.py
Expand Up @@ -32,6 +32,7 @@ def reference_group(self, request):
class AgencyMutationHandler(Handler):

handler_title = _("Agency")
code_title = _("Agencies")

@cached_property
def collection(self):
Expand Down Expand Up @@ -82,6 +83,7 @@ def get_links(self, request):
class PersonMutationHandler(Handler):

handler_title = _("Person")
code_title = _("People")

@cached_property
def collection(self):
Expand Down
1 change: 1 addition & 0 deletions src/onegov/feriennet/models/activity.py
Expand Up @@ -92,6 +92,7 @@ def reference_group(self, request):
class VacationActivityHandler(Handler):

handler_title = _("Activities")
code_title = _("Activities")

@cached_property
def collection(self):
Expand Down
26 changes: 24 additions & 2 deletions src/onegov/org/forms/settings.py
Expand Up @@ -729,9 +729,31 @@ class OrgTicketSettingsForm(Form):
render_kw={'disabled': True}
)

def code_title(self, code):
""" Renders a better translation for handler_codes.
Note that the registry of handler_codes is global and not all handlers
might are used in this app. The translations give a hint whether the
handler is used/defined in the app using this form.
A better translation is only then possible.
"""
trs = getattr(handlers.registry[code], 'code_title', None)
if not trs:
return code
translated = self.request.translate(trs)
if str(trs) == translated:
# Code not used by app
return code
return f'{code} - {translated}'

def on_request(self):
choices = tuple((key, key) for key in handlers.registry.keys())
self.ticket_auto_accepts.choices = [('RSV', 'RSV')]

choices = tuple(
(key, self.code_title(key)) for key in handlers.registry.keys()
)
auto_accept_choices = ('RSV',)
self.ticket_auto_accepts.choices = [
(key, self.code_title(key)) for key in auto_accept_choices
]
self.tickets_skip_opening_email.choices = choices

permissions = sorted([
Expand Down
4 changes: 4 additions & 0 deletions src/onegov/org/models/ticket.py
Expand Up @@ -105,6 +105,7 @@ class DirectoryEntryTicket(OrgTicketMixin, Ticket):
class FormSubmissionHandler(Handler):

handler_title = _("Form Submissions")
code_title = _("Forms")

@cached_property
def collection(self):
Expand Down Expand Up @@ -286,6 +287,7 @@ def get_links(self, request):
class ReservationHandler(Handler):

handler_title = _("Reservations")
code_title = _("Reservations")

@cached_property
def resource(self):
Expand Down Expand Up @@ -518,6 +520,7 @@ def get_links(self, request):
class EventSubmissionHandler(Handler):

handler_title = _("Events")
code_title = _("Events")

@cached_property
def collection(self):
Expand Down Expand Up @@ -669,6 +672,7 @@ def get_links(self, request):
class DirectoryEntryHandler(Handler):

handler_title = _("Directory Entry Submissions")
code_title = _("Directory Entry Submissions")

@cached_property
def collection(self):
Expand Down

0 comments on commit 085924d

Please sign in to comment.