Commit dfca5315ef7b2c71f80d6859da83d7d6144d02f0
1 parent
069dc064
Exists in
master
and in
3 other branches
modified subject delete process, now it works on /view and on /home with redirect
Showing
6 changed files
with
35 additions
and
7 deletions
Show diff stats
categories/views.py
... | ... | @@ -50,8 +50,7 @@ class IndexView(views.SuperuserRequiredMixin, LoginRequiredMixin, ListView): |
50 | 50 | if self.request.is_ajax(): |
51 | 51 | if self.request.user.is_staff: |
52 | 52 | self.template_name = "categories/home_admin_content.html" |
53 | - else: | |
54 | - self.template_name = "categories/home_teacher_student_content.html" | |
53 | + | |
55 | 54 | |
56 | 55 | return self.response_class(request = self.request, template = self.template_name, context = context, using = self.template_engine, **response_kwargs) |
57 | 56 | ... | ... |
subjects/static/subjects/js/modal_subject.js
... | ... | @@ -6,6 +6,7 @@ var RemoveSubject = { |
6 | 6 | $('body').removeClass('modal-open'); |
7 | 7 | $("#modal_course").empty(); |
8 | 8 | $(".modal-backdrop.in").remove(); |
9 | + window.location.href = data['url']; | |
9 | 10 | alertify.success("Subject removed successfully!"); |
10 | 11 | }).fail(function(){ |
11 | 12 | $("#modal_course").empty(); | ... | ... |
subjects/templates/subjects/initial.html
... | ... | @@ -59,6 +59,6 @@ |
59 | 59 | </div> |
60 | 60 | |
61 | 61 | <div id="modal_subject"></div> |
62 | - | |
62 | + <script type="text/javascript" src="{% static "subjects/js/modal_subject.js" %}"></script> | |
63 | 63 | <script type="text/javascript" src="{% static 'js/category.js' %}"></script> |
64 | 64 | {% endblock content %} |
65 | 65 | \ No newline at end of file | ... | ... |
subjects/templates/subjects/list.html
... | ... | @@ -187,6 +187,7 @@ |
187 | 187 | <div id="modal_subject"></div> |
188 | 188 | |
189 | 189 | <script type="text/javascript" src="{% static 'js/category.js' %}"></script> |
190 | + <script type="text/javascript" src="{% static "subjects/js/modal_subject.js" %}"></script> | |
190 | 191 | <script type="text/javascript"> |
191 | 192 | $(function (){ |
192 | 193 | var cat_slug = "{{ cat_slug }}" | ... | ... |
subjects/templates/subjects/subject_card.html
... | ... | @@ -5,10 +5,10 @@ |
5 | 5 | |
6 | 6 | {% if subject.visible or has_subject_permissions %} |
7 | 7 | {% if subject.visible %} |
8 | - <div class="panel panel-info subject-panel"> | |
8 | + <div class="panel panel-info subject-panel" id="subject_{{subject.slug}}"> | |
9 | 9 | <div class="panel-heading"> |
10 | 10 | {% elif has_subject_permissions %} |
11 | - <div class="panel panel-info subject-panel-invisible"> | |
11 | + <div class="panel panel-info subject-panel-invisible" id="subject_{{subject.slug}}"> | |
12 | 12 | <div class="panel-heading panel-invisible"> |
13 | 13 | {% endif %} |
14 | 14 | <div class="row"> | ... | ... |
subjects/views.py
... | ... | @@ -172,8 +172,7 @@ class IndexView(LoginRequiredMixin, ListView): |
172 | 172 | if self.request.is_ajax(): |
173 | 173 | if self.request.user.is_staff: |
174 | 174 | self.template_name = "categories/home_admin_content.html" |
175 | - else: | |
176 | - self.template_name = "categories/home_teacher_student_content.html" | |
175 | + | |
177 | 176 | |
178 | 177 | return self.response_class(request = self.request, template = self.template_name, context = context, using = self.template_engine, **response_kwargs) |
179 | 178 | |
... | ... | @@ -399,6 +398,30 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): |
399 | 398 | |
400 | 399 | return super(SubjectDeleteView, self).dispatch(request, *args, **kwargs) |
401 | 400 | |
401 | + | |
402 | + def delete(self, request, *args, **kwargs): | |
403 | + self.object = self.get_object() | |
404 | + self.object.delete() | |
405 | + if not (self.request.GET.get('view') == 'index'): | |
406 | + return self.ajax_success() | |
407 | + return HttpResponseRedirect(self.get_success_url()) | |
408 | + | |
409 | + def ajax_success(self): | |
410 | + self.log_context['category_id'] = self.object.category.id | |
411 | + self.log_context['category_name'] = self.object.category.name | |
412 | + self.log_context['category_slug'] = self.object.category.slug | |
413 | + self.log_context['subject_id'] = self.object.id | |
414 | + self.log_context['subject_name'] = self.object.name | |
415 | + self.log_context['subject_slug'] = self.object.slug | |
416 | + print("here 2") | |
417 | + super(SubjectDeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
418 | + | |
419 | + | |
420 | + messages.success(self.request, _('Subject "%s" removed successfully!')%(self.object.name)) | |
421 | + | |
422 | + return JsonResponse({'url':reverse_lazy('subjects:index')}) | |
423 | + | |
424 | + | |
402 | 425 | def get(self, request, *args, **kwargs): |
403 | 426 | self.object = self.get_object() |
404 | 427 | if self.object.students.count() > 0: |
... | ... | @@ -411,6 +434,10 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): |
411 | 434 | context = self.get_context_data(object=self.object) |
412 | 435 | return self.render_to_response(context) |
413 | 436 | |
437 | + def post(self, *args, **kwargs): | |
438 | + print("here") | |
439 | + return self.delete(*args, **kwargs) | |
440 | + | |
414 | 441 | def get_context_data(self, **kwargs): |
415 | 442 | context = super(SubjectDeleteView, self).get_context_data(**kwargs) |
416 | 443 | subject = get_object_or_404(Subject, slug = self.kwargs.get('slug')) | ... | ... |