Source code for fsi.layouts.course_event

from functools import cached_property

from onegov.core.elements import Link, Confirm, Intercooler, LinkGroup
from onegov.fsi.collections.audit import AuditCollection
from onegov.fsi.collections.course import CourseCollection
from onegov.fsi.collections.course_event import CourseEventCollection
from onegov.fsi.collections.notification_template import (
    CourseNotificationTemplateCollection)
from onegov.fsi.collections.subscription import SubscriptionsCollection
from onegov.fsi.layout import DefaultLayout
from onegov.fsi import _


from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from onegov.fsi.models import Course, CourseEvent


[docs] class CourseEventCollectionLayout(DefaultLayout):
[docs] model: CourseEventCollection
@cached_property
[docs] def course(self) -> 'Course | None': if self.model.course_id is None: return None return CourseCollection(self.request.session).by_id( self.model.course_id)
@cached_property
[docs] def title(self) -> str: if self.model.past_only: return _('Past Course Events') return _('Course Events')
@cached_property
[docs] def breadcrumbs(self) -> list[Link]: """ Returns the breadcrumbs for the current page. """ links = super().breadcrumbs assert isinstance(links, list) if self.course: links.append( Link( self.course.name, self.request.link(self.course) ) ) links.append( Link( _('Course Events'), self.request.class_link(CourseEventCollection))) return links
@cached_property
[docs] class CourseEventLayout(DefaultLayout):
[docs] model: 'CourseEvent'
@property
[docs] def title(self) -> str: return _('Course Event Details')
@cached_property
[docs] def collection(self) -> CourseEventCollection: return CourseEventCollection( self.request.session, show_hidden=True )
@cached_property
[docs] def course_collection(self) -> CourseEventCollection: return CourseEventCollection( self.request.session, show_hidden=True, course_id=self.model.course.id )
@cached_property
[docs] def reservation_collection(self) -> SubscriptionsCollection: return SubscriptionsCollection( self.request.session, course_event_id=self.model.id, auth_attendee=self.request.attendee )
@cached_property
[docs] def template_collection(self) -> CourseNotificationTemplateCollection: return CourseNotificationTemplateCollection( self.request.session, course_event_id=self.model.id )
@cached_property
[docs] def collection_url(self) -> str: return self.request.class_link(CourseEventCollection)
@cached_property
[docs] def breadcrumbs(self) -> list[Link]: """ Returns the breadcrumbs for the detail page. """ links = super().breadcrumbs assert isinstance(links, list) links.append( Link( self.model.course.name, self.request.link(self.model.course) ) ) links.append( Link( self.format_date(self.model.start, 'date_long'), self.request.link(self.model)) ) return links
@cached_property @cached_property
[docs] def intercooler_btn(self) -> Link: btn_class = f'button {"disabled" if self.model.booked else ""}' return Link( text=_('Subscribe'), url=self.csrf_protected_url( self.request.link( SubscriptionsCollection( self.request.session, auth_attendee=self.request.attendee, course_event_id=self.model.id, attendee_id=self.request.attendee_id ), name='add-from-course-event' ) ), attrs={'class': btn_class}, traits=( Confirm( _('Do you want to register for this course event ?'), _('A confirmation email will be sent to you later.'), _('Register for course event'), _('Cancel') ), Intercooler( request_method='POST', redirect_after=self.request.class_link( CourseCollection ) ) ) )
[docs] class EditCourseEventLayout(CourseEventLayout): @property
[docs] def title(self) -> str: return _('Edit course event')
@cached_property
[docs] def breadcrumbs(self) -> list[Link]: breadcrumbs = super().breadcrumbs breadcrumbs.append(Link(_('Edit'))) return breadcrumbs
[docs] class AddCourseEventLayout(CourseEventCollectionLayout): @property
[docs] def title(self) -> str: return _('Add course event')
@cached_property @cached_property
[docs] def breadcrumbs(self) -> list[Link]: links = super().breadcrumbs links.append(Link(_('Add'))) return links
[docs] class DuplicateCourseEventLayout(CourseEventLayout): @property
[docs] def title(self) -> str: return _('Duplicate course event')
@cached_property