Compare commits
No commits in common. "d1cd44f8f66f864b134053e96aeedf4383d4e05f" and "b4c4ed2689b9ff74310a8b9d2d20fdda6a57d5c2" have entirely different histories.
d1cd44f8f6
...
b4c4ed2689
17
api/views.py
17
api/views.py
|
@ -1,10 +1,7 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.http import JsonResponse
|
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
@ -16,8 +13,9 @@ from django.views.generic.edit import (
|
||||||
DeleteView,
|
DeleteView,
|
||||||
UpdateView,
|
UpdateView,
|
||||||
)
|
)
|
||||||
|
from django.http import JsonResponse
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
from utils.save_snapshots import move_json, save_in_disk
|
|
||||||
from dashboard.mixins import DashboardView
|
from dashboard.mixins import DashboardView
|
||||||
from evidence.models import Annotation
|
from evidence.models import Annotation
|
||||||
from evidence.parse import Build
|
from evidence.parse import Build
|
||||||
|
@ -26,6 +24,10 @@ from api.models import Token
|
||||||
from api.tables import TokensTable
|
from api.tables import TokensTable
|
||||||
|
|
||||||
|
|
||||||
|
def save_in_disk(data, user):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def NewSnapshot(request):
|
def NewSnapshot(request):
|
||||||
# Accept only posts
|
# Accept only posts
|
||||||
|
@ -58,11 +60,10 @@ def NewSnapshot(request):
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if exist_annotation:
|
if exist_annotation:
|
||||||
txt = "error: the snapshot {} exist".format(data['uuid'])
|
raise ValidationError("error: the snapshot {} exist".format(data['uuid']))
|
||||||
return JsonResponse({'status': txt}, status=500)
|
|
||||||
|
|
||||||
# Process snapshot
|
# Process snapshot
|
||||||
path_name = save_in_disk(data, tk.owner.institution.name)
|
# save_in_disk(data, tk.user)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Build(data, tk.owner)
|
Build(data, tk.owner)
|
||||||
|
@ -92,8 +93,6 @@ def NewSnapshot(request):
|
||||||
"url": url,
|
"url": url,
|
||||||
"public_url": url
|
"public_url": url
|
||||||
}
|
}
|
||||||
move_json(path_name, tk.owner.institution.name)
|
|
||||||
|
|
||||||
return JsonResponse(response, status=200)
|
return JsonResponse(response, status=200)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from utils.device import create_annotation, create_doc, create_index
|
from utils.device import create_annotation, create_doc, create_index
|
||||||
from utils.save_snapshots import move_json, save_in_disk
|
|
||||||
|
|
||||||
|
|
||||||
DEVICE_TYPES = [
|
DEVICE_TYPES = [
|
||||||
|
@ -57,11 +56,8 @@ class BaseDeviceFormSet(forms.BaseFormSet):
|
||||||
if not commit:
|
if not commit:
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
path_name = save_in_disk(doc, self.user.institution.name, place="placeholder")
|
|
||||||
create_index(doc, self.user)
|
create_index(doc, self.user)
|
||||||
create_annotation(doc, user, commit=commit)
|
create_annotation(doc, user, commit=commit)
|
||||||
move_json(path_name, self.user.institution.name, place="placeholder")
|
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ For the full list of settings and their values, see
|
||||||
https://docs.djangoproject.com/en/5.0/ref/settings/
|
https://docs.djangoproject.com/en/5.0/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
|
||||||
import xapian
|
import xapian
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -63,7 +62,6 @@ EMAIL_FILE_PATH = config('EMAIL_FILE_PATH', default='/tmp/app-messages')
|
||||||
|
|
||||||
ENABLE_EMAIL = config("ENABLE_EMAIL", default=True, cast=bool)
|
ENABLE_EMAIL = config("ENABLE_EMAIL", default=True, cast=bool)
|
||||||
|
|
||||||
EVIDENCES_DIR = config("EVIDENCES_DIR", default=os.path.join(BASE_DIR, "db"))
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ from utils.forms import MultipleFileField
|
||||||
from device.models import Device
|
from device.models import Device
|
||||||
from evidence.parse import Build
|
from evidence.parse import Build
|
||||||
from evidence.models import Annotation
|
from evidence.models import Annotation
|
||||||
from utils.save_snapshots import move_json, save_in_disk
|
|
||||||
|
|
||||||
|
|
||||||
class UploadForm(forms.Form):
|
class UploadForm(forms.Form):
|
||||||
|
@ -49,9 +48,7 @@ class UploadForm(forms.Form):
|
||||||
return
|
return
|
||||||
|
|
||||||
for ev in self.evidences:
|
for ev in self.evidences:
|
||||||
path_name = save_in_disk(ev[1], user.institution.name)
|
|
||||||
Build(ev[1], user)
|
Build(ev[1], user)
|
||||||
move_json(path_name, user.institution.name)
|
|
||||||
|
|
||||||
|
|
||||||
class UserTagForm(forms.Form):
|
class UserTagForm(forms.Form):
|
||||||
|
@ -154,11 +151,8 @@ class ImportForm(forms.Form):
|
||||||
|
|
||||||
if commit:
|
if commit:
|
||||||
for doc, cred in table:
|
for doc, cred in table:
|
||||||
path_name = save_in_disk(doc, self.user.institution.name, place="placeholder")
|
|
||||||
|
|
||||||
cred.save()
|
cred.save()
|
||||||
create_index(doc, self.user)
|
create_index(doc, self.user)
|
||||||
move_json(path_name, self.user.institution.name, place="placeholder")
|
|
||||||
return table
|
return table
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -65,6 +65,7 @@ class PasswordResetView(auth_views.PasswordResetView):
|
||||||
success_url = reverse_lazy('login:password_reset_done')
|
success_url = reverse_lazy('login:password_reset_done')
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
import pdb; pdb.set_trace()
|
||||||
try:
|
try:
|
||||||
response = super().form_valid(form)
|
response = super().form_valid(form)
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
|
|
||||||
def move_json(path_name, user, place="snapshots"):
|
|
||||||
if place != "snapshots":
|
|
||||||
place = "placeholders"
|
|
||||||
|
|
||||||
tmp_snapshots = settings.EVIDENCES_DIR
|
|
||||||
path_dir = os.path.join(tmp_snapshots, user, place)
|
|
||||||
|
|
||||||
if os.path.isfile(path_name):
|
|
||||||
shutil.copy(path_name, path_dir)
|
|
||||||
os.remove(path_name)
|
|
||||||
|
|
||||||
|
|
||||||
def save_in_disk(data, user, place="snapshots"):
|
|
||||||
uuid = data.get('uuid', '')
|
|
||||||
now = datetime.now()
|
|
||||||
year = now.year
|
|
||||||
month = now.month
|
|
||||||
day = now.day
|
|
||||||
hour = now.hour
|
|
||||||
minutes = now.minute
|
|
||||||
tmp_snapshots = settings.EVIDENCES_DIR
|
|
||||||
if place != "snapshots":
|
|
||||||
place = "placeholders"
|
|
||||||
|
|
||||||
name_file = f"{year}-{month}-{day}-{hour}-{minutes}_{uuid}.json"
|
|
||||||
path_dir = os.path.join(tmp_snapshots, user, place, "errors")
|
|
||||||
path_name = os.path.join(path_dir, name_file)
|
|
||||||
|
|
||||||
if not os.path.isdir(path_dir):
|
|
||||||
os.system(f'mkdir -p {path_dir}')
|
|
||||||
|
|
||||||
with open(path_name, 'w') as snapshot_file:
|
|
||||||
snapshot_file.write(json.dumps(data))
|
|
||||||
|
|
||||||
return path_name
|
|
Loading…
Reference in a new issue