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>
This commit is contained in:
+28
-23
@@ -18,7 +18,9 @@ from .links import (
|
||||
link_notification_mark_read_all, link_user_events,
|
||||
link_user_notifications_list
|
||||
)
|
||||
from .widgets import event_object_link, event_type_link, event_user_link
|
||||
from .widgets import (
|
||||
widget_event_object_link, widget_event_type_link, widget_event_user_link
|
||||
)
|
||||
|
||||
|
||||
class EventsApp(MayanAppConfig):
|
||||
@@ -37,21 +39,22 @@ class EventsApp(MayanAppConfig):
|
||||
User = get_user_model()
|
||||
|
||||
SourceColumn(
|
||||
source=Action, label=_('Timestamp'), attribute='timestamp'
|
||||
attribute='timestamp', is_identifier=True,
|
||||
label=_('Date and time'), source=Action
|
||||
)
|
||||
SourceColumn(
|
||||
source=Action, label=_('Actor'),
|
||||
func=lambda context: event_user_link(context['object'])
|
||||
func=widget_event_user_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'
|
||||
)
|
||||
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(
|
||||
@@ -62,25 +65,27 @@ class EventsApp(MayanAppConfig):
|
||||
)
|
||||
|
||||
SourceColumn(
|
||||
source=Notification, label=_('Timestamp'),
|
||||
attribute='action.timestamp'
|
||||
attribute='action.timestamp', is_identifier=True,
|
||||
label=_('Date and time'), source=Notification
|
||||
|
||||
)
|
||||
SourceColumn(
|
||||
source=Notification, label=_('Actor'), attribute='action.actor'
|
||||
func=widget_event_user_link, kwargs={'attribute': 'action'},
|
||||
label=_('Actor'), source=Notification
|
||||
)
|
||||
SourceColumn(
|
||||
source=Notification, label=_('Event'),
|
||||
func=lambda context: event_type_link(context['object'].action)
|
||||
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(
|
||||
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()
|
||||
attribute='read', label=_('Seen'), source=Notification,
|
||||
widget=TwoStateWidget
|
||||
)
|
||||
|
||||
menu_list_facet.bind_links(
|
||||
|
||||
@@ -32,10 +32,6 @@ def get_kwargs_factory(variable_name):
|
||||
return get_kwargs
|
||||
|
||||
|
||||
def get_notification_count(context):
|
||||
return context['request'].user.notifications.filter(read=False).count()
|
||||
|
||||
|
||||
link_current_user_events = Link(
|
||||
icon_class=icon_events_user_list, text=_('My events'),
|
||||
view='events:current_user_events'
|
||||
|
||||
@@ -13,7 +13,6 @@ from actstream.models import Action, any_stream
|
||||
|
||||
from mayan.apps.acls.models import AccessControlList
|
||||
from mayan.apps.common.generics import FormView, SimpleView
|
||||
from mayan.apps.common.utils import encapsulate
|
||||
from mayan.apps.common.views import SingleObjectListView
|
||||
|
||||
from .classes import EventType, ModelEventType
|
||||
@@ -26,7 +25,6 @@ from .icons import (
|
||||
from .links import link_event_types_subscriptions_list
|
||||
from .models import StoredEventType
|
||||
from .permissions import permission_events_view
|
||||
from .widgets import event_object_link
|
||||
|
||||
|
||||
class EventListView(SingleObjectListView):
|
||||
@@ -34,14 +32,6 @@ class EventListView(SingleObjectListView):
|
||||
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'extra_columns': (
|
||||
{
|
||||
'name': _('Target'),
|
||||
'attribute': encapsulate(
|
||||
lambda entry: event_object_link(entry)
|
||||
)
|
||||
},
|
||||
),
|
||||
'hide_object': True,
|
||||
'title': _('Events'),
|
||||
}
|
||||
@@ -270,14 +260,6 @@ class UserEventListView(SingleObjectListView):
|
||||
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'extra_columns': (
|
||||
{
|
||||
'name': _('Target'),
|
||||
'attribute': encapsulate(
|
||||
lambda entry: event_object_link(entry)
|
||||
)
|
||||
},
|
||||
),
|
||||
'hide_object': True,
|
||||
'no_results_icon': icon_events_user_list,
|
||||
'no_results_text': _(
|
||||
@@ -308,14 +290,6 @@ class CurrentUserEventListView(UserEventListView):
|
||||
class VerbEventListView(SingleObjectListView):
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'extra_columns': (
|
||||
{
|
||||
'name': _('Target'),
|
||||
'attribute': encapsulate(
|
||||
lambda entry: event_object_link(entry)
|
||||
)
|
||||
},
|
||||
),
|
||||
'hide_object': True,
|
||||
'title': _(
|
||||
'Events of type: %s'
|
||||
|
||||
@@ -5,15 +5,18 @@ from django.utils.encoding import force_text
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.common.utils import resolve_attribute
|
||||
|
||||
from .classes import EventType
|
||||
|
||||
|
||||
def event_object_link(entry, attribute='target'):
|
||||
def widget_event_object_link(context, attribute='target'):
|
||||
entry = context['object']
|
||||
label = ''
|
||||
url = '#'
|
||||
obj_type = ''
|
||||
|
||||
obj = getattr(entry, attribute)
|
||||
obj = resolve_attribute(obj=entry, attribute=attribute)
|
||||
|
||||
if obj:
|
||||
obj_type = '{}: '.format(obj._meta.verbose_name)
|
||||
@@ -28,7 +31,12 @@ def event_object_link(entry, attribute='target'):
|
||||
)
|
||||
|
||||
|
||||
def event_type_link(entry):
|
||||
def widget_event_type_link(context, attribute=None):
|
||||
entry = context['object']
|
||||
|
||||
if attribute:
|
||||
entry = getattr(entry, attribute)
|
||||
|
||||
return mark_safe(
|
||||
'<a href="%(url)s">%(label)s</a>' % {
|
||||
'url': reverse('events:events_by_verb', kwargs={'verb': entry.verb}),
|
||||
@@ -37,7 +45,12 @@ def event_type_link(entry):
|
||||
)
|
||||
|
||||
|
||||
def event_user_link(entry):
|
||||
def widget_event_user_link(context, attribute=None):
|
||||
entry = context['object']
|
||||
|
||||
if attribute:
|
||||
entry = getattr(entry, attribute)
|
||||
|
||||
if entry.actor == entry.target:
|
||||
return _('System')
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user