Make generates_choices_w_label a static method of AssignRemove, it's not anywhere else.
This commit is contained in:
@@ -56,20 +56,6 @@ def fs_cleanup(filename, suppress_exceptions=True):
|
||||
raise
|
||||
|
||||
|
||||
def generate_choices_w_labels(choices):
|
||||
results = []
|
||||
for choice in choices:
|
||||
ct = ContentType.objects.get_for_model(choice)
|
||||
label = unicode(choice)
|
||||
if isinstance(choice, User):
|
||||
label = choice.get_full_name() if choice.get_full_name() else choice
|
||||
|
||||
results.append(('%s,%s' % (ct.model, choice.pk), '%s' % (label)))
|
||||
|
||||
# Sort results by the label not the key value
|
||||
return sorted(results, key=lambda x: x[1])
|
||||
|
||||
|
||||
def get_descriptor(file_input, read=True):
|
||||
try:
|
||||
# Is it a file like object?
|
||||
|
||||
@@ -44,6 +44,20 @@ class AssignRemoveView(TemplateView):
|
||||
LEFT_LIST_NAME = 'left_list'
|
||||
RIGHT_LIST_NAME = 'right_list'
|
||||
|
||||
@staticmethod
|
||||
def generate_choices(choices):
|
||||
results = []
|
||||
for choice in choices:
|
||||
ct = ContentType.objects.get_for_model(choice)
|
||||
label = unicode(choice)
|
||||
if isinstance(choice, User):
|
||||
label = choice.get_full_name() if choice.get_full_name() else choice
|
||||
|
||||
results.append(('%s,%s' % (ct.model, choice.pk), '%s' % (label)))
|
||||
|
||||
# Sort results by the label not the key value
|
||||
return sorted(results, key=lambda x: x[1])
|
||||
|
||||
def left_list(self):
|
||||
# Subclass must override
|
||||
return []
|
||||
|
||||
@@ -12,7 +12,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from acls.models import AccessEntry
|
||||
from acls.utils import apply_default_acls
|
||||
from common.utils import encapsulate, generate_choices_w_labels
|
||||
from common.utils import encapsulate
|
||||
from common.views import AssignRemoveView
|
||||
from common.widgets import two_state_template
|
||||
from documents.models import Document
|
||||
@@ -185,10 +185,10 @@ class SetupIndexDocumentTypesView(AssignRemoveView):
|
||||
return super(SetupIndexDocumentTypesView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def left_list(self):
|
||||
return generate_choices_w_labels(self.index.get_document_types_not_in_index())
|
||||
return AssignRemoveView.generate_choices(self.index.get_document_types_not_in_index())
|
||||
|
||||
def right_list(self):
|
||||
return generate_choices_w_labels(self.index.document_types.all())
|
||||
return AssignRemoveView.generate_choices(self.index.document_types.all())
|
||||
|
||||
def remove(self, item):
|
||||
self.index.document_types.remove(item)
|
||||
|
||||
@@ -10,7 +10,6 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.generic import FormView
|
||||
|
||||
from acls.models import AccessEntry
|
||||
from common.utils import generate_choices_w_labels
|
||||
from common.views import (
|
||||
AssignRemoveView, SingleObjectCreateView, SingleObjectDeleteView,
|
||||
SingleObjectEditView, SingleObjectListView
|
||||
@@ -183,10 +182,10 @@ class SetupWorkflowDocumentTypesView(AssignRemoveView):
|
||||
return super(SetupWorkflowDocumentTypesView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def left_list(self):
|
||||
return generate_choices_w_labels(self.workflow.get_document_types_not_in_workflow())
|
||||
return AssignRemoveView.generate_choices(self.workflow.get_document_types_not_in_workflow())
|
||||
|
||||
def right_list(self):
|
||||
return generate_choices_w_labels(self.workflow.document_types.all())
|
||||
return AssignRemoveView.generate_choices(self.workflow.document_types.all())
|
||||
|
||||
def remove(self, item):
|
||||
self.workflow.document_types.remove(item)
|
||||
|
||||
@@ -14,7 +14,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from acls.models import AccessEntry
|
||||
from acls.utils import apply_default_acls
|
||||
from acls.views import acl_list_for
|
||||
from common.utils import encapsulate, generate_choices_w_labels
|
||||
from common.utils import encapsulate
|
||||
from common.views import AssignRemoveView
|
||||
from common.widgets import two_state_template
|
||||
from documents.models import Document, DocumentType
|
||||
@@ -48,10 +48,10 @@ class SetupSmartLinkDocumentTypesView(AssignRemoveView):
|
||||
return super(SetupSmartLinkDocumentTypesView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def left_list(self):
|
||||
return generate_choices_w_labels(DocumentType.objects.exclude(pk__in=self.smart_link.document_types.all()))
|
||||
return AssignRemoveView.generate_choices(DocumentType.objects.exclude(pk__in=self.smart_link.document_types.all()))
|
||||
|
||||
def right_list(self):
|
||||
return generate_choices_w_labels(self.smart_link.document_types.all())
|
||||
return AssignRemoveView.generate_choices(self.smart_link.document_types.all())
|
||||
|
||||
def remove(self, item):
|
||||
self.smart_link.document_types.remove(item)
|
||||
|
||||
@@ -11,6 +11,8 @@ from django.utils.http import urlencode
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext
|
||||
|
||||
from acls.models import AccessEntry
|
||||
from common.utils import encapsulate
|
||||
from common.views import AssignRemoveView
|
||||
from documents.models import Document, DocumentType
|
||||
from documents.permissions import (
|
||||
PERMISSION_DOCUMENT_TYPE_EDIT
|
||||
@@ -18,9 +20,6 @@ from documents.permissions import (
|
||||
from documents.views import DocumentListView
|
||||
from permissions.models import Permission
|
||||
|
||||
from common.utils import encapsulate, generate_choices_w_labels
|
||||
from common.views import AssignRemoveView
|
||||
|
||||
from .api import save_metadata_list
|
||||
from .forms import (
|
||||
AddMetadataForm, MetadataFormSet, MetadataRemoveFormSet, MetadataTypeForm
|
||||
@@ -453,10 +452,10 @@ class SetupDocumentTypeMetadataOptionalView(AssignRemoveView):
|
||||
return super(SetupDocumentTypeMetadataOptionalView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def left_list(self):
|
||||
return generate_choices_w_labels(set(MetadataType.objects.all()) - set(MetadataType.objects.filter(id__in=self.document_type.metadata.values_list('metadata_type', flat=True))))
|
||||
return AssignRemoveView.generate_choices(set(MetadataType.objects.all()) - set(MetadataType.objects.filter(id__in=self.document_type.metadata.values_list('metadata_type', flat=True))))
|
||||
|
||||
def right_list(self):
|
||||
return generate_choices_w_labels(self.document_type.metadata.filter(required=False))
|
||||
return AssignRemoveView.generate_choices(self.document_type.metadata.filter(required=False))
|
||||
|
||||
def remove(self, item):
|
||||
item.delete()
|
||||
@@ -477,7 +476,7 @@ class SetupDocumentTypeMetadataRequiredView(SetupDocumentTypeMetadataOptionalVie
|
||||
self.document_type.metadata.create(metadata_type=item, required=True)
|
||||
|
||||
def right_list(self):
|
||||
return generate_choices_w_labels(self.document_type.metadata.filter(required=True))
|
||||
return AssignRemoveView.generate_choices(self.document_type.metadata.filter(required=True))
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super(SetupDocumentTypeMetadataRequiredView, self).get_context_data(**kwargs)
|
||||
|
||||
@@ -10,7 +10,7 @@ from django.shortcuts import get_object_or_404, render_to_response
|
||||
from django.template import RequestContext
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common.utils import encapsulate, generate_choices_w_labels
|
||||
from common.utils import encapsulate
|
||||
from common.views import AssignRemoveView
|
||||
from common.widgets import two_state_template
|
||||
from permissions.models import Permission
|
||||
@@ -234,10 +234,10 @@ class UserGroupsView(AssignRemoveView):
|
||||
return super(UserGroupsView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def left_list(self):
|
||||
return generate_choices_w_labels(get_user_non_groups(self.user))
|
||||
return AssignRemoveView.generate_choices(get_user_non_groups(self.user))
|
||||
|
||||
def right_list(self):
|
||||
return generate_choices_w_labels(get_user_groups(self.user))
|
||||
return AssignRemoveView.generate_choices(get_user_groups(self.user))
|
||||
|
||||
def remove(self, item):
|
||||
item.user_set.remove(self.user)
|
||||
@@ -373,10 +373,10 @@ class GroupMembersView(AssignRemoveView):
|
||||
return super(GroupMembersView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def left_list(self):
|
||||
return generate_choices_w_labels(User.objects.exclude(groups=self.group).exclude(is_staff=True).exclude(is_superuser=True))
|
||||
return AssignRemoveView.generate_choices(User.objects.exclude(groups=self.group).exclude(is_staff=True).exclude(is_superuser=True))
|
||||
|
||||
def right_list(self):
|
||||
return generate_choices_w_labels(self.group.user_set.all())
|
||||
return AssignRemoveView.generate_choices(self.group.user_set.all())
|
||||
|
||||
def remove(self, item):
|
||||
self.group.user_set.remove(item)
|
||||
|
||||
Reference in New Issue
Block a user