Replace index, workflow, document and statistics views that use 'object_list' to SingleObjectListView class.

This commit is contained in:
Roberto Rosario
2015-08-15 01:07:52 -04:00
parent c6b20f13cc
commit c84ac0a2fc
5 changed files with 121 additions and 111 deletions
+36 -26
View File
@@ -1,52 +1,62 @@
from __future__ import unicode_literals
from django.http import Http404
from django.utils.translation import ugettext_lazy as _
from common.views import SimpleView
from common.views import SingleObjectListView
from .classes import Statistic, StatisticNamespace
from .permissions import permission_statistics_view
class NamespaceListView(SimpleView):
class NamespaceListView(SingleObjectListView):
extra_context = {
'hide_link': True,
'title': _('Statistics namespaces'),
}
template_name = 'appearance/generic_list.html'
view_permission = permission_statistics_view
def get_queryset(self):
return StatisticNamespace.get_all()
class NamespaceDetailView(SingleObjectListView):
template_name = 'appearance/generic_list.html'
view_permission = permission_statistics_view
def get_extra_context(self):
return {
'hide_link': True,
'object_list': StatisticNamespace.get_all(),
'title': _('Statistics namespaces'),
'object': self.get_namespace(),
'title': _('Namespace details for: %s') % self.get_namespace(),
}
def get_namespace(self):
return StatisticNamespace.get(self.kwargs['namespace_id'])
class NamespaceDetailView(SimpleView):
def get_queryset(self):
return self.get_namespace().statistics
class StatisticExecute(SingleObjectListView):
template_name = 'appearance/generic_list.html'
view_permission = permission_statistics_view
def get_extra_context(self):
namespace = StatisticNamespace.get(self.kwargs['namespace_id'])
return {
'hide_link': True,
'object': namespace,
'object_list': namespace.statistics,
'title': _('Namespace details for: %s') % namespace,
}
class StatisticExecute(SimpleView):
template_name = 'appearance/generic_list.html'
view_permission = permission_statistics_view
def get_extra_context(self):
statictic = Statistic.get(self.kwargs['statistic_id'])
return {
'hide_link': True,
'namespace': statictic.namespace,
'namespace': self.get_statictic().namespace,
'navigation_object_list': ('namespace', 'object'),
'object': statictic,
'object_list': statictic.get_results(),
'title': _('Results for: %s') % statictic,
'object': self.get_statictic(),
'title': _('Results for: %s') % self.get_statictic(),
}
def get_queryset(self):
return self.get_statictic().get_results()
def get_statictic(self):
try:
return Statistic.get(self.kwargs['statistic_id'])
except KeyError:
raise Http404(_('Statistic "%s" not found.') % self.kwargs['statistic_id'])