Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Added download_url to the Document model

Daniel Quinn2f0da8ab25eb
diff --git a/src/documents/admin.py b/src/documents/admin.py
index 214b9f1f2..635b9ddf8 100644
--- a/src/documents/admin.py
+++ b/src/documents/admin.py
@@ -48,7 +48,6 @@ class DocumentAdmin(admin.ModelAdmin):
search_fields = ("sender__name", "title", "content")
list_display = ("created", "sender", "title", "tags_", "document")
list_filter = ("tags", "sender", MonthListFilter)
- list_editable = ("sender", "title")
list_per_page = 25
def tags_(self, obj):
@@ -67,11 +66,12 @@ class DocumentAdmin(admin.ModelAdmin):
def document(self, obj):
return '<a href="{}">' \
- '<img src="{}" width="22" height="22" alt="{} icon">' \
+ '<img src="{}" width="22" height="22" alt="{} icon" title="{}">' \
'</a>'.format(
- reverse("fetch", kwargs={"pk": obj.pk}),
+ obj.download_url,
static("documents/img/{}.png".format(obj.file_type)),
- obj.file_type
+ obj.file_type,
+ obj.file_name
)
document.allow_tags = True
diff --git a/src/documents/management/commands/document_exporter.py b/src/documents/management/commands/document_exporter.py
index f64aaa39f..ac448d8e8 100644
--- a/src/documents/management/commands/document_exporter.py
+++ b/src/documents/management/commands/document_exporter.py
@@ -1,4 +1,3 @@
-import gnupg
import os
import time
@@ -25,7 +24,6 @@ class Command(Renderable, BaseCommand):
def __init__(self, *args, **kwargs):
self.verbosity = 0
self.target = None
- self.gpg = gnupg.GPG(gnupghome=settings.GNUPG_HOME)
BaseCommand.__init__(self, *args, **kwargs)
def handle(self, *args, **options):
@@ -44,7 +42,7 @@ class Command(Renderable, BaseCommand):
for document in Document.objects.all():
- target = os.path.join(self.target, document.parseable_file_name)
+ target = os.path.join(self.target, document.file_name)
print("Exporting: {}".format(target))
diff --git a/src/documents/models.py b/src/documents/models.py
index 26acb95d7..447beaa66 100644
--- a/src/documents/models.py
+++ b/src/documents/models.py
@@ -2,6 +2,7 @@ import os
import re
from django.conf import settings
+from django.core.urlresolvers import reverse
from django.db import models
from django.template.defaultfilters import slugify
from django.utils import timezone
@@ -162,7 +163,7 @@ class Document(models.Model):
return open(self.source_path, "rb")
@property
- def parseable_file_name(self):
+ def file_name(self):
if self.sender and self.title:
tags = ",".join([t.slug for t in self.tags.all()])
if tags:
@@ -170,3 +171,7 @@ class Document(models.Model):
self.sender, self.title, tags, self.file_type)
return "{} - {}.{}".format(self.sender, self.title, self.file_type)
return os.path.basename(self.source_path)
+
+ @property
+ def download_url(self):
+ return reverse("fetch", kwargs={"pk": self.pk})