Add the new list facet navigation menu. Used to provide facets to the list subtemplate. The list facet allows separating the object action links from the object navigation links. The list facet links are displayed before the list object links on the list subtemplate. In the object views, the list facet menu behaves exactly the same as the form facet menu. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
98 lines
3.2 KiB
Python
98 lines
3.2 KiB
Python
from __future__ import unicode_literals
|
|
|
|
from django.apps import apps
|
|
from django.contrib.auth import get_user_model
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from common import (
|
|
MayanAppConfig, menu_list_facet, menu_main, menu_object, menu_secondary,
|
|
menu_tools, menu_user
|
|
)
|
|
from common.widgets import TwoStateWidget
|
|
from navigation import SourceColumn
|
|
|
|
from .links import (
|
|
link_events_list, link_event_types_subscriptions_list,
|
|
link_notification_mark_read, link_notification_mark_read_all,
|
|
link_user_events, link_user_notifications_list,
|
|
)
|
|
from .licenses import * # NOQA
|
|
from .widgets import event_object_link, event_type_link, event_user_link
|
|
|
|
|
|
class EventsApp(MayanAppConfig):
|
|
has_rest_api = True
|
|
has_tests = True
|
|
name = 'events'
|
|
verbose_name = _('Events')
|
|
|
|
def ready(self):
|
|
super(EventsApp, self).ready()
|
|
Action = apps.get_model(app_label='actstream', model_name='Action')
|
|
Notification = self.get_model(model_name='Notification')
|
|
StoredEventType = self.get_model(model_name='StoredEventType')
|
|
User = get_user_model()
|
|
|
|
SourceColumn(
|
|
source=Action, label=_('Timestamp'), attribute='timestamp'
|
|
)
|
|
SourceColumn(
|
|
source=Action, label=_('Actor'),
|
|
func=lambda context: event_user_link(context['object'])
|
|
)
|
|
SourceColumn(
|
|
source=Action, label=_('Event'),
|
|
func=lambda context: event_type_link(context['object'])
|
|
)
|
|
SourceColumn(
|
|
source=Action, label=_('Action object'),
|
|
func=lambda context: event_object_link(
|
|
entry=context['object'], attribute='action_object'
|
|
)
|
|
)
|
|
|
|
SourceColumn(
|
|
source=StoredEventType, label=_('Namespace'), attribute='namespace'
|
|
)
|
|
SourceColumn(
|
|
source=StoredEventType, label=_('Label'), attribute='label'
|
|
)
|
|
|
|
SourceColumn(
|
|
source=Notification, label=_('Timestamp'),
|
|
attribute='action.timestamp'
|
|
)
|
|
SourceColumn(
|
|
source=Notification, label=_('Actor'), attribute='action.actor'
|
|
)
|
|
SourceColumn(
|
|
source=Notification, label=_('Event'),
|
|
func=lambda context: event_type_link(context['object'].action)
|
|
)
|
|
SourceColumn(
|
|
source=Notification, label=_('Target'),
|
|
func=lambda context: event_object_link(context['object'].action)
|
|
)
|
|
SourceColumn(
|
|
source=Notification, label=_('Seen'),
|
|
func=lambda context: TwoStateWidget(
|
|
state=context['object'].read
|
|
).render()
|
|
)
|
|
|
|
menu_list_facet.bind_links(
|
|
links=(link_user_events,), sources=(User,)
|
|
)
|
|
menu_main.bind_links(
|
|
links=(link_user_notifications_list,), position=99
|
|
)
|
|
menu_object.bind_links(
|
|
links=(link_notification_mark_read,), sources=(Notification,)
|
|
)
|
|
menu_secondary.bind_links(
|
|
links=(link_notification_mark_read_all,),
|
|
sources=('events:user_notifications_list',)
|
|
)
|
|
menu_tools.bind_links(links=(link_events_list,))
|
|
menu_user.bind_links(links=(link_event_types_subscriptions_list,))
|