Merge branch 'master' into feature/merge_master

This commit is contained in:
Roberto Rosario
2016-03-03 16:46:11 -04:00
24 changed files with 194 additions and 181 deletions

View File

@@ -1,8 +1,8 @@
from __future__ import unicode_literals
__title__ = 'Mayan EDMS'
__version__ = '2.0.1'
__build__ = 0x020001
__version__ = '2.0.2'
__build__ = 0x020002
__author__ = 'Roberto Rosario'
__author_email__ = 'roberto.rosario@mayan-edms.com'
__description__ = 'Free Open Source Electronic Document Management System'

View File

@@ -1,7 +1,7 @@
{% load i18n %}
{% if title %}
{{ title }}
{{ title|striptags }}
{% else %}
{% if read_only %}
{% blocktrans %}Details for: {{ object }}{% endblocktrans %}

View File

@@ -2,6 +2,8 @@
{% load i18n %}
{% block title %}{% include 'appearance/calculate_form_title.html' %}{% endblock %}
{% block content %}
<h3>{% include 'appearance/calculate_form_title.html' %}</h3>
<hr>

View File

@@ -2,6 +2,8 @@
from __future__ import unicode_literals
import time
from django.core.files import File
from django.core.urlresolvers import reverse
@@ -37,6 +39,10 @@ class DocumentsLinksTestCase(GenericDocumentViewTestCase):
self.assertEqual(resolved_link, None)
def test_document_version_revert_link_with_permission(self):
# Needed by MySQL as milliseconds value is not store in timestamp
# field
time.sleep(2)
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document.new_version(file_object=File(file_object))

View File

@@ -85,8 +85,8 @@ class DocumentTestCase(TestCase):
def test_auto_trashing(self):
"""
Test document type trashing policies. Documents are moved to the trash,
x amount of time after being uploaded
Test document type trashing policies. Documents are moved to the
trash, x amount of time after being uploaded
"""
self.document_type.trash_time_period = 1
@@ -94,7 +94,9 @@ class DocumentTestCase(TestCase):
self.document_type.trash_time_unit = 'seconds'
self.document_type.save()
time.sleep(1)
# Needed by MySQL as milliseconds value is not store in timestamp
# field
time.sleep(2)
self.assertEqual(Document.objects.count(), 1)
self.assertEqual(DeletedDocument.objects.count(), 0)
@@ -123,6 +125,8 @@ class DocumentTestCase(TestCase):
self.assertEqual(Document.objects.count(), 0)
self.assertEqual(DeletedDocument.objects.count(), 1)
# Needed by MySQL as milliseconds value is not store in timestamp
# field
time.sleep(2)
DocumentType.objects.check_delete_periods()
@@ -216,8 +220,9 @@ class DocumentVersionTestCase(TestCase):
def test_revert_version(self):
self.assertEqual(self.document.versions.count(), 1)
# Needed by MySQL as milliseconds value is not store in timestamp field
time.sleep(1)
# Needed by MySQL as milliseconds value is not store in timestamp
# field
time.sleep(2)
with open(TEST_DOCUMENT_PATH) as file_object:
self.document.new_version(

View File

@@ -79,10 +79,14 @@ class MetadataForm(forms.Form):
attrs={'readonly': 'readonly'}
)
def clean_value(self):
return self.metadata_type.validate_value(
document_type=self.document_type, value=self.cleaned_data['value']
)
def clean(self):
if self.cleaned_data.get('update') and hasattr(self, 'metadata_type'):
self.cleaned_data['value'] = self.metadata_type.validate_value(
document_type=self.document_type,
value=self.cleaned_data.get('value')
)
return self.cleaned_data
MetadataFormSet = formset_factory(MetadataForm, extra=0)

View File

@@ -126,7 +126,7 @@ class MetadataType(models.Model):
if self.lookup:
lookup_options = self.get_lookup_values()
if value not in lookup_options:
if value and value not in lookup_options:
raise ValidationError(
_('Value is not one of the provided options.')
)

View File

@@ -63,8 +63,9 @@ class MetadataTestCase(TestCase):
self.document.metadata_value_of.test, TEST_DEFAULT_VALUE
)
def test_lookup(self):
def test_lookup_with_incorrect_value(self):
self.metadata_type.lookup = TEST_LOOKUP_TEMPLATE
self.metadata_type.save()
document_metadata = DocumentMetadata(
document=self.document, metadata_type=self.metadata_type,
@@ -76,8 +77,15 @@ class MetadataTestCase(TestCase):
document_metadata.full_clean()
document_metadata.save()
# Should not return error
document_metadata.value = TEST_CORRECT_LOOKUP_VALUE
def test_lookup_with_correct_value(self):
self.metadata_type.lookup = TEST_LOOKUP_TEMPLATE
self.metadata_type.save()
document_metadata = DocumentMetadata(
document=self.document, metadata_type=self.metadata_type,
value=TEST_CORRECT_LOOKUP_VALUE
)
document_metadata.full_clean()
document_metadata.save()
@@ -85,6 +93,22 @@ class MetadataTestCase(TestCase):
self.document.metadata_value_of.test, TEST_CORRECT_LOOKUP_VALUE
)
def test_empty_optional_lookup(self):
"""
Checks for GitLab issue #250
Empty optional lookup metadata trigger validation error
"""
self.metadata_type.lookup = TEST_LOOKUP_TEMPLATE
self.metadata_type.save()
document_metadata = DocumentMetadata(
document=self.document, metadata_type=self.metadata_type
)
document_metadata.full_clean()
document_metadata.save()
def test_validation(self):
self.metadata_type.validation = TEST_DATE_VALIDATOR

View File

@@ -2,7 +2,7 @@ from __future__ import absolute_import, unicode_literals
from django.conf import settings
from django.contrib import messages
from django.core.exceptions import PermissionDenied
from django.core.exceptions import PermissionDenied, ValidationError
from django.core.urlresolvers import reverse, reverse_lazy
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render_to_response
@@ -125,20 +125,24 @@ def metadata_edit(request, document_id=None, document_id_list=None):
except Exception as exception:
errors.append(exception)
if errors:
for error in errors:
if settings.DEBUG:
raise
for error in errors:
if settings.DEBUG:
raise
else:
if isinstance(error, ValidationError):
exception_message = ', '.join(error.messages)
else:
messages.error(
request, _(
'Error editing metadata for document: '
'%(document)s; %(exception)s.'
) % {
'document': document,
'exception': ', '.join(exception.messages)
}
)
exception_message = unicode(error)
messages.error(
request, _(
'Error editing metadata for document: '
'%(document)s; %(exception)s.'
) % {
'document': document,
'exception': exception_message
}
)
else:
messages.success(
request,

View File

@@ -71,11 +71,11 @@ class OCRAPITestCase(APITestCase):
self.assertTrue('Mayan EDMS Documentation' in content)
def test_get_document_version_content(self):
def test_get_document_version_page_content(self):
response = self.client.get(
reverse(
'rest_api:document-page-content-view',
args=(self.document.latest_version.pk,)
args=(self.document.latest_version.pages.first().pk,)
),
)

View File

@@ -104,8 +104,9 @@ class DocumentCreateWizard(ViewPermissionCheckMixin, SessionWizardView):
try:
for identifier, metadata in enumerate(self.get_cleaned_data_for_step(STEP_METADATA)):
query_dict['metadata%s_id' % identifier] = metadata['id']
query_dict['metadata%s_value' % identifier] = metadata['value']
if metadata.get('update'):
query_dict['metadata%s_id' % identifier] = metadata['id']
query_dict['metadata%s_value' % identifier] = metadata['value']
except TypeError:
pass