Commit d6e5638b9f3b5255383df0a06154a54e0aa694e9
1 parent
809705cc
Exists in
master
and in
3 other branches
Adding topic deletion
Showing
5 changed files
with
58 additions
and
1 deletions
Show diff stats
amadeus/static/js/topics.js
... | ... | @@ -63,4 +63,14 @@ function sendUpdate(data) { |
63 | 63 | console.log(response); |
64 | 64 | } |
65 | 65 | }); |
66 | +} | |
67 | + | |
68 | +function delete_topic(url) { | |
69 | + $('.modal').remove(); | |
70 | + | |
71 | + $.get(url, function (modal) { | |
72 | + $("#topics-accordion").after(modal); | |
73 | + | |
74 | + $('.modal').modal('show'); | |
75 | + }); | |
66 | 76 | } |
67 | 77 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,23 @@ |
1 | +{% load i18n %} | |
2 | + | |
3 | +<div class="modal fade" id="topic" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
4 | + <div class="modal-dialog" role="document"> | |
5 | + <div class="modal-content"> | |
6 | + <div class="modal-body"> | |
7 | + <form id="delete_form" action="{% url 'topics:delete' topic.slug %}" method="post"> | |
8 | + {% csrf_token %} | |
9 | + <h4>{% trans 'Are you sure you want delete the topic' %}: {{ topic }}?</h4> | |
10 | + <p>{% trans 'All data will be lost and havent how recover it.' %}</p> | |
11 | + </form> | |
12 | + </div> | |
13 | + <div class="modal-footer"> | |
14 | + <div class="pull-right"> | |
15 | + <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | |
16 | + </div> | |
17 | + <div class="pull-left"> | |
18 | + <button type="submit" form="delete_form" class="btn btn-success btn-raised">{% trans "Delete" %}</button> | |
19 | + </div> | |
20 | + </div> | |
21 | + </div> | |
22 | + </div> | |
23 | +</div> | |
0 | 24 | \ No newline at end of file | ... | ... |
topics/templates/topics/list.html
... | ... | @@ -6,6 +6,7 @@ |
6 | 6 | <div class="panel-group subject-group" id="topics-accordion" role="tablist" aria-multiselectable="true"> |
7 | 7 | <input type="hidden" class="url_order" value="{% url 'topics:update_order' %}" /> |
8 | 8 | <input type="hidden" class="subs_url" value="{% url 'subjects:view' subject.slug %}" /> |
9 | + | |
9 | 10 | {% for topic in subject.topic_subject.all %} |
10 | 11 | {% if not topic.repository and topic.visible or has_subject_permissions %} |
11 | 12 | <div class="panel panel-info {% if not topic.visible or topic.repository %} topic-panel-invisible {% else %} topic-panel {% endif %} topic-panel"> |
... | ... | @@ -25,7 +26,7 @@ |
25 | 26 | </a> |
26 | 27 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
27 | 28 | <li><a href="{% url 'topics:update' subject.slug topic.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> |
28 | - <li><a href="javascript:delete_subject.get('{% url 'subjects:delete' subject.slug %}?view=index','#subject','#modal_subject')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
29 | + <li><a href="javascript:delete_topic('{% url 'topics:delete' topic.slug %}')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
29 | 30 | </ul> |
30 | 31 | <a href="" ><i class="fa fa-arrows" aria-hidden="true"></i></a> |
31 | 32 | </div> | ... | ... |
topics/urls.py
... | ... | @@ -6,5 +6,6 @@ from . import views |
6 | 6 | urlpatterns = [ |
7 | 7 | url(r'^create/(?P<slug>[\w_-]+)/$', views.CreateView.as_view(), name = 'create'), |
8 | 8 | url(r'^update/(?P<sub_slug>[\w_-]+)/(?P<slug>[\w_-]+)/$', views.UpdateView.as_view(), name = 'update'), |
9 | + url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'), | |
9 | 10 | url(r'^update_order/$', views.update_order, name = 'update_order'), |
10 | 11 | ] | ... | ... |
topics/views.py
... | ... | @@ -114,6 +114,28 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): |
114 | 114 | |
115 | 115 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.subject.slug}) |
116 | 116 | |
117 | +class DeleteView(LoginRequiredMixin, generic.DeleteView): | |
118 | + login_url = reverse_lazy("users:login") | |
119 | + redirect_field_name = 'next' | |
120 | + | |
121 | + template_name = 'topics/delete.html' | |
122 | + model = Topic | |
123 | + context_object_name = 'topic' | |
124 | + | |
125 | + def dispatch(self, request, *args, **kwargs): | |
126 | + slug = self.kwargs.get('slug', '') | |
127 | + topic = get_object_or_404(Topic, slug = slug) | |
128 | + | |
129 | + if not has_subject_permissions(request.user, topic.subject): | |
130 | + return redirect(reverse_lazy('subjects:home')) | |
131 | + | |
132 | + return super(DeleteView, self).dispatch(request, *args, **kwargs) | |
133 | + | |
134 | + def get_success_url(self): | |
135 | + messages.success(self.request, _('Topic "%s" was removed from virtual enviroment "%s" successfully!')%(self.object.name, self.object.subject.name)) | |
136 | + | |
137 | + return reverse_lazy('subjects:view', kwargs = {'slug': self.object.subject.slug}) | |
138 | + | |
117 | 139 | def update_order(request): |
118 | 140 | data = request.GET.get('data', None) |
119 | 141 | ... | ... |