Commit 9d6a4c6ee65d3da88c9be0b67f089c50e1f45841
1 parent
8ce9ba8b
Exists in
master
and in
3 other branches
subscription was made complete
Showing
5 changed files
with
83 additions
and
20 deletions
Show diff stats
subjects/static/subjects/js/modal_subject.js
@@ -28,4 +28,39 @@ var delete_subject = { | @@ -28,4 +28,39 @@ var delete_subject = { | ||
28 | } | 28 | } |
29 | }); | 29 | }); |
30 | } | 30 | } |
31 | -}; | ||
32 | \ No newline at end of file | 31 | \ No newline at end of file |
32 | +}; | ||
33 | + | ||
34 | + | ||
35 | +var subscribe_subject = { | ||
36 | + get: function(url, id_modal, id_div_modal){ | ||
37 | + $.get(url, function(data){ | ||
38 | + if($(id_modal).length){ | ||
39 | + $(id_div_modal).empty(); | ||
40 | + } | ||
41 | + if (!data['error']){ //If there is no error in the removing process, no message is shown | ||
42 | + $(id_div_modal).append(data); | ||
43 | + $(id_modal).modal('show'); | ||
44 | + }else{ | ||
45 | + window.location.href = data['url']; // If there is a error, we redirect to another URL | ||
46 | + } | ||
47 | + }); | ||
48 | + } | ||
49 | +} | ||
50 | + | ||
51 | + | ||
52 | +var SubscribeSubject = { | ||
53 | + subscribe: function(url,dados,id_li_link){ | ||
54 | + $("#subject").modal('toggle'); | ||
55 | + $.post(url,dados, function(data){ | ||
56 | + $(id_li_link).remove(); | ||
57 | + $('body').removeClass('modal-open'); | ||
58 | + $("#modal_course").empty(); | ||
59 | + $(".modal-backdrop.in").remove(); | ||
60 | + alertify.success("Subscription was succesfull!"); | ||
61 | + }).fail(function(){ | ||
62 | + $("#modal_course").empty(); | ||
63 | + $("#modal_course").append(data); | ||
64 | + $('#subject').modal('show'); | ||
65 | + }); | ||
66 | + } | ||
67 | +} | ||
33 | \ No newline at end of file | 68 | \ No newline at end of file |
subjects/templates/subjects/subject_card.html
@@ -47,14 +47,16 @@ | @@ -47,14 +47,16 @@ | ||
47 | <p><b>{% trans "End" %}:</b> {{subject.end_date}}</p> | 47 | <p><b>{% trans "End" %}:</b> {{subject.end_date}}</p> |
48 | </div> | 48 | </div> |
49 | </div> | 49 | </div> |
50 | - | ||
51 | - <p>{{subject.description_brief|safe}}</p> | 50 | + {% if subject.description_brief %} |
51 | + <p>{{subject.description_brief|safe}}</p> | ||
52 | + {% endif %} | ||
53 | + | ||
52 | {% if show_buttons %} | 54 | {% if show_buttons %} |
53 | 55 | ||
54 | {% if request.user in subject.students.all or request.user in subject.professor.all or request.user.is_staff or request.user in subject.category.coordinators.all %} | 56 | {% if request.user in subject.students.all or request.user in subject.professor.all or request.user.is_staff or request.user in subject.category.coordinators.all %} |
55 | <a href="{% url 'subjects:view' subject.slug %}" class="btn btn-success btn-raised"> {% trans "Access Subject" %}</a> | 57 | <a href="{% url 'subjects:view' subject.slug %}" class="btn btn-success btn-raised"> {% trans "Access Subject" %}</a> |
56 | {% else %} | 58 | {% else %} |
57 | - <a href="#" class="subscribe-subject btn btn-primary btn-raised"> {% trans "Subscribe to Subject" %}</a> | 59 | + <a href="javascript:subscribe_subject.get('{% url 'subjects:subscribe' subject.slug %}?view=index','#subject-subscribe','#modal_subject')" class="subscribe-subject btn btn-primary btn-raised"> {% trans "Subscribe to Subject" %}</a> |
58 | {% endif %} | 60 | {% endif %} |
59 | 61 | ||
60 | {% endif %} | 62 | {% endif %} |
@@ -115,7 +117,7 @@ | @@ -115,7 +117,7 @@ | ||
115 | {% if request.user in subject.students.all or request.user in subject.professor.all or request.user.is_staff or request.user in subject.category.coordinators.all %} | 117 | {% if request.user in subject.students.all or request.user in subject.professor.all or request.user.is_staff or request.user in subject.category.coordinators.all %} |
116 | <a href="{% url 'subjects:view' subject.slug %}" class="btn btn-success btn-raised"> {% trans "Access Subject" %}</a> | 118 | <a href="{% url 'subjects:view' subject.slug %}" class="btn btn-success btn-raised"> {% trans "Access Subject" %}</a> |
117 | {% else %} | 119 | {% else %} |
118 | - <a href="#" class="subscribe-subject btn btn-primary btn-raised"> {% trans "Subscribe to Subject" %}</a> | 120 | + <a href="{% url 'subjects:subscribe' subject.slug %}?view=index','#subject','#subject')" class="subscribe-subject btn btn-primary btn-raised"> {% trans "Subscribe to Subject" %}</a> |
119 | {% endif %} | 121 | {% endif %} |
120 | 122 | ||
121 | {% endif %} | 123 | {% endif %} |
subjects/templates/subjects/subscribe.html
1 | {% load static i18n permission_tags %} | 1 | {% load static i18n permission_tags %} |
2 | 2 | ||
3 | <!-- Modal (remember to change the ids!!!) --> | 3 | <!-- Modal (remember to change the ids!!!) --> |
4 | -<div class="modal fade" id="subscribe_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | 4 | +<div class="modal fade" id="subject-subscribe" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> |
5 | <div class="modal-dialog" role="document"> | 5 | <div class="modal-dialog" role="document"> |
6 | <div class="modal-content"> | 6 | <div class="modal-content"> |
7 | - <!-- Modal Body --> | 7 | + <!-- Modal Header --> |
8 | + <div class="modal-header"> | ||
9 | + | ||
10 | + <h4 class="modal-title" id="myModalLabel">{% trans "Delete Subject" %}</h4> | ||
11 | + </div> | ||
12 | + <!-- Modal Body --> | ||
8 | <div class="modal-body"> | 13 | <div class="modal-body"> |
9 | <!-- Put ONLY your content here!!! --> | 14 | <!-- Put ONLY your content here!!! --> |
10 | - <form id="modal_form" action="{% url 'subjects:subscribe' subject.slug %}" method="post"> | ||
11 | - {% csrf_token %} | ||
12 | - <p>{% trans 'Are you sure you want to subscribe to this subject' %} "{{subject.name}}"?</p> | ||
13 | - </form> | 15 | + <form id="subscribe" action="" method="post"> |
16 | + {% csrf_token %} | ||
17 | + <p>{% trans 'Are you sure you want to subscribe to the subject' %} "{{subject.name}}"?</p> | ||
18 | + </form> | ||
14 | </div> | 19 | </div> |
15 | <!-- Modal Footer --> | 20 | <!-- Modal Footer --> |
16 | - <div id="delete-category-footer"class="modal-footer"> | 21 | + <div class="modal-footer"> |
17 | <!-- Don't remove that!!! --> | 22 | <!-- Don't remove that!!! --> |
18 | - <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | ||
19 | - <button type="submit" id="button" form="delete_form" class="btn btn-primary btn-raised erase-button">{% trans "Subcribe" %}</button> | 23 | + <button type="button" class="btn btn-raised btn-default" data-dismiss="modal">{% trans "Cancel" %}</button> |
24 | + <button type="submit" id="button" form="subscribe" class="btn btn-success btn-raised">{% trans "Ok" %}</button> | ||
25 | + | ||
26 | + | ||
27 | + <script> | ||
28 | + $("#subscribe").submit(function(event) { | ||
29 | + SubscribeSubject.subscribe("{% url 'subjects:subscribe' subject.slug %}",$(this).serialize(),"#subject_{{subject.slug}}"); | ||
30 | + event.preventDefault(); | ||
31 | + }); | ||
32 | + </script> | ||
20 | 33 | ||
21 | </div> | 34 | </div> |
22 | </div> | 35 | </div> |
subjects/urls.py
@@ -10,5 +10,6 @@ urlpatterns = [ | @@ -10,5 +10,6 @@ urlpatterns = [ | ||
10 | url(r'^update/(?P<slug>[\w_-]+)/$', views.SubjectUpdateView.as_view(), name='update'), | 10 | url(r'^update/(?P<slug>[\w_-]+)/$', views.SubjectUpdateView.as_view(), name='update'), |
11 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.SubjectDeleteView.as_view(), name='delete'), | 11 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.SubjectDeleteView.as_view(), name='delete'), |
12 | url(r'^view/(?P<slug>[\w_-]+)/$', views.SubjectDetailView.as_view(), name='view'), | 12 | url(r'^view/(?P<slug>[\w_-]+)/$', views.SubjectDetailView.as_view(), name='view'), |
13 | + url(r'^subscribe/(?P<slug>[\w_-]+)/$', views.SubjectSubscribeView.as_view(), name='subscribe'), | ||
13 | #url(r'^modal/(?P<subject_slug>[\w_-]+)/$', views.subscribe_subject(), name='subscribe'), | 14 | #url(r'^modal/(?P<subject_slug>[\w_-]+)/$', views.subscribe_subject(), name='subscribe'), |
14 | ] | 15 | ] |
15 | \ No newline at end of file | 16 | \ No newline at end of file |
subjects/views.py
@@ -265,12 +265,24 @@ class SubjectDetailView(LoginRequiredMixin, DetailView): | @@ -265,12 +265,24 @@ class SubjectDetailView(LoginRequiredMixin, DetailView): | ||
265 | 265 | ||
266 | return context | 266 | return context |
267 | 267 | ||
268 | -def subscribe_subject(request, subject_slug): | ||
269 | - subject = get_object_or_404(Subject, slug= subject_slug) | ||
270 | - subject.students.add(request.user) | ||
271 | - subject.save() | ||
272 | 268 | ||
273 | - messages.success(self.request, _('Subcribed "%s" was updated on "%s" successfully!')%(self.object.name, self.object.category.name )) | ||
274 | - return reverse_lazy('subjects:index') | 269 | +class SubjectSubscribeView(LoginRequiredMixin, TemplateView): |
270 | + | ||
271 | + template_name = 'subjects/subscribe.html' | ||
272 | + | ||
273 | + def get_context_data(self, **kwargs): | ||
274 | + context = super(SubjectSubscribeView, self).get_context_data(**kwargs) | ||
275 | + context['subject'] = get_object_or_404(Subject, slug= kwargs.get('slug')) | ||
276 | + | ||
277 | + return context | ||
278 | + | ||
279 | + def post(self, request, *args, **kwargs): | ||
280 | + subject = get_object_or_404(Subject, slug= kwargs.get('slug')) | ||
281 | + print(subject) | ||
282 | + subject.students.add(request.user) | ||
283 | + subject.save() | ||
284 | + | ||
285 | + | ||
286 | + return HttpResponse('success') | ||
275 | 287 | ||
276 | 288 |