mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Attach storage_type to Documents
This commit is contained in:
		
							
								
								
									
										20
									
								
								src/documents/migrations/0019_document_storage_type.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/documents/migrations/0019_document_storage_type.py
									
									
									
									
									
										Normal file
									
								
							| @@ -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), | ||||
|         ), | ||||
|     ] | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Daniel Quinn
					Daniel Quinn