def setup_document_type_metadata(request, document_type_id): check_permissions(request.user, [PERMISSION_DOCUMENT_TYPE_EDIT]) document_type = get_object_or_404(DocumentType, pk=document_type_id) # Initialize defaults DocumentTypeDefaults.objects.get_or_create(document_type=document_type) return assign_remove( request, left_list=lambda: generate_choices_w_labels( get_document_type_metadata_non_members(document_type)), right_list=lambda: generate_choices_w_labels( get_document_type_metadata_members(document_type)), add_method=lambda x: add_document_type_metadata(document_type, x), remove_method=lambda x: remove_document_type_metadata( document_type, x), left_list_title=_(u'non members of document type: %s') % document_type, right_list_title=_(u'members of document type: %s') % document_type, extra_context={ 'document_type': document_type, 'navigation_object_name': 'document_type', 'object_name': _(u'document type'), }, )
def index_setup_document_types(request, index_pk): index = get_object_or_404(Index, pk=index_pk) try: Permission.objects.check_permissions( request.user, [PERMISSION_DOCUMENT_INDEXING_EDIT]) except PermissionDenied: AccessEntry.objects.check_access(PERMISSION_DOCUMENT_INDEXING_EDIT, request.user, index) return assign_remove( request, left_list=lambda: generate_choices_w_labels(index.get_document_types_not_in_index(), display_object_type=False), right_list=lambda: generate_choices_w_labels( index.get_index_document_types(), display_object_type=False), add_method=lambda x: index.document_types.add(x), remove_method=lambda x: index.document_types.remove(x), left_list_title=_(u'document types not in index: %s') % index, right_list_title=_(u'document types for index: %s') % index, decode_content_type=True, extra_context={ 'navigation_object_name': 'index', 'index': index, 'object_name': _(u'index'), })
def smart_link_document_types(request, smart_link_pk): smart_link = get_object_or_404(SmartLink, pk=smart_link_pk) try: Permission.objects.check_permissions(request.user, [PERMISSION_SMART_LINK_EDIT]) except PermissionDenied: AccessEntry.objects.check_access(PERMISSION_SMART_LINK_EDIT, request.user, smart_link) return assign_remove( request, left_list=lambda: generate_choices_w_labels( DocumentType.objects.exclude(pk__in=smart_link.document_types.all( )), display_object_type=False), right_list=lambda: generate_choices_w_labels( smart_link.document_types.all(), display_object_type=False), add_method=lambda x: smart_link.document_types.add(x), remove_method=lambda x: smart_link.document_types.remove(x), decode_content_type=True, extra_context={ 'main_title': _('Document type for which to enable smart link: %s') % smart_link, 'object': smart_link, })
def setup_document_type_metadata_required(request, document_type_id): Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_TYPE_EDIT]) document_type = get_object_or_404(DocumentType, pk=document_type_id) return assign_remove( request, left_list=lambda: generate_choices_w_labels(set( MetadataType.objects.all()) - set( MetadataType.objects.filter(id__in=document_type.metadata. values_list('metadata_type', flat=True))), display_object_type=False), right_list=lambda: generate_choices_w_labels( document_type.metadata.filter(required=True), display_object_type=False), add_method=lambda x: document_type.metadata.create(metadata_type=x, required=True), remove_method=lambda x: x.delete(), extra_context={ 'document_type': document_type, 'navigation_object_name': 'document_type', 'main_title': _('Required metadata types for document type: %s') % document_type, }, decode_content_type=True, )
def role_members(request, role_id): check_permissions(request.user, [PERMISSION_ROLE_EDIT]) role = get_object_or_404(Role, pk=role_id) return assign_remove( request, left_list=lambda: generate_choices_w_labels(get_non_role_members(role)), right_list=lambda: generate_choices_w_labels(get_role_members(role)), add_method=lambda x: add_role_member(role, x), remove_method=lambda x: remove_role_member(role, x), left_list_title=_(u'non members of role: %s') % role, right_list_title=_(u'members of role: %s') % role, obj=role, object_name=_(u'role'), )
def user_groups(request, user_id): Permission.objects.check_permissions(request.user, [PERMISSION_USER_EDIT]) user = get_object_or_404(User, pk=user_id) return assign_remove( request, left_list=lambda: generate_choices_w_labels(get_user_non_groups(user), display_object_type=False), right_list=lambda: generate_choices_w_labels(get_user_groups(user), display_object_type=False), add_method=lambda x: x.user_set.add(user), remove_method=lambda x: x.user_set.remove(user), left_list_title=_("Non groups of user: %s") % user, right_list_title=_("Groups of user: %s") % user, decode_content_type=True, extra_context={"object": user}, )
def group_members(request, group_id): check_permissions(request.user, [PERMISSION_GROUP_EDIT]) group = get_object_or_404(Group, pk=group_id) return assign_remove( request, left_list=lambda: generate_choices_w_labels(get_non_group_members(group), display_object_type=False), right_list=lambda: generate_choices_w_labels(get_group_members(group), display_object_type=False), add_method=lambda x: group.user_set.add(x), remove_method=lambda x: group.user_set.remove(x), left_list_title=_(u"non members of group: %s") % group, right_list_title=_(u"members of group: %s") % group, decode_content_type=True, extra_context={"template_id": u"group_members", "object": group, "object_name": _(u"group")}, )
def setup_metadata_set_edit(request, metadata_set_id): check_permissions(request.user, [PERMISSION_METADATA_SET_EDIT]) metadata_set = get_object_or_404(MetadataSet, pk=metadata_set_id) return assign_remove( request, left_list=lambda: generate_choices_w_labels(get_non_set_members(metadata_set)), right_list=lambda: generate_choices_w_labels(get_set_members(metadata_set)), add_method=lambda x: add_set_member(metadata_set, x), remove_method=lambda x: remove_set_member(metadata_set, x), left_list_title=_(u'non members of metadata set: %s') % metadata_set, right_list_title=_(u'members of metadata set: %s') % metadata_set, obj=metadata_set, object_name=_(u'metadata set'), )
def role_members(request, role_id): Permission.objects.check_permissions(request.user, [PERMISSION_ROLE_EDIT]) role = get_object_or_404(Role, pk=role_id) return assign_remove( request, left_list=lambda: get_non_role_members(role), right_list=lambda: get_role_members(role), add_method=lambda x: add_role_member(role, x), remove_method=lambda x: remove_role_member(role, x), left_list_title=_('Non members of role: %s') % role, right_list_title=_('Members of role: %s') % role, extra_context={ 'object': role, }, grouped=True, )
def setup_document_type_metadata_required(request, document_type_id): Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_TYPE_EDIT]) document_type = get_object_or_404(DocumentType, pk=document_type_id) return assign_remove( request, left_list=lambda: generate_choices_w_labels(set(MetadataType.objects.all()) - set(MetadataType.objects.filter(id__in=document_type.metadata.values_list('metadata_type', flat=True))), display_object_type=False), right_list=lambda: generate_choices_w_labels(document_type.metadata.filter(required=True), display_object_type=False), add_method=lambda x: document_type.metadata.create(metadata_type=x, required=True), remove_method=lambda x: x.delete(), extra_context={ 'document_type': document_type, 'navigation_object_name': 'document_type', 'main_title': _('Required metadata types for document type: %s') % document_type, }, decode_content_type=True, )
def group_members(request, group_id): Permission.objects.check_permissions(request.user, [PERMISSION_GROUP_EDIT]) group = get_object_or_404(Group, pk=group_id) return assign_remove( request, left_list=lambda: generate_choices_w_labels(get_non_group_members(group), display_object_type=False), right_list=lambda: generate_choices_w_labels(get_group_members(group), display_object_type=False), add_method=lambda x: group.user_set.add(x), remove_method=lambda x: group.user_set.remove(x), left_list_title=_(u'non members of group: %s') % group, right_list_title=_(u'members of group: %s') % group, decode_content_type=True, extra_context={ 'object': group, 'object_name': _(u'group'), } )
def setup_metadata_set_members(request, metadata_set_id): Permission.objects.check_permissions(request.user, [PERMISSION_METADATA_SET_EDIT]) metadata_set = get_object_or_404(MetadataSet, pk=metadata_set_id) return assign_remove( request, left_list=lambda: generate_choices_w_labels(get_non_set_members(metadata_set), display_object_type=False), right_list=lambda: generate_choices_w_labels(get_set_members(metadata_set), display_object_type=False), add_method=lambda x: add_set_member(metadata_set, x), remove_method=lambda x: remove_set_member(metadata_set, x), left_list_title=_(u'non members of metadata set: %s') % metadata_set, right_list_title=_(u'members of metadata set: %s') % metadata_set, extra_context={ 'object': metadata_set, 'object_name': _(u'metadata set'), } )
def user_groups(request, user_id): Permission.objects.check_permissions(request.user, [PERMISSION_USER_EDIT]) user = get_object_or_404(User, pk=user_id) return assign_remove( request, left_list=lambda: generate_choices_w_labels(get_user_non_groups(user), display_object_type=False), right_list=lambda: generate_choices_w_labels(get_user_groups(user), display_object_type=False), add_method=lambda x: x.user_set.add(user), remove_method=lambda x: x.user_set.remove(user), left_list_title=_(u'non groups of user: %s') % user, right_list_title=_(u'groups of user: %s') % user, decode_content_type=True, extra_context={ 'object': user, 'object_name': _(u'user'), } )
def setup_metadata_set_edit(request, metadata_set_id): check_permissions(request.user, [PERMISSION_METADATA_SET_EDIT]) metadata_set = get_object_or_404(MetadataSet, pk=metadata_set_id) return assign_remove( request, left_list=lambda: generate_choices_w_labels( get_non_set_members(metadata_set)), right_list=lambda: generate_choices_w_labels( get_set_members(metadata_set)), add_method=lambda x: add_set_member(metadata_set, x), remove_method=lambda x: remove_set_member(metadata_set, x), left_list_title=_(u'non members of metadata set: %s') % metadata_set, right_list_title=_(u'members of metadata set: %s') % metadata_set, extra_context={ 'object': metadata_set, 'object_name': _(u'metadata set'), })
def setup_document_type_metadata(request, document_type_id): check_permissions(request.user, [PERMISSION_DOCUMENT_TYPE_EDIT]) document_type = get_object_or_404(DocumentType, pk=document_type_id) # Initialize defaults DocumentTypeDefaults.objects.get_or_create(document_type=document_type) return assign_remove( request, left_list=lambda: generate_choices_w_labels(get_document_type_metadata_non_members(document_type)), right_list=lambda: generate_choices_w_labels(get_document_type_metadata_members(document_type)), add_method=lambda x: add_document_type_metadata(document_type, x), remove_method=lambda x: remove_document_type_metadata(document_type, x), left_list_title=_(u'non members of document type: %s') % document_type, right_list_title=_(u'members of document type: %s') % document_type, obj=document_type, object_name=_(u'document type'), )
def index_setup_document_types(request, index_pk): index = get_object_or_404(Index, pk=index_pk) try: Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_INDEXING_EDIT]) except PermissionDenied: AccessEntry.objects.check_access(PERMISSION_DOCUMENT_INDEXING_EDIT, request.user, index) return assign_remove( request, left_list=lambda: generate_choices_w_labels(index.get_document_types_not_in_index(), display_object_type=False), right_list=lambda: generate_choices_w_labels(index.get_index_document_types(), display_object_type=False), add_method=lambda x: index.document_types.add(x), remove_method=lambda x: index.document_types.remove(x), left_list_title=_(u"document types not in index: %s") % index, right_list_title=_(u"document types for index: %s") % index, decode_content_type=True, extra_context={"navigation_object_name": "index", "index": index, "object_name": _(u"index")}, )
def role_members(request, role_id): Permission.objects.check_permissions(request.user, [PERMISSION_ROLE_EDIT]) role = get_object_or_404(Role, pk=role_id) return assign_remove( request, #left_list=lambda: generate_choices_w_labels(get_non_role_members(role)), left_list=lambda: get_non_role_members(role), #right_list=lambda: generate_choices_w_labels(get_role_members(role)), right_list=lambda: get_role_members(role), add_method=lambda x: add_role_member(role, x), remove_method=lambda x: remove_role_member(role, x), left_list_title=_(u'non members of role: %s') % role, right_list_title=_(u'members of role: %s') % role, extra_context={ 'object': role, 'object_name': _(u'role'), }, grouped=True, )
def role_members(request, role_id): Permission.objects.check_permissions(request.user, [PERMISSION_ROLE_EDIT]) role = get_object_or_404(Role, pk=role_id) return assign_remove( request, # left_list=lambda: generate_choices_w_labels(get_non_role_members(role)), left_list=lambda: get_non_role_members(role), # right_list=lambda: generate_choices_w_labels(get_role_members(role)), right_list=lambda: get_role_members(role), add_method=lambda x: add_role_member(role, x), remove_method=lambda x: remove_role_member(role, x), left_list_title=_(u'non members of role: %s') % role, right_list_title=_(u'members of role: %s') % role, extra_context={ 'object': role, 'object_name': _(u'role'), }, grouped=True, )
def setup_workflow_document_types(request, pk): workflow = get_object_or_404(Workflow, pk=pk) try: Permission.objects.check_permissions(request.user, [PERMISSION_WORKFLOW_EDIT]) except PermissionDenied: AccessEntry.objects.check_access(PERMISSION_WORKFLOW_EDIT, request.user, workflow) return assign_remove( request, left_list=lambda: generate_choices_w_labels(workflow.get_document_types_not_in_workflow(), display_object_type=False), right_list=lambda: generate_choices_w_labels(workflow.document_types.all(), display_object_type=False), add_method=lambda x: workflow.document_types.add(x), remove_method=lambda x: workflow.document_types.remove(x), decode_content_type=True, extra_context={ 'main_title': _('Document types assigned the workflow: %s') % workflow, 'object': workflow, } )
def smart_link_document_types(request, smart_link_pk): smart_link = get_object_or_404(SmartLink, pk=smart_link_pk) try: Permission.objects.check_permissions(request.user, [PERMISSION_SMART_LINK_EDIT]) except PermissionDenied: AccessEntry.objects.check_access(PERMISSION_SMART_LINK_EDIT, request.user, smart_link) return assign_remove( request, left_list=lambda: generate_choices_w_labels(DocumentType.objects.exclude(pk__in=smart_link.document_types.all()), display_object_type=False), right_list=lambda: generate_choices_w_labels(smart_link.document_types.all(), display_object_type=False), add_method=lambda x: smart_link.document_types.add(x), remove_method=lambda x: smart_link.document_types.remove(x), decode_content_type=True, extra_context={ 'main_title': _('Document type for which to enable smart link: %s') % smart_link, 'object': smart_link, } )
def setup_document_type_metadata(request, document_type_id): Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_TYPE_EDIT]) document_type = get_object_or_404(DocumentType, pk=document_type_id) # Initialize defaults DocumentTypeDefaults.objects.get_or_create(document_type=document_type) return assign_remove( request, left_list=lambda: get_document_type_metadata_non_members(document_type), right_list=lambda: get_document_type_metadata_members(document_type), add_method=lambda x: add_document_type_metadata(document_type, x), remove_method=lambda x: remove_document_type_metadata(document_type, x), left_list_title=_(u'non members of document type: %s') % document_type, right_list_title=_(u'members of document type: %s') % document_type, extra_context={ 'document_type': document_type, 'navigation_object_name': 'document_type', 'object_name': _(u'document type'), }, grouped=True, )