Source code for fsi.custom

from onegov.core.elements import Link
from onegov.form.collection import SurveyCollection
from onegov.fsi import FsiApp
from onegov.fsi.collections.attendee import CourseAttendeeCollection
from onegov.fsi.collections.audit import AuditCollection
from onegov.fsi.collections.course import CourseCollection
from onegov.fsi.collections.course_event import PastCourseEventCollection
from onegov.fsi.collections.subscription import SubscriptionsCollection
from onegov.fsi.layout import DefaultLayout
from onegov.fsi import _
from import LinkGroup
from import logout_path
from import GeneralFileCollection, ImageFileCollection
from onegov.user import Auth, UserCollection

from typing import Any, TYPE_CHECKING
    from import Iterator
    from onegov.fsi.request import FsiRequest

[docs] def get_base_tools(request: 'FsiRequest') -> 'Iterator[Link | LinkGroup]': if request.is_logged_in: usr = request.attendee reservation_count = 0 if not usr else usr.subscriptions.count() profile_links = [ Link( _("Profile"),, attrs={'class': 'profile'} ) ] if usr else [] if request.is_admin: profile_links.append( Link( _("User Profile"),, name='userprofile'), attrs={'class': 'profile'} ) ) profile_links.append( Link( _("Logout"), Auth.from_request( request, to=logout_path(request)), name='logout' ), attrs={'class': 'logout'} ), ) assert request.current_username is not None yield LinkGroup( request.current_username, classes=('user',), links=profile_links) # Management dropdown for admin (e.g Kursverantwortlicher) links = [] if request.is_manager: links.append( Link( _('Attendees'), request.session, auth_attendee=usr)), attrs={'class': 'attendees'} ) ) links.append( Link( _('Event Subscriptions'), request.session, auth_attendee=usr)), attrs={'class': 'subscriptions'} ) ) links.append( Link( _("Surveys"), request.class_link( SurveyCollection), attrs={'class': 'surveys'} ) ) if request.is_admin: links.append( Link( _("Files"), request.class_link(GeneralFileCollection), attrs={'class': 'files'} ) ) links.append( Link( _("Images"), request.class_link(ImageFileCollection), attrs={'class': 'images'} ) ) links.append( Link( _("Settings"),, 'settings' ), attrs={'class': 'settings'} ) ) links.append( Link( _("Users"), request.class_link(UserCollection), attrs={'class': 'users'} ) ) if request.is_manager: yield LinkGroup(_("Management"), classes=('management',), links=links) if reservation_count: css = 'alert open-tickets' else: css = 'no-tickets' yield Link( reservation_count == 1 and _("Event Subscription") or _("Event Subscriptions"), SubscriptionsCollection( request.session, attendee_id=request.attendee_id, auth_attendee=usr ), ), attrs={ 'class': ('with-count', css), 'data-count': str(reservation_count) } ) 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'})
[docs] def get_global_tools(request: 'FsiRequest') -> 'Iterator[Link | LinkGroup]': yield from get_base_tools(request)
[docs] def get_template_variables(request: 'FsiRequest') -> dict[str, Any]: return { 'global_tools': tuple(get_global_tools(request)), 'top_navigation': tuple(get_top_navigation(request)), 'hide_search_header': not request.is_logged_in }
[docs] def get_top_navigation(request: 'FsiRequest') -> 'Iterator[Link]': # inject an activites link in front of all top navigation links yield Link( text=_("Courses"), url=request.class_link(CourseCollection) ) if request.is_manager: yield Link( text=_("Audit"), url=request.class_link(AuditCollection) ) yield Link( text=_("Attendee Check"), url=request.class_link(PastCourseEventCollection) ) layout = DefaultLayout(, request) yield from layout.top_navigation or ()