Source code for org.custom

from import MessageCollection, TextModuleCollection
from onegov.core.elements import Link, LinkGroup
from onegov.form.collection import FormCollection, SurveyCollection
from import _, OrgApp
from import (
    GeneralFileCollection, ImageFileCollection, Organisation)
from import PaymentProviderCollection, PaymentCollection
from onegov.ticket import TicketCollection
from onegov.ticket.collection import ArchivedTicketCollection
from onegov.user import Auth, UserCollection, UserGroupCollection
from purl import URL

from typing import Any, TYPE_CHECKING
    from import Iterator
    from import OrgRequest

[docs] def get_template_variables(request: 'OrgRequest') -> dict[str, Any]: return { 'global_tools': tuple(get_global_tools(request)) }
[docs] def logout_path(request: 'OrgRequest') -> str: url = URL( return url.path() or '/'
[docs] def get_global_tools(request: 'OrgRequest') -> 'Iterator[Link | LinkGroup]': # Authentication / Userprofile if request.is_logged_in: yield LinkGroup(_("Account"), classes=('user', ), links=( Link( _("User Profile"),, name='userprofile' ), attrs={'class': 'profile'} ), Link( _("Logout"), Auth.from_request( request, to=logout_path(request)), name='logout' ), attrs={'class': 'logout'} ), )) else: yield Link( _("Login"), Auth.from_request_path(request), name='login' ), attrs={'class': 'login'} ) if yield Link( _("Register"), Auth.from_request_path(request), name='register' ), attrs={'class': 'register'}) # Management dropdown if request.is_manager: links = [] links.append( Link( _("Timeline"), request.class_link(MessageCollection), attrs={'class': 'timeline'} ) ) links.append( Link( _("Files"), request.class_link(GeneralFileCollection), attrs={'class': 'files'} ) ) links.append( Link( _("Images"), request.class_link(ImageFileCollection), attrs={'class': 'images'} ) ) if request.is_admin and links.append( Link( _("Payment Provider"), request.class_link(PaymentProviderCollection), attrs={'class': 'payment-provider'} ) ) links.append( Link( _("Payments"), request.class_link(PaymentCollection), attrs={'class': 'payment'} ) ) links.append( Link( _("Text modules"), request.class_link(TextModuleCollection), attrs={'class': 'text-modules'} ) ) if request.is_admin: links.append( Link( _("Settings"),, 'settings' ), attrs={'class': 'settings'} ) ) links.append( Link( _("Users"), request.class_link( UserCollection, variables={'active': [True]}), attrs={'class': 'user'} ) ) links.append( Link( _('User groups'), request.class_link(UserGroupCollection), attrs={'class': 'users'} ) ) links.append( Link( _("Link Check"), request.class_link(Organisation, name='link-check'), attrs={'class': 'link-check'} ) ) links.append( Link( _("Archived Tickets"), request.class_link( ArchivedTicketCollection, {'handler': 'ALL'}), attrs={'class': 'ticket-archive'} ) ) links.append( Link( _("Forms"), request.class_link( FormCollection), attrs={'class': 'forms'} ) ) links.append( Link( _("Surveys"), request.class_link( SurveyCollection), attrs={'class': 'surveys'} ) ) yield LinkGroup(_("Management"), classes=('management', ), links=links) # Tickets if request.is_manager: assert request.current_user is not None ticket_count = screen_count = or ticket_count.pending links = [] links.append( Link( _("My Tickets"), request.class_link( TicketCollection, { 'handler': 'ALL', 'state': 'unfinished', 'owner': }, ), attrs={ 'class': ('my-tickets'), } ) ) links.append( Link( _("Open Tickets"), request.class_link( TicketCollection, {'handler': 'ALL', 'state': 'open'} ), attrs={ 'class': ('with-count', 'alert', 'open-tickets'), 'data-count': str( } ) ) links.append( Link( _("Pending Tickets"), request.class_link( TicketCollection, {'handler': 'ALL', 'state': 'pending'} ), attrs={ 'class': ('with-count', 'info', 'pending-tickets'), 'data-count': str(ticket_count.pending) } ) ) links.append( Link( _("Closed Tickets"), url=request.class_link( TicketCollection, {'handler': 'ALL', 'state': 'closed'} ), attrs={ 'class': ('with-count', 'secondary', 'closed-tickets'), 'data-count': str(ticket_count.closed), } ) ) if screen_count: css = and 'alert' or 'info' else: css = 'no-tickets' yield LinkGroup( screen_count == 1 and _("Ticket") or _("Tickets"), classes=('with-count', css), links=links, attributes={'data-count': str(screen_count)} )