From a5e922416b7df63c2781aaaa0c0ec2471082ce66 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 23 Jun 2015 03:13:28 -0400 Subject: [PATCH] Make generates_choices_w_label a static method of AssignRemove, it's not anywhere else. --- mayan/apps/common/utils.py | 14 -------------- mayan/apps/common/views.py | 14 ++++++++++++++ mayan/apps/document_indexing/views.py | 6 +++--- mayan/apps/document_states/views.py | 5 ++--- mayan/apps/linking/views.py | 6 +++--- mayan/apps/metadata/views.py | 11 +++++------ mayan/apps/user_management/views.py | 10 +++++----- 7 files changed, 32 insertions(+), 34 deletions(-) diff --git a/mayan/apps/common/utils.py b/mayan/apps/common/utils.py index 50706d1239..04e44f3316 100644 --- a/mayan/apps/common/utils.py +++ b/mayan/apps/common/utils.py @@ -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? diff --git a/mayan/apps/common/views.py b/mayan/apps/common/views.py index 4742b6d162..10169ddd85 100644 --- a/mayan/apps/common/views.py +++ b/mayan/apps/common/views.py @@ -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 [] diff --git a/mayan/apps/document_indexing/views.py b/mayan/apps/document_indexing/views.py index 2f2ff55225..24828e9154 100644 --- a/mayan/apps/document_indexing/views.py +++ b/mayan/apps/document_indexing/views.py @@ -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) diff --git a/mayan/apps/document_states/views.py b/mayan/apps/document_states/views.py index cc59234e95..d3e4c58ae3 100644 --- a/mayan/apps/document_states/views.py +++ b/mayan/apps/document_states/views.py @@ -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) diff --git a/mayan/apps/linking/views.py b/mayan/apps/linking/views.py index eb75860187..5b265e980d 100644 --- a/mayan/apps/linking/views.py +++ b/mayan/apps/linking/views.py @@ -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) diff --git a/mayan/apps/metadata/views.py b/mayan/apps/metadata/views.py index 5d5626c588..deeb616294 100644 --- a/mayan/apps/metadata/views.py +++ b/mayan/apps/metadata/views.py @@ -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) diff --git a/mayan/apps/user_management/views.py b/mayan/apps/user_management/views.py index 534b3ecc4b..798302d028 100644 --- a/mayan/apps/user_management/views.py +++ b/mayan/apps/user_management/views.py @@ -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)