From 56a21eaafea6c9517f36e321baa9a1c557ae7437 Mon Sep 17 00:00:00 2001 From: Zambom Date: Fri, 9 Jun 2017 17:22:17 -0300 Subject: [PATCH] Fixing no user image error when backup --- subjects/views.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/subjects/views.py b/subjects/views.py index 7453587..90fb673 100644 --- a/subjects/views.py +++ b/subjects/views.py @@ -770,20 +770,22 @@ def realize_backup(request, subject): for filelink in filelinks: - if os.path.exists(filelink.file_content.path): - fdir, fname = os.path.split(filelink.file_content.path) - zip_path = os.path.join(resource_files_subdir, fname) + if bool(filelink.file_content): + if os.path.exists(filelink.file_content.path): + fdir, fname = os.path.split(filelink.file_content.path) + zip_path = os.path.join(resource_files_subdir, fname) - # Add file, at correct path - zf.write(filelink.file_content.path, zip_path) + # Add file, at correct path + zf.write(filelink.file_content.path, zip_path) for pdffile in pdffiles: - if os.path.exists(pdffile.file.path): - fdir, fname = os.path.split(pdffile.file.path) - zip_path = os.path.join(resource_files_subdir, fname) + if bool(pdffile.file): + if os.path.exists(pdffile.file.path): + fdir, fname = os.path.split(pdffile.file.path) + zip_path = os.path.join(resource_files_subdir, fname) - # Add file, at correct path - zf.write(pdffile.file.path, zip_path) + # Add file, at correct path + zf.write(pdffile.file.path, zip_path) file = open("backup.json", "w") @@ -793,11 +795,12 @@ def realize_backup(request, subject): participants = User.objects.filter(subject_student__slug = subject) for user in participants: - if os.path.exists(user.image.path): - fdir, fname = os.path.split(user.image.path) - zip_path = os.path.join('users', fname) + if bool(user.image): + if os.path.exists(user.image.path): + fdir, fname = os.path.split(user.image.path) + zip_path = os.path.join('users', fname) - zf.write(user.image.path, zip_path) + zf.write(user.image.path, zip_path) serializer_w = CompleteWebpageSerializer(webpages, many = True) serializer_y = CompleteYTVideoSerializer(ytvideos, many = True) -- libgit2 0.21.2