Files
mayan-edms/mayan/apps/events/apps.py
Roberto Rosario 64e1c6bb67 Add widget support to SourceColumn
Allow passing a widget class to SourceColumn. This makes
using lambdas to render model column unnecesary and are
mostly removed too.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
2018-12-22 05:35:31 -04:00

110 lines
3.5 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 mayan.apps.common import (
MayanAppConfig, menu_list_facet, menu_object, menu_secondary,
menu_tools, menu_topbar, menu_user
)
from mayan.apps.common.widgets import TwoStateWidget
from mayan.apps.navigation import SourceColumn
from .licenses import * # NOQA
from .links import (
link_current_user_events, link_event_types_subscriptions_list,
link_events_list, link_notification_mark_read,
link_notification_mark_read_all, link_user_events,
link_user_notifications_list
)
from .widgets import (
widget_event_object_link, widget_event_type_link, widget_event_user_link
)
class EventsApp(MayanAppConfig):
app_namespace = 'events'
app_url = 'events'
has_rest_api = True
has_tests = True
name = 'mayan.apps.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(
attribute='timestamp', is_identifier=True,
label=_('Date and time'), source=Action
)
SourceColumn(
func=widget_event_user_link, label=_('Actor'), source=Action
)
SourceColumn(
func=widget_event_type_link, label=_('Event'), source=Action
)
SourceColumn(
func=widget_event_object_link, kwargs={
'attribute': 'action_object'
}, label=_('Action object'), source=Action
)
SourceColumn(
func=widget_event_object_link, label=_('Target'), source=Action
)
SourceColumn(
source=StoredEventType, label=_('Namespace'), attribute='namespace'
)
SourceColumn(
source=StoredEventType, label=_('Label'), attribute='label'
)
SourceColumn(
attribute='action.timestamp', is_identifier=True,
label=_('Date and time'), source=Notification
)
SourceColumn(
func=widget_event_user_link, kwargs={'attribute': 'action'},
label=_('Actor'), source=Notification
)
SourceColumn(
func=widget_event_type_link, kwargs={'attribute': 'action'},
label=_('Event'), source=Notification
)
SourceColumn(
func=widget_event_object_link, kwargs={
'attribute': 'action.target'
}, label=_('Target'), source=Notification
)
SourceColumn(
attribute='read', label=_('Seen'), source=Notification,
widget=TwoStateWidget
)
menu_list_facet.bind_links(
links=(link_user_events,), sources=(User,)
)
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_topbar.bind_links(
links=(link_user_notifications_list,), position=1
)
menu_user.bind_links(
links=(
link_event_types_subscriptions_list, link_current_user_events
)
)