Fix smart link document type assign remove view

This commit is contained in:
Roberto Rosario
2015-07-02 00:57:08 -04:00
parent c6ec9fbc33
commit 70b0996354
2 changed files with 12 additions and 16 deletions

View File

@@ -13,7 +13,7 @@ urlpatterns = patterns(
url(r'^setup/create/$', 'smart_link_create', name='smart_link_create'),
url(r'^setup/(?P<smart_link_pk>\d+)/delete/$', 'smart_link_delete', name='smart_link_delete'),
url(r'^setup/(?P<smart_link_pk>\d+)/edit/$', 'smart_link_edit', name='smart_link_edit'),
url(r'^setup/(?P<smart_link_pk>\d+)/document_types/$', SetupSmartLinkDocumentTypesView.as_view(), name='smart_link_document_types'),
url(r'^setup/(?P<pk>\d+)/document_types/$', SetupSmartLinkDocumentTypesView.as_view(), name='smart_link_document_types'),
url(r'^setup/(?P<smart_link_pk>\d+)/condition/list/$', 'smart_link_condition_list', name='smart_link_condition_list'),
url(r'^setup/(?P<smart_link_pk>\d+)/condition/create/$', 'smart_link_condition_create', name='smart_link_condition_create'),

View File

@@ -32,34 +32,30 @@ logger = logging.getLogger(__name__)
class SetupSmartLinkDocumentTypesView(AssignRemoveView):
decode_content_type = True
left_list_title = _('Available document types')
right_list_title = _('Document types enabled')
object_permission = permission_smart_link_edit
def add(self, item):
self.smart_link.document_types.add(item)
self.get_object().document_types.add(item)
def dispatch(self, request, *args, **kwargs):
self.smart_link = get_object_or_404(SmartLink, pk=self.kwargs['smart_link_pk'])
try:
Permission.check_permissions(self.request.user, [permission_smart_link_edit])
except PermissionDenied:
AccessControlList.objects.check_access(permission_smart_link_edit, self.request.user, self.smart_link)
return super(SetupSmartLinkDocumentTypesView, self).dispatch(request, *args, **kwargs)
def get_object(self):
return get_object_or_404(SmartLink, pk=self.kwargs['pk'])
def left_list(self):
return AssignRemoveView.generate_choices(DocumentType.objects.exclude(pk__in=self.smart_link.document_types.all()))
return AssignRemoveView.generate_choices(DocumentType.objects.exclude(pk__in=self.get_object().document_types.all()))
def right_list(self):
return AssignRemoveView.generate_choices(self.smart_link.document_types.all())
return AssignRemoveView.generate_choices(self.get_object().document_types.all())
def remove(self, item):
self.smart_link.document_types.remove(item)
self.get_object().document_types.remove(item)
def get_context_data(self, **kwargs):
data = super(SetupSmartLinkDocumentTypesView, self).get_context_data(**kwargs)
data.update({
'main_title': _('Document type for which to enable smart link: %s') % self.smart_link,
'object': self.smart_link,
'object': self.get_object(),
'title': _('Document type for which to enable smart link: %s') % self.get_object(),
})
return data