Remove use of extra_columns and move logic to models and apps.

This commit is contained in:
Roberto Rosario
2015-08-16 00:12:51 -04:00
parent 5563484ae8
commit be358f7879
3 changed files with 16 additions and 20 deletions

View File

@@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from common import MayanAppConfig, menu_object, menu_sidebar from common import MayanAppConfig, menu_object, menu_sidebar
from navigation import SourceColumn
from .links import link_acl_new, link_acl_delete, link_acl_permissions from .links import link_acl_new, link_acl_delete, link_acl_permissions
from .models import AccessControlList from .models import AccessControlList
@@ -15,6 +16,14 @@ class ACLsApp(MayanAppConfig):
def ready(self): def ready(self):
super(ACLsApp, self).ready() super(ACLsApp, self).ready()
SourceColumn(
source=AccessControlList, label=_('Permissions'),
attribute='get_permission_titles'
)
SourceColumn(
source=AccessControlList, label=_('Role'), attribute='role'
)
menu_object.bind_links( menu_object.bind_links(
links=(link_acl_permissions, link_acl_delete), links=(link_acl_permissions, link_acl_delete),
sources=(AccessControlList,) sources=(AccessControlList,)

View File

@@ -51,3 +51,10 @@ class AccessControlList(models.Model):
return AccessControlList.objects.get_inherited_permissions( return AccessControlList.objects.get_inherited_permissions(
role=self.role, obj=self.content_object role=self.role, obj=self.content_object
) )
def get_permission_titles(self):
result = ', '.join(
[unicode(permission) for permission in self.permissions.all()]
)
return result or _('None')

View File

@@ -26,12 +26,6 @@ logger = logging.getLogger(__name__)
class ACLListView(SingleObjectListView): class ACLListView(SingleObjectListView):
@staticmethod
def permission_titles(permission_list):
return ', '.join(
[unicode(permission) for permission in permission_list]
)
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
self.content_type = get_object_or_404( self.content_type = get_object_or_404(
ContentType, app_label=self.kwargs['app_label'], ContentType, app_label=self.kwargs['app_label'],
@@ -66,20 +60,6 @@ class ACLListView(SingleObjectListView):
'hide_object': True, 'hide_object': True,
'object': self.content_object, 'object': self.content_object,
'title': _('Access control lists for: %s' % self.content_object), 'title': _('Access control lists for: %s' % self.content_object),
'extra_columns': [
{
'name': _('Role'),
'attribute': 'role'
},
{
'name': _('Permissions'),
'attribute': encapsulate(
lambda entry: ACLListView.permission_titles(
entry.permissions.all()
)
)
},
],
} }