Commit 56a21eaafea6c9517f36e321baa9a1c557ae7437
1 parent
e3a02b92
Exists in
master
and in
2 other branches
Fixing no user image error when backup
Showing
1 changed file
with
17 additions
and
14 deletions
Show diff stats
subjects/views.py
@@ -770,20 +770,22 @@ def realize_backup(request, subject): | @@ -770,20 +770,22 @@ def realize_backup(request, subject): | ||
770 | 770 | ||
771 | 771 | ||
772 | for filelink in filelinks: | 772 | for filelink in filelinks: |
773 | - if os.path.exists(filelink.file_content.path): | ||
774 | - fdir, fname = os.path.split(filelink.file_content.path) | ||
775 | - zip_path = os.path.join(resource_files_subdir, fname) | 773 | + if bool(filelink.file_content): |
774 | + if os.path.exists(filelink.file_content.path): | ||
775 | + fdir, fname = os.path.split(filelink.file_content.path) | ||
776 | + zip_path = os.path.join(resource_files_subdir, fname) | ||
776 | 777 | ||
777 | - # Add file, at correct path | ||
778 | - zf.write(filelink.file_content.path, zip_path) | 778 | + # Add file, at correct path |
779 | + zf.write(filelink.file_content.path, zip_path) | ||
779 | 780 | ||
780 | for pdffile in pdffiles: | 781 | for pdffile in pdffiles: |
781 | - if os.path.exists(pdffile.file.path): | ||
782 | - fdir, fname = os.path.split(pdffile.file.path) | ||
783 | - zip_path = os.path.join(resource_files_subdir, fname) | 782 | + if bool(pdffile.file): |
783 | + if os.path.exists(pdffile.file.path): | ||
784 | + fdir, fname = os.path.split(pdffile.file.path) | ||
785 | + zip_path = os.path.join(resource_files_subdir, fname) | ||
784 | 786 | ||
785 | - # Add file, at correct path | ||
786 | - zf.write(pdffile.file.path, zip_path) | 787 | + # Add file, at correct path |
788 | + zf.write(pdffile.file.path, zip_path) | ||
787 | 789 | ||
788 | file = open("backup.json", "w") | 790 | file = open("backup.json", "w") |
789 | 791 | ||
@@ -793,11 +795,12 @@ def realize_backup(request, subject): | @@ -793,11 +795,12 @@ def realize_backup(request, subject): | ||
793 | participants = User.objects.filter(subject_student__slug = subject) | 795 | participants = User.objects.filter(subject_student__slug = subject) |
794 | 796 | ||
795 | for user in participants: | 797 | for user in participants: |
796 | - if os.path.exists(user.image.path): | ||
797 | - fdir, fname = os.path.split(user.image.path) | ||
798 | - zip_path = os.path.join('users', fname) | 798 | + if bool(user.image): |
799 | + if os.path.exists(user.image.path): | ||
800 | + fdir, fname = os.path.split(user.image.path) | ||
801 | + zip_path = os.path.join('users', fname) | ||
799 | 802 | ||
800 | - zf.write(user.image.path, zip_path) | 803 | + zf.write(user.image.path, zip_path) |
801 | 804 | ||
802 | serializer_w = CompleteWebpageSerializer(webpages, many = True) | 805 | serializer_w = CompleteWebpageSerializer(webpages, many = True) |
803 | serializer_y = CompleteYTVideoSerializer(ytvideos, many = True) | 806 | serializer_y = CompleteYTVideoSerializer(ytvideos, many = True) |