Commit e3a02b9272e8abe6cc7820ac95ce7638fb6cc5b7
1 parent
7b846305
Exists in
master
and in
2 other branches
Some adjusts in backup and restore
Showing
9 changed files
with
27 additions
and
76 deletions
Show diff stats
file_link/serializers.py
... | ... | @@ -92,13 +92,7 @@ class SimpleFileLinkSerializer(serializers.ModelSerializer): |
92 | 92 | data["topic"] = topic |
93 | 93 | else: |
94 | 94 | data["topic"] = get_object_or_404(Topic, id = topic["id"]) |
95 | - | |
96 | - if not data["file_content"] is None: | |
97 | - f = open(os.path.join(settings.MEDIA_ROOT, data["file_content"]), encoding="latin-1") | |
98 | - file = File(f) | |
99 | - | |
100 | - data["file_content"] = file | |
101 | - | |
95 | + | |
102 | 96 | file_link_data = data |
103 | 97 | |
104 | 98 | pendencies = file_link_data["pendencies_resource"] |
... | ... | @@ -208,12 +202,6 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): |
208 | 202 | else: |
209 | 203 | data["topic"] = get_object_or_404(Topic, id = topic["id"]) |
210 | 204 | |
211 | - if not data["file_content"] is None: | |
212 | - f = open(os.path.join(settings.MEDIA_ROOT, data["file_content"]), encoding="latin-1") | |
213 | - file = File(f) | |
214 | - | |
215 | - data["file_content"] = file | |
216 | - | |
217 | 205 | file_link_data = data |
218 | 206 | |
219 | 207 | pendencies = file_link_data["pendencies_resource"] |
... | ... | @@ -260,12 +248,6 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): |
260 | 248 | if not l_exists.exists(): |
261 | 249 | Log.objects.create(**log) |
262 | 250 | else: |
263 | - if not student_data["image"] is None: | |
264 | - f = open(os.path.join(settings.MEDIA_ROOT, student_data["image"]), encoding="latin-1") | |
265 | - file = File(f) | |
266 | - | |
267 | - student_data["image"] = file | |
268 | - | |
269 | 251 | student = User() |
270 | 252 | student.email = student_data["email"] |
271 | 253 | student.username = student_data["username"] | ... | ... |
goals/serializers.py
... | ... | @@ -203,12 +203,6 @@ class CompleteGoalSerializer(serializers.ModelSerializer): |
203 | 203 | if not l_exists.exists(): |
204 | 204 | Log.objects.create(**log) |
205 | 205 | else: |
206 | - if not student_data["image"] is None: | |
207 | - f = open(os.path.join(settings.MEDIA_ROOT, student_data["image"]), encoding="latin-1") | |
208 | - file = File(f) | |
209 | - | |
210 | - student_data["image"] = file | |
211 | - | |
212 | 206 | student = User() |
213 | 207 | student.email = student_data["email"] |
214 | 208 | student.username = student_data["username"] | ... | ... |
links/serializers.py
... | ... | @@ -185,12 +185,6 @@ class CompleteLinkSerializer(serializers.ModelSerializer): |
185 | 185 | if not l_exists.exists(): |
186 | 186 | Log.objects.create(**log) |
187 | 187 | else: |
188 | - if not student_data["image"] is None: | |
189 | - f = open(os.path.join(settings.MEDIA_ROOT, student_data["image"]), encoding="latin-1") | |
190 | - file = File(f) | |
191 | - | |
192 | - student_data["image"] = file | |
193 | - | |
194 | 188 | student = User() |
195 | 189 | student.email = student_data["email"] |
196 | 190 | student.username = student_data["username"] | ... | ... |
pdf_file/serializers.py
... | ... | @@ -86,12 +86,6 @@ class SimplePDFFileSerializer(serializers.ModelSerializer): |
86 | 86 | else: |
87 | 87 | data["topic"] = get_object_or_404(Topic, id = topic["id"]) |
88 | 88 | |
89 | - if not data["file"] is None: | |
90 | - f = open(os.path.join(settings.MEDIA_ROOT, data["file"]), encoding="latin-1") | |
91 | - file = File(f) | |
92 | - | |
93 | - data["file"] = file | |
94 | - | |
95 | 89 | pdf_data = data |
96 | 90 | |
97 | 91 | pendencies = pdf_data["pendencies_resource"] |
... | ... | @@ -183,6 +177,7 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): |
183 | 177 | pdf = None |
184 | 178 | |
185 | 179 | if not topic["id"] is None: |
180 | + | |
186 | 181 | if "subject" in topic: |
187 | 182 | r_exits = Resource.objects.filter(topic__subject = topic["subject"], name__unaccent__iexact = data["name"]) |
188 | 183 | else: |
... | ... | @@ -201,13 +196,6 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): |
201 | 196 | else: |
202 | 197 | data["topic"] = get_object_or_404(Topic, id = topic["id"]) |
203 | 198 | |
204 | - | |
205 | - if not data["file"] is None: | |
206 | - f = open(os.path.join(settings.MEDIA_ROOT, data["file"]), encoding="latin-1") | |
207 | - file = File(f) | |
208 | - | |
209 | - data["file"] = file | |
210 | - | |
211 | 199 | pdf_data = data |
212 | 200 | |
213 | 201 | pendencies = pdf_data["pendencies_resource"] |
... | ... | @@ -254,12 +242,6 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): |
254 | 242 | if not l_exists.exists(): |
255 | 243 | Log.objects.create(**log) |
256 | 244 | else: |
257 | - if not student_data["image"] is None: | |
258 | - f = open(os.path.join(settings.MEDIA_ROOT, student_data["image"]), encoding="latin-1") | |
259 | - file = File(f) | |
260 | - | |
261 | - student_data["image"] = file | |
262 | - | |
263 | 245 | student = User() |
264 | 246 | student.email = student_data["email"] |
265 | 247 | student.username = student_data["username"] | ... | ... |
pdf_file/views.py
... | ... | @@ -56,7 +56,6 @@ class ViewPDFFile(LoginRequiredMixin, LogMixin, generic.TemplateView): |
56 | 56 | context['pdf_file'] = pdf_file |
57 | 57 | context['subject'] = pdf_file.topic.subject |
58 | 58 | |
59 | - | |
60 | 59 | self.log_context['category_id'] = pdf_file.topic.subject.category.id |
61 | 60 | self.log_context['category_name'] = pdf_file.topic.subject.category.name |
62 | 61 | self.log_context['category_slug'] = pdf_file.topic.subject.category.slug |
... | ... | @@ -81,6 +80,7 @@ class ViewPDFFile(LoginRequiredMixin, LogMixin, generic.TemplateView): |
81 | 80 | |
82 | 81 | if not path.exists(pdf_file.file.path): |
83 | 82 | raise Http404() |
83 | + | |
84 | 84 | if pdf_file.show_window: |
85 | 85 | response = HttpResponse(open(pdf_file.file.path, 'rb').read(),content_type = 'application/pdf') |
86 | 86 | return response | ... | ... |
subjects/views.py
... | ... | @@ -813,13 +813,23 @@ def realize_backup(request, subject): |
813 | 813 | serializer_p = SimplePDFFileSerializer(pdffiles, many = True) |
814 | 814 | serializer_g = SimpleGoalSerializer(goals, many = True) |
815 | 815 | |
816 | + if len(serializer_w.data) > 0: | |
817 | + data_list.append(serializer_w.data) | |
816 | 818 | |
817 | - data_list.append(serializer_w.data) | |
818 | - data_list.append(serializer_y.data) | |
819 | - data_list.append(serializer_f.data) | |
820 | - data_list.append(serializer_l.data) | |
821 | - data_list.append(serializer_p.data) | |
822 | - data_list.append(serializer_g.data) | |
819 | + if len(serializer_y.data) > 0: | |
820 | + data_list.append(serializer_y.data) | |
821 | + | |
822 | + if len(serializer_f.data) > 0: | |
823 | + data_list.append(serializer_f.data) | |
824 | + | |
825 | + if len(serializer_l.data) > 0: | |
826 | + data_list.append(serializer_l.data) | |
827 | + | |
828 | + if len(serializer_p.data) > 0: | |
829 | + data_list.append(serializer_p.data) | |
830 | + | |
831 | + if len(serializer_g.data) > 0: | |
832 | + data_list.append(serializer_g.data) | |
823 | 833 | |
824 | 834 | json.dump(data_list, file) |
825 | 835 | ... | ... |
topics/serializers.py
... | ... | @@ -16,15 +16,16 @@ class TopicSerializer(serializers.ModelSerializer): |
16 | 16 | if topic.exists(): |
17 | 17 | data = topic[0].__dict__ |
18 | 18 | else: |
19 | - topic = Topic.objects.filter(subject = subject, repository = True) | |
19 | + data["id"] = "" | |
20 | + data["subject"] = subject | |
21 | + data["order"] = Topic.objects.filter(subject = subject).count() + 1 | |
20 | 22 | |
21 | - if topic.exists(): | |
22 | - data = topic[0].__dict__ | |
23 | - else: | |
24 | - data["id"] = "" | |
25 | - data["subject"] = subject | |
26 | - data["order"] = Topic.objects.filter(subject = subject).count() + 1 | |
23 | + if data["repository"] == True: | |
24 | + topic = Topic.objects.filter(subject = subject, repository = True) | |
27 | 25 | |
26 | + if topic.exists(): | |
27 | + data = topic[0].__dict__ | |
28 | + | |
28 | 29 | return data |
29 | 30 | |
30 | 31 | class Meta: | ... | ... |
webpage/serializers.py
... | ... | @@ -186,12 +186,6 @@ class CompleteWebpageSerializer(serializers.ModelSerializer): |
186 | 186 | if not l_exists.exists(): |
187 | 187 | Log.objects.create(**log) |
188 | 188 | else: |
189 | - if not student_data["image"] is None: | |
190 | - f = open(os.path.join(settings.MEDIA_ROOT, student_data["image"]), encoding="latin-1") | |
191 | - file = File(f) | |
192 | - | |
193 | - student_data["image"] = file | |
194 | - | |
195 | 189 | student = User() |
196 | 190 | student.email = student_data["email"] |
197 | 191 | student.username = student_data["username"] | ... | ... |
youtube_video/serializers.py
... | ... | @@ -187,12 +187,6 @@ class CompleteYTVideoSerializer(serializers.ModelSerializer): |
187 | 187 | if not l_exists.exists(): |
188 | 188 | Log.objects.create(**log) |
189 | 189 | else: |
190 | - if not student_data["image"] is None: | |
191 | - f = open(os.path.join(settings.MEDIA_ROOT, student_data["image"]), encoding="latin-1") | |
192 | - file = File(f) | |
193 | - | |
194 | - student_data["image"] = file | |
195 | - | |
196 | 190 | student = User() |
197 | 191 | student.email = student_data["email"] |
198 | 192 | student.username = student_data["username"] | ... | ... |