Fix GitLab issue #245, "Add multiple metadata not possible"
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
2.0.1 (2016-01-xx)
|
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 #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)
|
2.0 (2015-12-04)
|
||||||
================
|
================
|
||||||
|
|||||||
@@ -15,6 +15,15 @@ Required metadata was not enforce correctly
|
|||||||
Fixed a situation where documents having required metadata could still be
|
Fixed a situation where documents having required metadata could still be
|
||||||
uploaded without entering a value for the required metadata.
|
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
|
Other changes
|
||||||
-------------
|
-------------
|
||||||
* None
|
* 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 #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/
|
.. _PyPI: https://pypi.python.org/pypi/mayan-edms/
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.core.files.base import File
|
||||||
from documents.models import DocumentType
|
from documents.models import DocumentType
|
||||||
from documents.permissions import (
|
from documents.permissions import (
|
||||||
permission_document_properties_edit, permission_document_view
|
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 documents.tests.test_views import GenericDocumentViewTestCase
|
||||||
from user_management.tests.literals import (
|
from user_management.tests.literals import (
|
||||||
TEST_USER_USERNAME, TEST_USER_PASSWORD
|
TEST_USER_USERNAME, TEST_USER_PASSWORD
|
||||||
@@ -77,7 +80,7 @@ class DocumentMetadataTestCase(GenericDocumentViewTestCase):
|
|||||||
|
|
||||||
def test_metadata_edit_after_document_type_change(self):
|
def test_metadata_edit_after_document_type_change(self):
|
||||||
# Gitlab issue #204
|
# 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(
|
self.login(
|
||||||
username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD
|
username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD
|
||||||
@@ -206,3 +209,65 @@ class DocumentMetadataTestCase(GenericDocumentViewTestCase):
|
|||||||
self.assertContains(response, 'Success', status_code=200)
|
self.assertContains(response, 'Success', status_code=200)
|
||||||
|
|
||||||
self.assertEqual(len(self.document.metadata.all()), 0)
|
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)
|
||||||
|
|||||||
@@ -93,21 +93,21 @@ def metadata_edit(request, document_id=None, document_id_list=None):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
metadata = {}
|
metadata_dict = {}
|
||||||
initial = []
|
initial = []
|
||||||
|
|
||||||
for document in documents:
|
for document in documents:
|
||||||
document.add_as_recent_document_for_user(request.user)
|
document.add_as_recent_document_for_user(request.user)
|
||||||
|
|
||||||
for item in document.metadata.all():
|
for document_metadata in document.metadata.all():
|
||||||
value = item.value
|
metadata_dict.setdefault(document_metadata.metadata_type, set())
|
||||||
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 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({
|
initial.append({
|
||||||
'document_type': document.document_type,
|
'document_type': document.document_type,
|
||||||
'metadata_type': key,
|
'metadata_type': key,
|
||||||
@@ -293,7 +293,7 @@ def metadata_add(request, document_id=None, document_id_list=None):
|
|||||||
elif documents.count() > 1:
|
elif documents.count() > 1:
|
||||||
return HttpResponseRedirect('%s?%s' % (
|
return HttpResponseRedirect('%s?%s' % (
|
||||||
reverse('metadata:metadata_multiple_edit'),
|
reverse('metadata:metadata_multiple_edit'),
|
||||||
urlencode({'id_list': document_id_list, 'next': next}))
|
urlencode({'id_list': ','.join(document_id_list), 'next': next}))
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user