xapian #1
|
@ -171,3 +171,4 @@ LOGGING = {
|
||||||
}
|
}
|
||||||
|
|
||||||
SNAPSHOT_PATH="/tmp/"
|
SNAPSHOT_PATH="/tmp/"
|
||||||
|
DATA_UPLOAD_MAX_NUMBER_FILES = 1000
|
||||||
|
|
|
@ -1,27 +1,43 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from utils.forms import MultipleFileField
|
||||||
from evidence.parse import Build
|
from evidence.parse import Build
|
||||||
|
from evidence.models import Annotation
|
||||||
|
|
||||||
|
|
||||||
class UploadForm(forms.Form):
|
class UploadForm(forms.Form):
|
||||||
|
|
||||||
evidence_file = forms.FileField(label=_("File"))
|
evidence_file = MultipleFileField(label=_("File"))
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
self.evidences = []
|
||||||
data = self.cleaned_data.get('evidence_file')
|
data = self.cleaned_data.get('evidence_file')
|
||||||
if not data:
|
if not data:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.file_name = data.name
|
for f in data:
|
||||||
self.file_data = data.read()
|
file_name = f.name
|
||||||
if not self.file_name or not self.file_data:
|
file_data = f.read()
|
||||||
|
if not file_name or not file_data:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.file_json = json.loads(self.file_data)
|
file_json = json.loads(file_data)
|
||||||
|
Build(file_json, None, check=True)
|
||||||
|
exist_annotation = Annotation.objects.filter(
|
||||||
|
uuid=file_json['uuid']
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if exist_annotation:
|
||||||
|
raise ValidationError("error: {} exist".format(file_name))
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
raise ValidationError("error in: {}".format(file_name))
|
||||||
|
|
||||||
|
self.evidences.append((file_name, file_json))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -29,5 +45,5 @@ class UploadForm(forms.Form):
|
||||||
if not commit or not user:
|
if not commit or not user:
|
||||||
return
|
return
|
||||||
|
|
||||||
evidence = Build(self.file_json, user)
|
for ev in self.evidences:
|
||||||
return evidence
|
Build(ev[1], user)
|
||||||
|
|
Loading…
Reference in New Issue