Add link to filter event list by event type, update code to be more up to speed with other apps
This commit is contained in:
@@ -3,9 +3,31 @@ from __future__ import absolute_import
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from project_tools.api import register_tool
|
||||
from navigation.api import register_model_list_columns, register_links
|
||||
from common.utils import encapsulate
|
||||
|
||||
from .permissions import PERMISSION_HISTORY_VIEW
|
||||
from .models import History
|
||||
from .widgets import history_entry_summary, history_entry_type_link
|
||||
|
||||
history_list = {'text': _(u'history'), 'view': 'history_list', 'famfam': 'book', 'icon': 'book.png', 'children_view_regex': [r'history_[l,v]']}
|
||||
history_details = {'text': _(u'details'), 'view': 'history_view', 'famfam': 'book_open', 'args': 'object.pk'}
|
||||
|
||||
register_tool(history_list)
|
||||
|
||||
register_model_list_columns(History, [
|
||||
{
|
||||
'name': _(u'date and time'),
|
||||
'attribute': 'datetime'
|
||||
},
|
||||
{
|
||||
'name': _(u'type'),
|
||||
'attribute': encapsulate(lambda entry: history_entry_type_link(entry))
|
||||
},
|
||||
{
|
||||
'name': _(u'summary'),
|
||||
'attribute': encapsulate(lambda entry: unicode(entry.get_processed_summary()))
|
||||
}
|
||||
])
|
||||
|
||||
register_links(History, [history_details])
|
||||
|
||||
@@ -19,7 +19,14 @@ class HistoryType(models.Model):
|
||||
name = models.CharField(max_length=64, verbose_name=_(u'name'))
|
||||
|
||||
def __unicode__(self):
|
||||
return u'%s - %s' % (self.namespace, self.name)
|
||||
try:
|
||||
return unicode(history_types_dict[self.namespace][self.name]['label'])
|
||||
except KeyError:
|
||||
return u'obsolete history type: %s - %s' % (self.namespace, self.name)
|
||||
|
||||
@models.permalink
|
||||
def get_absolute_url(self):
|
||||
return ('history_type_list', [self.pk])
|
||||
|
||||
class Meta:
|
||||
ordering = ('namespace', 'name')
|
||||
|
||||
@@ -4,4 +4,5 @@ urlpatterns = patterns('history.views',
|
||||
url(r'^list/$', 'history_list', (), 'history_list'),
|
||||
url(r'^list/for_object/(?P<app_label>[\w\-]+)/(?P<module_name>[\w\-]+)/(?P<object_id>\d+)/$', 'history_for_object', (), 'history_for_object'),
|
||||
url(r'^(?P<object_id>\d+)/$', 'history_view', (), 'history_view'),
|
||||
url(r'^type/(?P<history_type_pk>\d+)/list/$', 'history_type_list', (), 'history_type_list'),
|
||||
)
|
||||
|
||||
@@ -13,7 +13,7 @@ from permissions.models import Permission
|
||||
from common.utils import encapsulate
|
||||
from acls.models import AccessEntry
|
||||
|
||||
from .models import History
|
||||
from .models import History, HistoryType
|
||||
from .forms import HistoryDetailForm
|
||||
from .permissions import PERMISSION_HISTORY_VIEW
|
||||
from .widgets import history_entry_object_link, history_entry_summary
|
||||
@@ -37,17 +37,9 @@ def history_list(request, object_list=None, title=None, extra_context=None):
|
||||
'title': title if title else _(u'history events'),
|
||||
'extra_columns': [
|
||||
{
|
||||
'name': _(u'date and time'),
|
||||
'attribute': 'datetime'
|
||||
},
|
||||
{
|
||||
'name': _(u'object'),
|
||||
'name': _(u'object link'),
|
||||
'attribute': encapsulate(lambda x: history_entry_object_link(x))
|
||||
},
|
||||
{
|
||||
'name': _(u'summary'),
|
||||
'attribute': encapsulate(lambda x: history_entry_summary(x))
|
||||
}
|
||||
],
|
||||
'hide_object': True,
|
||||
}
|
||||
@@ -75,16 +67,6 @@ def history_for_object(request, app_label, module_name, object_id):
|
||||
'object_list': History.objects.filter(content_type=content_type, object_id=object_id),
|
||||
'title': _(u'history events for: %s') % content_object,
|
||||
'object': content_object,
|
||||
'extra_columns': [
|
||||
{
|
||||
'name': _(u'date and time'),
|
||||
'attribute': 'datetime'
|
||||
},
|
||||
{
|
||||
'name': _(u'summary'),
|
||||
'attribute': encapsulate(lambda x: history_entry_summary(x))
|
||||
}
|
||||
],
|
||||
'hide_object': True,
|
||||
}
|
||||
|
||||
@@ -113,3 +95,13 @@ def history_view(request, object_id):
|
||||
'form': form,
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def history_type_list(request, history_type_pk):
|
||||
history_type = get_object_or_404(HistoryType, pk=history_type_pk)
|
||||
|
||||
return history_list(
|
||||
request,
|
||||
object_list=History.objects.filter(history_type=history_type),
|
||||
title=_(u'history events of type: %s') % history_type,
|
||||
)
|
||||
|
||||
@@ -14,3 +14,11 @@ def history_entry_summary(entry):
|
||||
'url': entry.get_absolute_url(),
|
||||
'label': unicode(entry.get_processed_summary())
|
||||
})
|
||||
|
||||
|
||||
def history_entry_type_link(entry):
|
||||
return mark_safe(u'<a href="%(url)s">%(label)s</a>' % {
|
||||
'url': entry.history_type.get_absolute_url(),
|
||||
'label': unicode(entry.history_type)
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user