Update documents app

Rename the DeletedDocument proxy model to a TrashedDocument.

Rename the deleted_document views to trashed_document.

Rename the document and deleted_document URL parameters to
trashed_document.

Update URL parameters to the '_id' form.

Add keyword arguments.

Update use of .filter_by_access().

Enclose trashed document restore method in a transaction.

Sort arguments.

Update app for compliance with MERCs 5 and 6.

Add document page view tests.

Add favorite document view tests.

Movernize tests.

Replace use of urlencode with furl.

Update views to use ExternalObjectMixin.

Refactor the document and version download views.

Rename the DocumentDocumentTypeEditView to DocumentChangeTypeView.

Move the trashed document views to their own module.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-01-28 05:25:48 -04:00
parent 7532429b0b
commit 74dfa53787
40 changed files with 1914 additions and 1615 deletions

View File

@@ -151,7 +151,7 @@ class DocumentVersion(models.Model):
def get_absolute_url(self):
return reverse(
viewname='documents:document_version_view',
kwargs={'document_version_pk': self.pk}
kwargs={'document_version_id': self.pk}
)
def get_api_image_url(self, *args, **kwargs):
@@ -195,6 +195,7 @@ class DocumentVersion(models.Model):
filename, self.get_rendered_timestamp(), extension
)
else:
#TODO: use get_rendered_timestamp here
return Template(
'{{ instance.document }} - {{ instance.timestamp }}'
).render(context=Context({'instance': self}))
@@ -205,6 +206,10 @@ class DocumentVersion(models.Model):
)
get_rendered_timestamp.short_description = _('Date and time')
@property
def label(self):
return self.get_rendered_string()
def natural_key(self):
return (self.checksum, self.document.natural_key())
natural_key.dependencies = ['documents.Document']
@@ -250,9 +255,19 @@ class DocumentVersion(models.Model):
self.document, self
)
event_document_version_revert.commit(actor=_user, target=self.document)
for version in self.document.versions.filter(timestamp__gt=self.timestamp):
version.delete()
try:
with transaction.atomic():
event_document_version_revert.commit(
actor=_user, target=self.document
)
for version in self.document.versions.filter(timestamp__gt=self.timestamp):
version.delete()
except Exception as exception:
logger.error(
'Error reverting document version for document "%s"; %s',
self.document, exception
)
raise
def save(self, *args, **kwargs):
"""