Commit db7f1d1ebd34386dd15a9525b0fa26e3b530e58a

Authored by Zambom
1 parent 97e8e4a2

Subject restore extracting json file (Still working on how to read it)

Showing 1 changed file with 17 additions and 1 deletions   Show diff stats
subjects/views.py
... ... @@ -40,6 +40,7 @@ from io import BytesIO
40 40 from itertools import chain
41 41 from django.core import serializers
42 42 from rest_framework.renderers import JSONRenderer
  43 +from rest_framework.parsers import JSONParser
43 44  
44 45 from users.serializers import UserSerializer
45 46 from file_link.serializers import SimpleFileLinkSerializer, CompleteFileLinkSerializer
... ... @@ -871,6 +872,21 @@ def realize_restore(request, subject):
871 872 if zip_file:
872 873 if zipfile.is_zipfile(zip_file):
873 874 file = zipfile.ZipFile(zip_file)
874   - print(file.namelist())
  875 + total_files = len(file.namelist())
  876 +
  877 + json_file = file.namelist()[total_files-1]
  878 +
  879 + dst_path = os.path.join(settings.MEDIA_ROOT, "tmp")
  880 +
  881 + path = file.extract(json_file, dst_path)
  882 +
  883 + for line in open(path, 'r'):
  884 + print(line)
  885 + #print(json.loads(line))
  886 +
  887 + # with open(path) as bkp_file:
  888 + # data = json.loads(bkp_file.read())
  889 +
  890 + # print(data)
875 891  
876 892 return JsonResponse({'message': 'ok'})
877 893 \ No newline at end of file
... ...