Fix GitLab issue #245, "Add multiple metadata not possible"

This commit is contained in:
Roberto Rosario
2016-01-12 03:44:47 -04:00
parent 79c5a103a2
commit 460076004a
4 changed files with 88 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
2.0.1 (2016-01-xx)
==================
- Fix GitLab issue #243, "System allows a user to skip entering values for a required metadata field while uploading a new document"
- Fix GitLab issue #245, "Add multiple metadata not possible"
2.0 (2015-12-04)
================

View File

@@ -15,6 +15,15 @@ Required metadata was not enforce correctly
Fixed a situation where documents having required metadata could still be
uploaded without entering a value for the required metadata.
Fix multiple document metadata adding
-------------------------------------
Fixed a bug when adding metadata to multiple documents.
Fix multiple document metadata editing
--------------------------------------
Fixed a bug that made it impossible to edit multiple documents' metadata values
if one of the documents had no previous value for it's metadata.
Other changes
-------------
* None
@@ -73,5 +82,6 @@ Bugs fixed or issues closed
===========================
* `GitLab issue #243 <https://gitlab.com/mayan-edms/mayan-edms/issues/243>`_ System allows a user to skip entering values for a required metadata field while uploading a new document
* `GitLab issue #245 <https://gitlab.com/mayan-edms/mayan-edms/issues/245>`_ Add multiple metadata not possible
.. _PyPI: https://pypi.python.org/pypi/mayan-edms/

View File

@@ -1,10 +1,13 @@
from __future__ import unicode_literals
from django.core.files.base import File
from documents.models import DocumentType
from documents.permissions import (
permission_document_properties_edit, permission_document_view
)
from documents.tests.literals import TEST_DOCUMENT_TYPE_2
from documents.tests.literals import (
TEST_DOCUMENT_TYPE_2, TEST_SMALL_DOCUMENT_PATH
)
from documents.tests.test_views import GenericDocumentViewTestCase
from user_management.tests.literals import (
TEST_USER_USERNAME, TEST_USER_PASSWORD
@@ -77,7 +80,7 @@ class DocumentMetadataTestCase(GenericDocumentViewTestCase):
def test_metadata_edit_after_document_type_change(self):
# Gitlab issue #204
# Problems to add required metadata after changin the document type
# Problems to add required metadata after changing the document type
self.login(
username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD
@@ -206,3 +209,65 @@ class DocumentMetadataTestCase(GenericDocumentViewTestCase):
self.assertContains(response, 'Success', status_code=200)
self.assertEqual(len(self.document.metadata.all()), 0)
def test_multiple_document_metadata_edit(self):
self.login(
username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD
)
self.role.permissions.add(
permission_document_view.stored_permission
)
self.role.permissions.add(
permission_metadata_document_add.stored_permission
)
self.role.permissions.add(
permission_metadata_document_edit.stored_permission
)
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document_2 = self.document_type.new_document(
file_object=File(file_object)
)
self.document.metadata.create(metadata_type=self.metadata_type)
document_2.metadata.create(metadata_type=self.metadata_type)
response = self.get(
'metadata:metadata_multiple_edit', data={
'id_list': '{},{}'.format(self.document.pk, document_2.pk)
}
)
self.assertContains(response, 'Edit', status_code=200)
def test_multiple_document_metadata_add(self):
self.login(
username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD
)
self.role.permissions.add(
permission_document_view.stored_permission
)
self.role.permissions.add(
permission_metadata_document_add.stored_permission
)
self.role.permissions.add(
permission_metadata_document_edit.stored_permission
)
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document_2 = self.document_type.new_document(
file_object=File(file_object)
)
response = self.post(
'metadata:metadata_multiple_add', data={
'id_list': '{},{}'.format(self.document.pk, document_2.pk),
'metadata_type': self.metadata_type.pk
}, follow=True
)
self.assertContains(response, 'Edit', status_code=200)

View File

@@ -93,21 +93,21 @@ def metadata_edit(request, document_id=None, document_id_list=None):
)
)
metadata = {}
metadata_dict = {}
initial = []
for document in documents:
document.add_as_recent_document_for_user(request.user)
for item in document.metadata.all():
value = item.value
if item.metadata_type in metadata:
if value not in metadata[item.metadata_type]:
metadata[item.metadata_type].append(value)
else:
metadata[item.metadata_type] = [value] if value else []
for document_metadata in document.metadata.all():
metadata_dict.setdefault(document_metadata.metadata_type, set())
for key, value in metadata.items():
if document_metadata.value:
metadata_dict[
document_metadata.metadata_type
].add(document_metadata.value)
for key, value in metadata_dict.items():
initial.append({
'document_type': document.document_type,
'metadata_type': key,
@@ -293,7 +293,7 @@ def metadata_add(request, document_id=None, document_id_list=None):
elif documents.count() > 1:
return HttpResponseRedirect('%s?%s' % (
reverse('metadata:metadata_multiple_edit'),
urlencode({'id_list': document_id_list, 'next': next}))
urlencode({'id_list': ','.join(document_id_list), 'next': next}))
)
else: