Browse Source

Added more columns to the documents table and started implementing logic for saving attachments on the back-end

pull/170/head
Michael Olund 5 years ago
parent
commit
a4483a096e
7 changed files with 128 additions and 10 deletions
  1. +42
    -0
      edivorce/apps/poc/migrations/0005_auto_20200921_1255.py
  2. +20
    -0
      edivorce/apps/poc/migrations/0006_auto_20200921_1301.py
  3. +23
    -0
      edivorce/apps/poc/migrations/0007_auto_20200921_1523.py
  4. +26
    -2
      edivorce/apps/poc/models.py
  5. +6
    -1
      edivorce/apps/poc/views.py
  6. +10
    -6
      vue/src/components/Uploader/Main.vue
  7. +1
    -1
      vue/src/components/Uploader/UploadedImage.vue

+ 42
- 0
edivorce/apps/poc/migrations/0005_auto_20200921_1255.py View File

@ -0,0 +1,42 @@
# Generated by Django 2.2.15 on 2020-09-21 19:55
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0020_auto_20200903_2328'),
('poc', '0004_auto_20200917_1008'),
]
operations = [
migrations.RenameField(
model_name='document',
old_name='docType',
new_name='doc_type',
),
migrations.RenameField(
model_name='document',
old_name='partyId',
new_name='party_id',
),
migrations.AddField(
model_name='document',
name='bceid_user',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='uploads', to='core.BceidUser'),
),
migrations.AddField(
model_name='document',
name='length',
field=models.IntegerField(default=0),
),
migrations.AlterUniqueTogether(
name='document',
unique_together={('bceid_user', 'doc_type', 'party_id', 'filename', 'length')},
),
migrations.RunSQL(
sql='delete from poc_document'
)
]

+ 20
- 0
edivorce/apps/poc/migrations/0006_auto_20200921_1301.py View File

@ -0,0 +1,20 @@
# Generated by Django 2.2.15 on 2020-09-21 20:01
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('poc', '0005_auto_20200921_1255'),
]
operations = [
migrations.AlterField(
model_name='document',
name='bceid_user',
field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, related_name='uploads', to='core.BceidUser'),
preserve_default=False,
),
]

+ 23
- 0
edivorce/apps/poc/migrations/0007_auto_20200921_1523.py View File

@ -0,0 +1,23 @@
# Generated by Django 2.2.15 on 2020-09-21 22:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('poc', '0006_auto_20200921_1301'),
]
operations = [
migrations.AddField(
model_name='document',
name='order',
field=models.IntegerField(default=1),
),
migrations.AddField(
model_name='document',
name='rotation',
field=models.IntegerField(default=0),
),
]

+ 26
- 2
edivorce/apps/poc/models.py View File

@ -1,5 +1,6 @@
from django.db import models from django.db import models
from django.conf import settings from django.conf import settings
from edivorce.apps.core.models import BceidUser
from edivorce.apps.core import redis from edivorce.apps.core import redis
@ -9,12 +10,35 @@ class Document(models.Model):
This is only a POC model and should not be loaded on a production system. This is only a POC model and should not be loaded on a production system.
""" """
filename = models.CharField(max_length=128, null=True) # saving the original filename separately filename = models.CharField(max_length=128, null=True) # saving the original filename separately
""" File name and extension """
length = models.IntegerField(default=0)
""" Size of the file (size and name uniquely identify each file on the input) """
file = models.FileField(upload_to=redis.generate_unique_filename, storage=redis.RedisStorage()) file = models.FileField(upload_to=redis.generate_unique_filename, storage=redis.RedisStorage())
docType = models.CharField(max_length=4, null=True, blank=True)
partyId = models.IntegerField(default=0)
""" File temporarily stored in Redis """
doc_type = models.CharField(max_length=4, null=True, blank=True)
""" CEIS Document Type Code (2-4 letters) """
party_id = models.IntegerField(default=0)
""" 1 = You, 2 = Your Spouse, 0 = Shared """
order = models.IntegerField(default=1)
""" file order (page number in the PDF) """
rotation = models.IntegerField(default=0)
""" 0, 90, 180 or 270 """
bceid_user = models.ForeignKey(BceidUser, related_name='uploads', on_delete=models.CASCADE)
""" User who uploaded the attachment """
class Meta:
unique_together = ("bceid_user", "doc_type", "party_id", "filename", "length")
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
self.filename = self.file.name self.filename = self.file.name
self.length = self.file.size
super(Document, self).save(*args, **kwargs) super(Document, self).save(*args, **kwargs)


+ 6
- 1
edivorce/apps/poc/views.py View File

@ -39,7 +39,7 @@ class UploadScan(FormView):
class UploadStorage(CreateView): class UploadStorage(CreateView):
model = Document model = Document
fields = ['file', 'docType', 'partyId']
fields = ['file', 'doc_type', 'party_id']
template_name = "storage.html" template_name = "storage.html"
success_url = settings.FORCE_SCRIPT_NAME + 'poc/storage' success_url = settings.FORCE_SCRIPT_NAME + 'poc/storage'
@ -54,6 +54,11 @@ class UploadStorage(CreateView):
kwargs['documents'] = Document.objects.all() kwargs['documents'] = Document.objects.all()
return super(UploadStorage, self).get_context_data(**kwargs) return super(UploadStorage, self).get_context_data(**kwargs)
def form_valid(self, form):
obj = form.save(commit=False)
obj.bceid_user = self.request.user
return super(UploadStorage, self).form_valid(form)
class UploadStorageDelete(DeleteView): class UploadStorageDelete(DeleteView):
model = Document model = Document


+ 10
- 6
vue/src/components/Uploader/Main.vue View File

@ -101,8 +101,8 @@ export default {
}, },
data() { data() {
return { return {
docType: this.docType,
partyId: this.party
doc_type: this.docType,
party_id: this.party
}; };
} }
}, },
@ -122,7 +122,7 @@ export default {
console.log('inputFile newFile=' + newFile.name); console.log('inputFile newFile=' + newFile.name);
} }
if (oldFile) {
if (oldFile && !newFile) {
console.log('inputFile oldFile=' + oldFile.name); console.log('inputFile oldFile=' + oldFile.name);
} }
}, },
@ -130,13 +130,17 @@ export default {
if (newFile && !oldFile) { if (newFile && !oldFile) {
// Filter non-image file // Filter non-image file
if (!/\.(jpeg|jpg|gif|png|pdf)$/i.test(newFile.name)) { if (!/\.(jpeg|jpg|gif|png|pdf)$/i.test(newFile.name)) {
this.warningText = 'Unsupported file type. Allowed extensions are jpeg, jpg, gif,png and pdf.';
this.showWarning = true;
return prevent() return prevent()
} }
this.files.forEach(function(f) {
this.files.forEach((file) => {
// prevent duplicates (based on filename and length) // prevent duplicates (based on filename and length)
if (f.name === newFile.name && f.length === newFile.length) {
return prevent();
if (file.name === newFile.name && file.length === newFile.length) {
this.warningText = 'Duplicate file: ' + newFile.name;
this.showWarning = true;
return prevent();
} }
}); });


+ 1
- 1
vue/src/components/Uploader/UploadedImage.vue View File

@ -97,7 +97,7 @@ export default {
z-index: 2; z-index: 2;
i.fa-file-pdf-o { i.fa-file-pdf-o {
color: silver;
color: #F40F02;
display: block; display: block;
font-size: 50px; font-size: 50px;
margin-left: 15px; margin-left: 15px;


Loading…
Cancel
Save