Add support for showing the current user's events

Add support kwargs to the SourceColumn class. Improve the
event widgets, views and tests.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-22 01:32:52 -04:00
parent 66e0d9f357
commit ce0a6368f2
14 changed files with 259 additions and 177 deletions

View File

@@ -1,7 +1,6 @@
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.apps import MayanAppConfig
@@ -11,13 +10,15 @@ from mayan.apps.common.menus import (
from mayan.apps.common.widgets import TwoStateWidget
from mayan.apps.navigation import SourceColumn
from .html_widgets import (
ObjectLinkWidget, widget_event_actor_link, widget_event_type_link
)
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,
link_current_user_events, link_event_types_subscriptions_list,
link_events_list, link_notification_mark_read,
link_notification_mark_read_all, link_user_notifications_list,
)
from .licenses import * # NOQA
from .widgets import event_object_link, event_type_link, event_user_link
class EventsApp(MayanAppConfig):
@@ -33,24 +34,23 @@ class EventsApp(MayanAppConfig):
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'])
func=widget_event_actor_link, label=_('Actor'), source=Action
)
SourceColumn(
source=Action, label=_('Event'),
func=lambda context: event_type_link(context['object'])
func=widget_event_type_link, label=_('Event'), source=Action
)
SourceColumn(
source=Action, label=_('Action object'),
func=lambda context: event_object_link(
entry=context['object'], attribute='action_object'
)
attribute='action_object', label=_('Action object'), source=Action,
widget=ObjectLinkWidget
)
SourceColumn(
attribute='target', label=_('Target'), source=Action,
widget=ObjectLinkWidget
)
SourceColumn(
@@ -64,17 +64,20 @@ class EventsApp(MayanAppConfig):
source=Notification, label=_('Timestamp'),
attribute='action.timestamp'
)
SourceColumn(
source=Notification, label=_('Actor'), attribute='action.actor'
func=widget_event_actor_link, label=_('Actor'),
kwargs={'attribute': 'action'}, source=Notification
)
SourceColumn(
source=Notification, label=_('Event'),
func=lambda context: event_type_link(context['object'].action)
func=widget_event_type_link, label=_('Event'),
kwargs={'attribute': 'action'}, source=Notification
)
SourceColumn(
source=Notification, label=_('Target'),
func=lambda context: event_object_link(context['object'].action)
attribute='action.target', label=_('Target'), source=Notification,
widget=ObjectLinkWidget
)
SourceColumn(
source=Notification, label=_('Seen'),
func=lambda context: TwoStateWidget(
@@ -88,14 +91,13 @@ class EventsApp(MayanAppConfig):
menu_object.bind_links(
links=(link_notification_mark_read,), sources=(Notification,)
)
menu_object.bind_links(
links=(link_user_events,), sources=(User,)
)
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,), position=50
links=(
link_event_types_subscriptions_list, link_current_user_events
), position=50
)