mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Added download_url to the Document model
This commit is contained in:
		| @@ -48,7 +48,6 @@ class DocumentAdmin(admin.ModelAdmin): | |||||||
|     search_fields = ("sender__name", "title", "content") |     search_fields = ("sender__name", "title", "content") | ||||||
|     list_display = ("created", "sender", "title", "tags_", "document") |     list_display = ("created", "sender", "title", "tags_", "document") | ||||||
|     list_filter = ("tags", "sender", MonthListFilter) |     list_filter = ("tags", "sender", MonthListFilter) | ||||||
|     list_editable = ("sender", "title") |  | ||||||
|     list_per_page = 25 |     list_per_page = 25 | ||||||
|  |  | ||||||
|     def tags_(self, obj): |     def tags_(self, obj): | ||||||
| @@ -67,11 +66,12 @@ class DocumentAdmin(admin.ModelAdmin): | |||||||
|  |  | ||||||
|     def document(self, obj): |     def document(self, obj): | ||||||
|         return '<a href="{}">' \ |         return '<a href="{}">' \ | ||||||
|                  '<img src="{}" width="22" height="22" alt="{} icon">' \ |                  '<img src="{}" width="22" height="22" alt="{} icon" title="{}">' \ | ||||||
|                '</a>'.format( |                '</a>'.format( | ||||||
|                     reverse("fetch", kwargs={"pk": obj.pk}), |                     obj.download_url, | ||||||
|                     static("documents/img/{}.png".format(obj.file_type)), |                     static("documents/img/{}.png".format(obj.file_type)), | ||||||
|                     obj.file_type |                     obj.file_type, | ||||||
|  |                     obj.file_name | ||||||
|                 ) |                 ) | ||||||
|     document.allow_tags = True |     document.allow_tags = True | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,4 +1,3 @@ | |||||||
| import gnupg |  | ||||||
| import os | import os | ||||||
| import time | import time | ||||||
|  |  | ||||||
| @@ -25,7 +24,6 @@ class Command(Renderable, BaseCommand): | |||||||
|     def __init__(self, *args, **kwargs): |     def __init__(self, *args, **kwargs): | ||||||
|         self.verbosity = 0 |         self.verbosity = 0 | ||||||
|         self.target = None |         self.target = None | ||||||
|         self.gpg = gnupg.GPG(gnupghome=settings.GNUPG_HOME) |  | ||||||
|         BaseCommand.__init__(self, *args, **kwargs) |         BaseCommand.__init__(self, *args, **kwargs) | ||||||
|  |  | ||||||
|     def handle(self, *args, **options): |     def handle(self, *args, **options): | ||||||
| @@ -44,7 +42,7 @@ class Command(Renderable, BaseCommand): | |||||||
|  |  | ||||||
|         for document in Document.objects.all(): |         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)) |             print("Exporting: {}".format(target)) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ import os | |||||||
| import re | import re | ||||||
|  |  | ||||||
| from django.conf import settings | from django.conf import settings | ||||||
|  | from django.core.urlresolvers import reverse | ||||||
| from django.db import models | from django.db import models | ||||||
| from django.template.defaultfilters import slugify | from django.template.defaultfilters import slugify | ||||||
| from django.utils import timezone | from django.utils import timezone | ||||||
| @@ -162,7 +163,7 @@ class Document(models.Model): | |||||||
|         return open(self.source_path, "rb") |         return open(self.source_path, "rb") | ||||||
|  |  | ||||||
|     @property |     @property | ||||||
|     def parseable_file_name(self): |     def file_name(self): | ||||||
|         if self.sender and self.title: |         if self.sender and self.title: | ||||||
|             tags = ",".join([t.slug for t in self.tags.all()]) |             tags = ",".join([t.slug for t in self.tags.all()]) | ||||||
|             if tags: |             if tags: | ||||||
| @@ -170,3 +171,7 @@ class Document(models.Model): | |||||||
|                     self.sender, self.title, tags, self.file_type) |                     self.sender, self.title, tags, self.file_type) | ||||||
|             return "{} - {}.{}".format(self.sender, self.title, self.file_type) |             return "{} - {}.{}".format(self.sender, self.title, self.file_type) | ||||||
|         return os.path.basename(self.source_path) |         return os.path.basename(self.source_path) | ||||||
|  |  | ||||||
|  |     @property | ||||||
|  |     def download_url(self): | ||||||
|  |         return reverse("fetch", kwargs={"pk": self.pk}) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Daniel Quinn
					Daniel Quinn