Skip to content

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

Attach storage_type to Documents

Daniel Quinnda6dc2ad5bab
diff --git a/src/documents/migrations/0019_document_storage_type.py b/src/documents/migrations/0019_document_storage_type.py
new file mode 100644
index 000000000..bd3595643
--- /dev/null
+++ b/src/documents/migrations/0019_document_storage_type.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-02-04 13:07
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('documents', '0018_auto_20170715_1712'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='document',
+ name='storage_type',
+ field=models.CharField(choices=[('unencrypted', 'Unencrypted'), ('gpg', 'Encrypted with GNU Privacy Guard')], default='gpg', editable=False, max_length=11),
+ ),
+ ]
diff --git a/src/documents/models.py b/src/documents/models.py
index 420afa426..8e072a1cc 100644
--- a/src/documents/models.py
+++ b/src/documents/models.py
@@ -190,6 +190,13 @@ class Document(models.Model):
TYPE_TIF = "tiff"
TYPES = (TYPE_PDF, TYPE_PNG, TYPE_JPG, TYPE_GIF, TYPE_TIF,)
+ STORAGE_TYPE_UNENCRYPTED = "unencrypted"
+ STORAGE_TYPE_GPG = "gpg"
+ STORAGE_TYPES = (
+ (STORAGE_TYPE_UNENCRYPTED, "Unencrypted"),
+ (STORAGE_TYPE_GPG, "Encrypted with GNU Privacy Guard")
+ )
+
correspondent = models.ForeignKey(
Correspondent,
blank=True,
@@ -229,6 +236,12 @@ class Document(models.Model):
default=timezone.now, db_index=True)
modified = models.DateTimeField(
auto_now=True, editable=False, db_index=True)
+ storage_type = models.CharField(
+ max_length=11,
+ choices=STORAGE_TYPES,
+ default=STORAGE_TYPE_GPG,
+ editable=False
+ )
class Meta(object):
ordering = ("correspondent", "title")
@@ -244,11 +257,16 @@ class Document(models.Model):
@property
def source_path(self):
+
+ file_name = "{:07}.{}".format(self.pk, self.file_type)
+ if self.storage_type == self.STORAGE_TYPE_GPG:
+ file_name += ".gpg"
+
return os.path.join(
settings.MEDIA_ROOT,
"documents",
"originals",
- "{:07}.{}.gpg".format(self.pk, self.file_type)
+ file_name
)
@property
@@ -265,11 +283,16 @@ class Document(models.Model):
@property
def thumbnail_path(self):
+
+ file_name = "{:07}.png".format(self.pk)
+ if self.storage_type == self.STORAGE_TYPE_GPG:
+ file_name += ".gpg"
+
return os.path.join(
settings.MEDIA_ROOT,
"documents",
"thumbnails",
- "{:07}.png.gpg".format(self.pk)
+ file_name
)
@property