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,13 +92,7 @@ class SimpleFileLinkSerializer(serializers.ModelSerializer): | ||
92 | data["topic"] = topic | 92 | data["topic"] = topic |
93 | else: | 93 | else: |
94 | data["topic"] = get_object_or_404(Topic, id = topic["id"]) | 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 | file_link_data = data | 96 | file_link_data = data |
103 | 97 | ||
104 | pendencies = file_link_data["pendencies_resource"] | 98 | pendencies = file_link_data["pendencies_resource"] |
@@ -208,12 +202,6 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): | @@ -208,12 +202,6 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): | ||
208 | else: | 202 | else: |
209 | data["topic"] = get_object_or_404(Topic, id = topic["id"]) | 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 | file_link_data = data | 205 | file_link_data = data |
218 | 206 | ||
219 | pendencies = file_link_data["pendencies_resource"] | 207 | pendencies = file_link_data["pendencies_resource"] |
@@ -242,6 +230,7 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): | @@ -242,6 +230,7 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): | ||
242 | file_link.tags.add(tag) | 230 | file_link.tags.add(tag) |
243 | 231 | ||
244 | students = data["students"] | 232 | students = data["students"] |
233 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
245 | 234 | ||
246 | for student_data in students: | 235 | for student_data in students: |
247 | logs = student_data["get_items"] | 236 | logs = student_data["get_items"] |
@@ -260,12 +249,6 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): | @@ -260,12 +249,6 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): | ||
260 | if not l_exists.exists(): | 249 | if not l_exists.exists(): |
261 | Log.objects.create(**log) | 250 | Log.objects.create(**log) |
262 | else: | 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 | student = User() | 252 | student = User() |
270 | student.email = student_data["email"] | 253 | student.email = student_data["email"] |
271 | student.username = student_data["username"] | 254 | student.username = student_data["username"] |
@@ -292,11 +275,10 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): | @@ -292,11 +275,10 @@ class CompleteFileLinkSerializer(serializers.ModelSerializer): | ||
292 | Log.objects.create(**log) | 275 | Log.objects.create(**log) |
293 | 276 | ||
294 | file_link.students.add(student) | 277 | file_link.students.add(student) |
278 | + subject.students.add(student) | ||
295 | 279 | ||
296 | groups = data["groups"] | 280 | groups = data["groups"] |
297 | 281 | ||
298 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
299 | - | ||
300 | for group_data in groups: | 282 | for group_data in groups: |
301 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) | 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,6 +185,7 @@ class CompleteGoalSerializer(serializers.ModelSerializer): | ||
185 | goals.tags.add(tag) | 185 | goals.tags.add(tag) |
186 | 186 | ||
187 | students = data["students"] | 187 | students = data["students"] |
188 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
188 | 189 | ||
189 | for student_data in students: | 190 | for student_data in students: |
190 | logs = student_data["get_items"] | 191 | logs = student_data["get_items"] |
@@ -203,12 +204,6 @@ class CompleteGoalSerializer(serializers.ModelSerializer): | @@ -203,12 +204,6 @@ class CompleteGoalSerializer(serializers.ModelSerializer): | ||
203 | if not l_exists.exists(): | 204 | if not l_exists.exists(): |
204 | Log.objects.create(**log) | 205 | Log.objects.create(**log) |
205 | else: | 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 | student = User() | 207 | student = User() |
213 | student.email = student_data["email"] | 208 | student.email = student_data["email"] |
214 | student.username = student_data["username"] | 209 | student.username = student_data["username"] |
@@ -235,11 +230,10 @@ class CompleteGoalSerializer(serializers.ModelSerializer): | @@ -235,11 +230,10 @@ class CompleteGoalSerializer(serializers.ModelSerializer): | ||
235 | Log.objects.create(**log) | 230 | Log.objects.create(**log) |
236 | 231 | ||
237 | goals.students.add(student) | 232 | goals.students.add(student) |
233 | + subject.students.add(student) | ||
238 | 234 | ||
239 | groups = data["groups"] | 235 | groups = data["groups"] |
240 | 236 | ||
241 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
242 | - | ||
243 | for group_data in groups: | 237 | for group_data in groups: |
244 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) | 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,6 +167,7 @@ class CompleteLinkSerializer(serializers.ModelSerializer): | ||
167 | link.tags.add(tag) | 167 | link.tags.add(tag) |
168 | 168 | ||
169 | students = data["students"] | 169 | students = data["students"] |
170 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
170 | 171 | ||
171 | for student_data in students: | 172 | for student_data in students: |
172 | logs = student_data["get_items"] | 173 | logs = student_data["get_items"] |
@@ -185,12 +186,6 @@ class CompleteLinkSerializer(serializers.ModelSerializer): | @@ -185,12 +186,6 @@ class CompleteLinkSerializer(serializers.ModelSerializer): | ||
185 | if not l_exists.exists(): | 186 | if not l_exists.exists(): |
186 | Log.objects.create(**log) | 187 | Log.objects.create(**log) |
187 | else: | 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 | student = User() | 189 | student = User() |
195 | student.email = student_data["email"] | 190 | student.email = student_data["email"] |
196 | student.username = student_data["username"] | 191 | student.username = student_data["username"] |
@@ -217,11 +212,10 @@ class CompleteLinkSerializer(serializers.ModelSerializer): | @@ -217,11 +212,10 @@ class CompleteLinkSerializer(serializers.ModelSerializer): | ||
217 | Log.objects.create(**log) | 212 | Log.objects.create(**log) |
218 | 213 | ||
219 | links.students.add(student) | 214 | links.students.add(student) |
215 | + subject.students.add(student) | ||
220 | 216 | ||
221 | groups = data["groups"] | 217 | groups = data["groups"] |
222 | 218 | ||
223 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
224 | - | ||
225 | for group_data in groups: | 219 | for group_data in groups: |
226 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) | 220 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) |
227 | 221 |
@@ -0,0 +1,20 @@ | @@ -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,12 +86,6 @@ class SimplePDFFileSerializer(serializers.ModelSerializer): | ||
86 | else: | 86 | else: |
87 | data["topic"] = get_object_or_404(Topic, id = topic["id"]) | 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 | pdf_data = data | 89 | pdf_data = data |
96 | 90 | ||
97 | pendencies = pdf_data["pendencies_resource"] | 91 | pendencies = pdf_data["pendencies_resource"] |
@@ -183,6 +177,7 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): | @@ -183,6 +177,7 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): | ||
183 | pdf = None | 177 | pdf = None |
184 | 178 | ||
185 | if not topic["id"] is None: | 179 | if not topic["id"] is None: |
180 | + | ||
186 | if "subject" in topic: | 181 | if "subject" in topic: |
187 | r_exits = Resource.objects.filter(topic__subject = topic["subject"], name__unaccent__iexact = data["name"]) | 182 | r_exits = Resource.objects.filter(topic__subject = topic["subject"], name__unaccent__iexact = data["name"]) |
188 | else: | 183 | else: |
@@ -201,13 +196,6 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): | @@ -201,13 +196,6 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): | ||
201 | else: | 196 | else: |
202 | data["topic"] = get_object_or_404(Topic, id = topic["id"]) | 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 | pdf_data = data | 199 | pdf_data = data |
212 | 200 | ||
213 | pendencies = pdf_data["pendencies_resource"] | 201 | pendencies = pdf_data["pendencies_resource"] |
@@ -236,6 +224,7 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): | @@ -236,6 +224,7 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): | ||
236 | pdf.tags.add(tag) | 224 | pdf.tags.add(tag) |
237 | 225 | ||
238 | students = data["students"] | 226 | students = data["students"] |
227 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
239 | 228 | ||
240 | for student_data in students: | 229 | for student_data in students: |
241 | logs = student_data["get_items"] | 230 | logs = student_data["get_items"] |
@@ -254,12 +243,6 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): | @@ -254,12 +243,6 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): | ||
254 | if not l_exists.exists(): | 243 | if not l_exists.exists(): |
255 | Log.objects.create(**log) | 244 | Log.objects.create(**log) |
256 | else: | 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 | student = User() | 246 | student = User() |
264 | student.email = student_data["email"] | 247 | student.email = student_data["email"] |
265 | student.username = student_data["username"] | 248 | student.username = student_data["username"] |
@@ -286,10 +269,10 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): | @@ -286,10 +269,10 @@ class CompletePDFFileSerializer(serializers.ModelSerializer): | ||
286 | Log.objects.create(**log) | 269 | Log.objects.create(**log) |
287 | 270 | ||
288 | pdf.students.add(student) | 271 | pdf.students.add(student) |
272 | + subject.students.add(student) | ||
289 | 273 | ||
290 | groups = data["groups"] | 274 | groups = data["groups"] |
291 | 275 | ||
292 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
293 | 276 | ||
294 | for group_data in groups: | 277 | for group_data in groups: |
295 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) | 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,7 +56,6 @@ class ViewPDFFile(LoginRequiredMixin, LogMixin, generic.TemplateView): | ||
56 | context['pdf_file'] = pdf_file | 56 | context['pdf_file'] = pdf_file |
57 | context['subject'] = pdf_file.topic.subject | 57 | context['subject'] = pdf_file.topic.subject |
58 | 58 | ||
59 | - | ||
60 | self.log_context['category_id'] = pdf_file.topic.subject.category.id | 59 | self.log_context['category_id'] = pdf_file.topic.subject.category.id |
61 | self.log_context['category_name'] = pdf_file.topic.subject.category.name | 60 | self.log_context['category_name'] = pdf_file.topic.subject.category.name |
62 | self.log_context['category_slug'] = pdf_file.topic.subject.category.slug | 61 | self.log_context['category_slug'] = pdf_file.topic.subject.category.slug |
@@ -81,6 +80,7 @@ class ViewPDFFile(LoginRequiredMixin, LogMixin, generic.TemplateView): | @@ -81,6 +80,7 @@ class ViewPDFFile(LoginRequiredMixin, LogMixin, generic.TemplateView): | ||
81 | 80 | ||
82 | if not path.exists(pdf_file.file.path): | 81 | if not path.exists(pdf_file.file.path): |
83 | raise Http404() | 82 | raise Http404() |
83 | + | ||
84 | if pdf_file.show_window: | 84 | if pdf_file.show_window: |
85 | response = HttpResponse(open(pdf_file.file.path, 'rb').read(),content_type = 'application/pdf') | 85 | response = HttpResponse(open(pdf_file.file.path, 'rb').read(),content_type = 'application/pdf') |
86 | return response | 86 | return response |
@@ -101,7 +101,10 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): | @@ -101,7 +101,10 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): | ||
101 | login_url = reverse_lazy("users:login") | 101 | login_url = reverse_lazy("users:login") |
102 | redirect_field_name = 'next' | 102 | redirect_field_name = 'next' |
103 | 103 | ||
104 | + log_component = 'resources' | ||
104 | log_resource = 'pdffile' | 105 | log_resource = 'pdffile' |
106 | + log_action = 'create' | ||
107 | + log_context = {} | ||
105 | 108 | ||
106 | def dispatch(self, request, *args, **kwargs): | 109 | def dispatch(self, request, *args, **kwargs): |
107 | slug = self.kwargs.get('slug', '') | 110 | slug = self.kwargs.get('slug', '') |
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) |
@@ -813,13 +816,23 @@ def realize_backup(request, subject): | @@ -813,13 +816,23 @@ def realize_backup(request, subject): | ||
813 | serializer_p = SimplePDFFileSerializer(pdffiles, many = True) | 816 | serializer_p = SimplePDFFileSerializer(pdffiles, many = True) |
814 | serializer_g = SimpleGoalSerializer(goals, many = True) | 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 | json.dump(data_list, file) | 837 | json.dump(data_list, file) |
825 | 838 |
@@ -0,0 +1,20 @@ | @@ -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,15 +16,16 @@ class TopicSerializer(serializers.ModelSerializer): | ||
16 | if topic.exists(): | 16 | if topic.exists(): |
17 | data = topic[0].__dict__ | 17 | data = topic[0].__dict__ |
18 | else: | 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 | return data | 29 | return data |
29 | 30 | ||
30 | class Meta: | 31 | class Meta: |
webpage/serializers.py
@@ -167,6 +167,7 @@ class CompleteWebpageSerializer(serializers.ModelSerializer): | @@ -167,6 +167,7 @@ class CompleteWebpageSerializer(serializers.ModelSerializer): | ||
167 | webpage.tags.add(tag) | 167 | webpage.tags.add(tag) |
168 | 168 | ||
169 | students = data["students"] | 169 | students = data["students"] |
170 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
170 | 171 | ||
171 | for student_data in students: | 172 | for student_data in students: |
172 | logs = student_data["get_items"] | 173 | logs = student_data["get_items"] |
@@ -186,12 +187,6 @@ class CompleteWebpageSerializer(serializers.ModelSerializer): | @@ -186,12 +187,6 @@ class CompleteWebpageSerializer(serializers.ModelSerializer): | ||
186 | if not l_exists.exists(): | 187 | if not l_exists.exists(): |
187 | Log.objects.create(**log) | 188 | Log.objects.create(**log) |
188 | else: | 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 | student = User() | 190 | student = User() |
196 | student.email = student_data["email"] | 191 | student.email = student_data["email"] |
197 | student.username = student_data["username"] | 192 | student.username = student_data["username"] |
@@ -218,11 +213,10 @@ class CompleteWebpageSerializer(serializers.ModelSerializer): | @@ -218,11 +213,10 @@ class CompleteWebpageSerializer(serializers.ModelSerializer): | ||
218 | Log.objects.create(**log) | 213 | Log.objects.create(**log) |
219 | 214 | ||
220 | webpage.students.add(student) | 215 | webpage.students.add(student) |
216 | + subject.students.add(student) | ||
221 | 217 | ||
222 | groups = data["groups"] | 218 | groups = data["groups"] |
223 | 219 | ||
224 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
225 | - | ||
226 | for group_data in groups: | 220 | for group_data in groups: |
227 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) | 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,6 +169,7 @@ class CompleteYTVideoSerializer(serializers.ModelSerializer): | ||
169 | ytvideo.tags.add(tag) | 169 | ytvideo.tags.add(tag) |
170 | 170 | ||
171 | students = data["students"] | 171 | students = data["students"] |
172 | + subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
172 | 173 | ||
173 | for student_data in students: | 174 | for student_data in students: |
174 | logs = student_data["get_items"] | 175 | logs = student_data["get_items"] |
@@ -187,12 +188,6 @@ class CompleteYTVideoSerializer(serializers.ModelSerializer): | @@ -187,12 +188,6 @@ class CompleteYTVideoSerializer(serializers.ModelSerializer): | ||
187 | if not l_exists.exists(): | 188 | if not l_exists.exists(): |
188 | Log.objects.create(**log) | 189 | Log.objects.create(**log) |
189 | else: | 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 | student = User() | 191 | student = User() |
197 | student.email = student_data["email"] | 192 | student.email = student_data["email"] |
198 | student.username = student_data["username"] | 193 | student.username = student_data["username"] |
@@ -219,11 +214,10 @@ class CompleteYTVideoSerializer(serializers.ModelSerializer): | @@ -219,11 +214,10 @@ class CompleteYTVideoSerializer(serializers.ModelSerializer): | ||
219 | Log.objects.create(**log) | 214 | Log.objects.create(**log) |
220 | 215 | ||
221 | ytvideo.students.add(student) | 216 | ytvideo.students.add(student) |
217 | + subject.students.add(student) | ||
222 | 218 | ||
223 | groups = data["groups"] | 219 | groups = data["groups"] |
224 | 220 | ||
225 | - subject = get_object_or_404(Subject, slug = self.context.get("subject", None)) | ||
226 | - | ||
227 | for group_data in groups: | 221 | for group_data in groups: |
228 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) | 222 | g_exists = StudentsGroup.objects.filter(subject = subject, slug = group_data["slug"]) |
229 | 223 |