From 626c7799cf9af2d25bb2ca814b32ade5285821b7 Mon Sep 17 00:00:00 2001 From: Marcin Armacki Date: Thu, 23 Apr 2020 20:09:28 +0200 Subject: [PATCH 1/2] Added XML check --- backend/webapp/prototype/filehandler/forms.py | 2 +- backend/webapp/prototype/filehandler/functions.py | 10 ++++++++++ backend/webapp/prototype/filehandler/models.py | 2 +- .../prototype/filehandler/templates/core/home.html | 2 +- backend/webapp/prototype/filehandler/views.py | 10 +++++++--- 5 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 backend/webapp/prototype/filehandler/functions.py diff --git a/backend/webapp/prototype/filehandler/forms.py b/backend/webapp/prototype/filehandler/forms.py index 13a4c94..a8d8888 100644 --- a/backend/webapp/prototype/filehandler/forms.py +++ b/backend/webapp/prototype/filehandler/forms.py @@ -4,4 +4,4 @@ from prototype.filehandler.models import Document class DocumentForm(forms.ModelForm): class Meta: model = Document - fields = ('description', 'document', ) + fields = ('description', 'file', ) diff --git a/backend/webapp/prototype/filehandler/functions.py b/backend/webapp/prototype/filehandler/functions.py new file mode 100644 index 0000000..56301b7 --- /dev/null +++ b/backend/webapp/prototype/filehandler/functions.py @@ -0,0 +1,10 @@ +from xml.etree.ElementTree import parse + +def isValidXML(file): + try: + parse(file) + except: + return(False) + return(True) + + diff --git a/backend/webapp/prototype/filehandler/models.py b/backend/webapp/prototype/filehandler/models.py index 928e2d0..5ccb64b 100644 --- a/backend/webapp/prototype/filehandler/models.py +++ b/backend/webapp/prototype/filehandler/models.py @@ -3,5 +3,5 @@ from django.db import models class Document(models.Model): description = models.CharField(max_length=255, blank=True) - document = models.FileField(upload_to='documents/') + file = models.FileField(upload_to='documents/') uploaded_at = models.DateTimeField(auto_now_add=True) diff --git a/backend/webapp/prototype/filehandler/templates/core/home.html b/backend/webapp/prototype/filehandler/templates/core/home.html index 9d273a9..d37bff5 100644 --- a/backend/webapp/prototype/filehandler/templates/core/home.html +++ b/backend/webapp/prototype/filehandler/templates/core/home.html @@ -11,7 +11,7 @@