Commit fa28668fd90e75b8d317240e5f5f0fa95e84ac85
Exists in
master
and in
2 other branches
Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring
Showing
11 changed files
with
99 additions
and
101 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"] |
... | ... | @@ -242,6 +230,7 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): |
242 | 230 | file_link.tags.add(tag) |
243 | 231 | |
244 | 232 | students = data["students"] |
233 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
245 | 234 | |
246 | 235 | for student_data in students: |
247 | 236 | logs = student_data["get_items"] |
... | ... | @@ -260,12 +249,6 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): |
260 | 249 | if not l_exists.exists(): |
261 | 250 | Log.objects.create(**log) |
262 | 251 | 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 | 252 | student = User() |
270 | 253 | student.email = student_data["email"] |
271 | 254 | student.username = student_data["username"] |
... | ... | @@ -292,11 +275,10 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): |
292 | 275 | Log.objects.create(**log) |
293 | 276 | |
294 | 277 | file_link.students.add(student) |
278 | + subject.students.add(student) | |
295 | 279 | |
296 | 280 | groups = data["groups"] |
297 | 281 | |
298 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
299 | - | |
300 | 282 | for group_data in groups: |
301 | 283 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) |
302 | 284 | ... | ... |
goals/serializers.py
... | ... | @@ -185,6 +185,7 @@ class CompleteGoalSerializer(serializers.ModelSerializer): |
185 | 185 | goals.tags.add(tag) |
186 | 186 | |
187 | 187 | students = data["students"] |
188 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
188 | 189 | |
189 | 190 | for student_data in students: |
190 | 191 | logs = student_data["get_items"] |
... | ... | @@ -203,12 +204,6 @@ class CompleteGoalSerializer(serializers.ModelSerializer): |
203 | 204 | if not l_exists.exists(): |
204 | 205 | Log.objects.create(**log) |
205 | 206 | 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 | 207 | student = User() |
213 | 208 | student.email = student_data["email"] |
214 | 209 | student.username = student_data["username"] |
... | ... | @@ -235,11 +230,10 @@ class CompleteGoalSerializer(serializers.ModelSerializer): |
235 | 230 | Log.objects.create(**log) |
236 | 231 | |
237 | 232 | goals.students.add(student) |
233 | + subject.students.add(student) | |
238 | 234 | |
239 | 235 | groups = data["groups"] |
240 | 236 | |
241 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
242 | - | |
243 | 237 | for group_data in groups: |
244 | 238 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) |
245 | 239 | ... | ... |
links/serializers.py
... | ... | @@ -167,6 +167,7 @@ class CompleteLinkSerializer(serializers.ModelSerializer): |
167 | 167 | link.tags.add(tag) |
168 | 168 | |
169 | 169 | students = data["students"] |
170 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
170 | 171 | |
171 | 172 | for student_data in students: |
172 | 173 | logs = student_data["get_items"] |
... | ... | @@ -185,12 +186,6 @@ class CompleteLinkSerializer(serializers.ModelSerializer): |
185 | 186 | if not l_exists.exists(): |
186 | 187 | Log.objects.create(**log) |
187 | 188 | 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 | 189 | student = User() |
195 | 190 | student.email = student_data["email"] |
196 | 191 | student.username = student_data["username"] |
... | ... | @@ -217,11 +212,10 @@ class CompleteLinkSerializer(serializers.ModelSerializer): |
217 | 212 | Log.objects.create(**log) |
218 | 213 | |
219 | 214 | links.students.add(student) |
215 | + subject.students.add(student) | |
220 | 216 | |
221 | 217 | groups = data["groups"] |
222 | 218 | |
223 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
224 | - | |
225 | 219 | for group_data in groups: |
226 | 220 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) |
227 | 221 | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10.4 on 2017-06-10 18:12 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +from django.db import migrations, models | |
6 | + | |
7 | + | |
8 | +class Migration(migrations.Migration): | |
9 | + | |
10 | + dependencies = [ | |
11 | + ('news', '0002_auto_20170413_2034'), | |
12 | + ] | |
13 | + | |
14 | + operations = [ | |
15 | + migrations.AlterField( | |
16 | + model_name='news', | |
17 | + name='content', | |
18 | + field=models.TextField(blank=True, verbose_name='News Content'), | |
19 | + ), | |
20 | + ] | ... | ... |
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"] |
... | ... | @@ -236,6 +224,7 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): |
236 | 224 | pdf.tags.add(tag) |
237 | 225 | |
238 | 226 | students = data["students"] |
227 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
239 | 228 | |
240 | 229 | for student_data in students: |
241 | 230 | logs = student_data["get_items"] |
... | ... | @@ -254,12 +243,6 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): |
254 | 243 | if not l_exists.exists(): |
255 | 244 | Log.objects.create(**log) |
256 | 245 | 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 | 246 | student = User() |
264 | 247 | student.email = student_data["email"] |
265 | 248 | student.username = student_data["username"] |
... | ... | @@ -286,10 +269,10 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): |
286 | 269 | Log.objects.create(**log) |
287 | 270 | |
288 | 271 | pdf.students.add(student) |
272 | + subject.students.add(student) | |
289 | 273 | |
290 | 274 | groups = data["groups"] |
291 | 275 | |
292 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
293 | 276 | |
294 | 277 | for group_data in groups: |
295 | 278 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) | ... | ... |
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 |
... | ... | @@ -101,7 +101,10 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): |
101 | 101 | login_url = reverse_lazy("users:login") |
102 | 102 | redirect_field_name = 'next' |
103 | 103 | |
104 | + log_component = 'resources' | |
104 | 105 | log_resource = 'pdffile' |
106 | + log_action = 'create' | |
107 | + log_context = {} | |
105 | 108 | |
106 | 109 | def dispatch(self, request, *args, **kwargs): |
107 | 110 | slug = self.kwargs.get('slug', '') | ... | ... |
subjects/views.py
... | ... | @@ -770,20 +770,22 @@ def realize_backup(request, subject): |
770 | 770 | |
771 | 771 | |
772 | 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 | 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 | 790 | file = open("backup.json", "w") |
789 | 791 | |
... | ... | @@ -793,11 +795,12 @@ def realize_backup(request, subject): |
793 | 795 | participants = User.objects.filter(subject_student__slug = subject) |
794 | 796 | |
795 | 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 | 805 | serializer_w = CompleteWebpageSerializer(webpages, many = True) |
803 | 806 | serializer_y = CompleteYTVideoSerializer(ytvideos, many = True) |
... | ... | @@ -813,13 +816,23 @@ def realize_backup(request, subject): |
813 | 816 | serializer_p = SimplePDFFileSerializer(pdffiles, many = True) |
814 | 817 | serializer_g = SimpleGoalSerializer(goals, many = True) |
815 | 818 | |
819 | + if len(serializer_w.data) > 0: | |
820 | + data_list.append(serializer_w.data) | |
816 | 821 | |
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) | |
822 | + if len(serializer_y.data) > 0: | |
823 | + data_list.append(serializer_y.data) | |
824 | + | |
825 | + if len(serializer_f.data) > 0: | |
826 | + data_list.append(serializer_f.data) | |
827 | + | |
828 | + if len(serializer_l.data) > 0: | |
829 | + data_list.append(serializer_l.data) | |
830 | + | |
831 | + if len(serializer_p.data) > 0: | |
832 | + data_list.append(serializer_p.data) | |
833 | + | |
834 | + if len(serializer_g.data) > 0: | |
835 | + data_list.append(serializer_g.data) | |
823 | 836 | |
824 | 837 | json.dump(data_list, file) |
825 | 838 | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10.4 on 2017-06-10 18:12 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +from django.db import migrations, models | |
6 | + | |
7 | + | |
8 | +class Migration(migrations.Migration): | |
9 | + | |
10 | + dependencies = [ | |
11 | + ('themes', '0005_auto_20170209_1434'), | |
12 | + ] | |
13 | + | |
14 | + operations = [ | |
15 | + migrations.AlterField( | |
16 | + model_name='themes', | |
17 | + name='css_style', | |
18 | + field=models.CharField(choices=[('green', 'Green'), ('contrast', 'Contrast'), ('red', 'Red'), ('black', 'Black')], default='green', max_length=50, verbose_name='Css Style'), | |
19 | + ), | |
20 | + ] | ... | ... |
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
... | ... | @@ -167,6 +167,7 @@ class CompleteWebpageSerializer(serializers.ModelSerializer): |
167 | 167 | webpage.tags.add(tag) |
168 | 168 | |
169 | 169 | students = data["students"] |
170 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
170 | 171 | |
171 | 172 | for student_data in students: |
172 | 173 | logs = student_data["get_items"] |
... | ... | @@ -186,12 +187,6 @@ class CompleteWebpageSerializer(serializers.ModelSerializer): |
186 | 187 | if not l_exists.exists(): |
187 | 188 | Log.objects.create(**log) |
188 | 189 | 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 | 190 | student = User() |
196 | 191 | student.email = student_data["email"] |
197 | 192 | student.username = student_data["username"] |
... | ... | @@ -218,11 +213,10 @@ class CompleteWebpageSerializer(serializers.ModelSerializer): |
218 | 213 | Log.objects.create(**log) |
219 | 214 | |
220 | 215 | webpage.students.add(student) |
216 | + subject.students.add(student) | |
221 | 217 | |
222 | 218 | groups = data["groups"] |
223 | 219 | |
224 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
225 | - | |
226 | 220 | for group_data in groups: |
227 | 221 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) |
228 | 222 | ... | ... |
youtube_video/serializers.py
... | ... | @@ -169,6 +169,7 @@ class CompleteYTVideoSerializer(serializers.ModelSerializer): |
169 | 169 | ytvideo.tags.add(tag) |
170 | 170 | |
171 | 171 | students = data["students"] |
172 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
172 | 173 | |
173 | 174 | for student_data in students: |
174 | 175 | logs = student_data["get_items"] |
... | ... | @@ -187,12 +188,6 @@ class CompleteYTVideoSerializer(serializers.ModelSerializer): |
187 | 188 | if not l_exists.exists(): |
188 | 189 | Log.objects.create(**log) |
189 | 190 | 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 | 191 | student = User() |
197 | 192 | student.email = student_data["email"] |
198 | 193 | student.username = student_data["username"] |
... | ... | @@ -219,11 +214,10 @@ class CompleteYTVideoSerializer(serializers.ModelSerializer): |
219 | 214 | Log.objects.create(**log) |
220 | 215 | |
221 | 216 | ytvideo.students.add(student) |
217 | + subject.students.add(student) | |
222 | 218 | |
223 | 219 | groups = data["groups"] |
224 | 220 | |
225 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | |
226 | - | |
227 | 221 | for group_data in groups: |
228 | 222 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) |
229 | 223 | ... | ... |