Commit 0aa01fa47b5c1c2678f2b211a4d91f0e9ebfb49f
1 parent
17ebf399
Exists in
master
and in
5 other branches
ajustando para quando criar uma enquete não precisar atualizar a página para ela aparecer #261
Showing
10 changed files
with
99 additions
and
30 deletions
Show diff stats
courses/templates/subject/poll_item_actions_teacher.html
0 → 100644
... | ... | @@ -0,0 +1,10 @@ |
1 | +{% load static i18n permission_tags professor_access %} | |
2 | + | |
3 | +<div id="list-topic-{{ topic.slug }}-poll-edit"> | |
4 | + {% for poll in polls %} | |
5 | + <div id="poll_{{poll.slug}}_div"> | |
6 | + <li class="icon_edit_remove" ><a href="javascript:modal.get('{% url 'course:poll:update_poll' poll.slug %}','#poll','#requisicoes_ajax');"><i class="fa fa-pencil fa-lg" aria-hidden="true"></i></a> <a href="javascript:modal.get('{% url 'course:poll:delete_poll' poll.slug %}','#poll','#requisicoes_ajax');"><i class="fa fa-trash fa-lg" aria-hidden="true"></i></a></li> | |
7 | + <li><i class="fa fa-bar-chart"></i> <a href="javascript:modal.get('{% url 'course:poll:view_poll' poll.slug %}','#poll','#requisicoes_ajax');">{{poll}}</a></li> | |
8 | + </div> | |
9 | + {% endfor %} | |
10 | +</div> | ... | ... |
poll/models.py
... | ... | @@ -12,7 +12,7 @@ class Poll(Activity): |
12 | 12 | verbose_name_plural = _('Polls') |
13 | 13 | |
14 | 14 | def __str__(self): |
15 | - return str(self.name) + str("/") + str(self.topic) | |
15 | + return str(self.name) | |
16 | 16 | |
17 | 17 | class Answer(models.Model): |
18 | 18 | answer = models.CharField(_("Answer"), max_length = 200) | ... | ... |
poll/static/js/modal_poll.js
1 | -//controles do modal | |
2 | -$(window).ready(function() { // utilizado para abrir o modal quando tiver tido algum erro no preenchimento do formulario | |
3 | - if($('.not_submited').length){ | |
4 | - $('#poll').modal('show'); | |
5 | - } | |
6 | -}); | |
1 | +// | |
2 | +// //controles do modal | |
3 | +// $(window).ready(function() { // utilizado para abrir o modal quando tiver tido algum erro no preenchimento do formulario | |
4 | +// if($('.not_submited').length){ | |
5 | +// $('#poll').modal('show'); | |
6 | +// } | |
7 | +// }); | |
8 | + | |
7 | 9 | var Answer = { |
8 | 10 | init: function(url) { // utilizado para adicionar um novo campo de resposta |
9 | 11 | $.get(url, function(data){ |
... | ... | @@ -17,24 +19,59 @@ var Answer = { |
17 | 19 | }; |
18 | 20 | |
19 | 21 | var Submite = { |
20 | - post: function(url,dados){ | |
22 | + create: function(url,dados, slug){ | |
23 | + $('#poll').modal('hide'); | |
24 | + var poll = null; | |
25 | + $.post(url,dados, function(data){ | |
26 | + $.ajax({ | |
27 | + method: "get", | |
28 | + url: data["view"], | |
29 | + success: function(view){ | |
30 | + $('#list-topic-'+ slug +'-poll').append(view); | |
31 | + } | |
32 | + }); | |
33 | + $.ajax({ | |
34 | + method: "get", | |
35 | + url: data["edit"], | |
36 | + success: function(edit){ | |
37 | + $('#list-topic-'+ slug +'-poll-edit').append(edit); | |
38 | + } | |
39 | + }); | |
40 | + $("#requisicoes_ajax").empty(); | |
41 | + alertify.alert('Link successfully created!'); | |
42 | + }).fail(function(data){ | |
43 | + $("div.modal-backdrop.fade.in").remove(); | |
44 | + $("#requisicoes_ajax").empty(); | |
45 | + $("#requisicoes_ajax").append(data.responseText); | |
46 | + $('#poll').modal('show'); | |
47 | + }); | |
48 | + }, | |
49 | + update: function(url,dados, slug_poll, slug_topic){ | |
21 | 50 | $('#poll').modal('hide'); |
22 | 51 | $.post(url,dados, function(data){ |
52 | + $('#list-topic-'+ slug_topic +'-poll #'+slug_poll).remove(); | |
53 | + $('#list-topic-'+ slug_topic +'-poll #'+slug_poll).remove(); | |
54 | + $('#list-topic-'+ slug_topic +'-poll').append(data); | |
55 | + $('#list-topic-'+ slug_topic +'-poll-edit').append(data); | |
56 | + $("#requisicoes_ajax").empty(); | |
57 | + alertify.alert('Link successfully updated!') | |
23 | 58 | }).fail(function(data){ |
24 | 59 | $("div.modal-backdrop.fade.in").remove(); |
25 | - $("#modal_poll").empty(); | |
26 | - $("#modal_poll").append(data.responseText); | |
60 | + $("#requisicoes_ajax").empty(); | |
61 | + $("#requisicoes_ajax").append(data.responseText); | |
62 | + $('#poll').modal('show'); | |
27 | 63 | }); |
28 | 64 | }, |
29 | 65 | remove: function(url,dados, id_li_link){ |
30 | 66 | $('#poll').modal('hide'); |
31 | 67 | $.post(url,dados, function(data){ |
32 | 68 | $(id_li_link).remove(); |
33 | - $("#modal_poll").empty(); | |
69 | + $(id_li_link+"_div").remove(); | |
70 | + $("#requisicoes_ajax").empty(); | |
34 | 71 | $("div.modal-backdrop.fade.in").remove(); |
35 | 72 | }).fail(function(){ |
36 | - $("#modal_poll").empty(); | |
37 | - $("#modal_poll").append(data); | |
73 | + $("#requisicoes_ajax").empty(); | |
74 | + $("#requisicoes_ajax").append(data); | |
38 | 75 | $('#poll').modal('show'); |
39 | 76 | }); |
40 | 77 | } | ... | ... |
poll/templates/poll/create.html
... | ... | @@ -2,13 +2,6 @@ |
2 | 2 | |
3 | 3 | {% load i18n widget_tweaks dict_access static%} |
4 | 4 | |
5 | -{# {% block style %} #} | |
6 | - <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> | |
7 | - <script src="{% static 'js/modal_poll.js' %}"></script> | |
8 | - | |
9 | -{# {% endblock %} #} | |
10 | - | |
11 | -{# {% block content %} #} | |
12 | 5 | <!-- Modal (remember to change the ids!!!) --> |
13 | 6 | <div class="modal fade" id="poll" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> |
14 | 7 | <div class="modal-dialog" role="document"> |
... | ... | @@ -178,7 +171,7 @@ |
178 | 171 | }); |
179 | 172 | |
180 | 173 | $("#form").submit(function(event) { |
181 | - Submite.post("{% url 'course:poll:create_poll' topic.slug %}",$(this).serialize()); | |
174 | + Submite.create("{% url 'course:poll:create_poll' topic.slug %}",$(this).serialize(), "{{topic.slug}}"); | |
182 | 175 | event.preventDefault(); |
183 | 176 | }); |
184 | 177 | </script> | ... | ... |
... | ... | @@ -0,0 +1,4 @@ |
1 | +<div id="poll_{{poll.slug}}_div"> | |
2 | + <li class="icon_edit_remove" ><a href="javascript:modal.get('{% url 'course:poll:update_poll' poll.slug %}','#poll','#requisicoes_ajax');"><i class="fa fa-pencil fa-lg" aria-hidden="true"></i></a> <a href="javascript:modal.get('{% url 'course:poll:delete_poll' poll.slug %}','#poll','#requisicoes_ajax');"><i class="fa fa-trash fa-lg" aria-hidden="true"></i></a></li> | |
3 | + <li><i class="fa fa-bar-chart"></i> <a href="javascript:modal.get('{% url 'course:poll:view_poll' poll.slug %}','#poll','#requisicoes_ajax');">{{poll}}</a></li> | |
4 | +</div> | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +<li id="poll_{{poll.slug}}"><i class="fa fa-bar-chart"></i> <a href="javascript:modal.get('{% url 'course:poll:view_poll' poll.slug %}','#poll','#requisicoes_ajax');">{{ poll }}</a></li> | ... | ... |
poll/templates/poll/remove.html
... | ... | @@ -10,15 +10,15 @@ |
10 | 10 | {% block content_poll %} |
11 | 11 | <script src="{% static 'js/modal_poll.js' %}"></script> |
12 | 12 | <!-- Put ONLY your content here!!! --> |
13 | -<form id="delete_form" action="" method="post"> | |
13 | +<form id="delete_poll" action="" method="post"> | |
14 | 14 | {% csrf_token %} |
15 | 15 | <p>{% trans 'Are you sure you want to delete the subject' %} "{{poll.name}}"?</p> |
16 | 16 | </form> |
17 | 17 | {% endblock content_poll %} |
18 | 18 | {% block button_save %} |
19 | -<button type="submite" id="button" form="delete_form" class="btn btn-primary btn-raised">{% trans "Delete" %}</button> | |
19 | +<button type="submite" id="button" form="delete_poll" class="btn btn-primary btn-raised">{% trans "Delete" %}</button> | |
20 | 20 | <script> |
21 | - $("#delete_form").submit(function(event) { | |
21 | + $("#delete_poll").submit(function(event) { | |
22 | 22 | Submite.remove("{% url 'course:poll:delete_poll' poll.slug %}",$(this).serialize(),"#poll_{{poll.slug}}"); |
23 | 23 | event.preventDefault(); |
24 | 24 | }); | ... | ... |
poll/templates/poll/update.html
... | ... | @@ -25,7 +25,7 @@ |
25 | 25 | }); |
26 | 26 | |
27 | 27 | $("#form").submit(function(event) { |
28 | - Submite.post("{% url 'course:poll:update_poll' poll.slug %}",$(this).serialize()); | |
28 | + Submite.update("{% url 'course:poll:update_poll' poll.slug %}",$(this).serialize(), "{{poll.slug}}"); | |
29 | 29 | event.preventDefault(); |
30 | 30 | }); |
31 | 31 | </script> | ... | ... |
poll/urls.py
... | ... | @@ -9,4 +9,6 @@ urlpatterns = [ |
9 | 9 | url(r'^delete/(?P<slug>[\w\-_]+)/$', views.DeletePoll.as_view(), name='delete_poll'), # poll |
10 | 10 | url(r'^answer/$', views.AnswerPoll.as_view(), name='answer_poll'), # poll |
11 | 11 | url(r'^answer-poll/(?P<slug>[\w\-_]+)/$', views.AnswerStudentPoll.as_view(), name='answer_student_poll'), # poll slug |
12 | + url(r'^poll-view/(?P<slug>[\w\-_]+)/$', views.render_poll_view, name='render_poll_view'), # poll slug | |
13 | + url(r'^poll-edit/(?P<slug>[\w\-_]+)/$', views.render_poll_edit, name='render_poll_edit'), # poll slug | |
12 | 14 | ] | ... | ... |
poll/views.py
... | ... | @@ -20,6 +20,8 @@ from courses.models import Course, Topic |
20 | 20 | |
21 | 21 | import datetime |
22 | 22 | |
23 | +from django.http import JsonResponse | |
24 | + | |
23 | 25 | class ViewPoll(LoginRequiredMixin, LogMixin, generic.DetailView): |
24 | 26 | log_component = "poll" |
25 | 27 | log_resource = "poll" |
... | ... | @@ -96,7 +98,6 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin, LogMixin, NotificationMixin,ge |
96 | 98 | context.context_data['keys'] = keys |
97 | 99 | context.context_data['form'] = form |
98 | 100 | context.status_code = 400 |
99 | - s | |
100 | 101 | return context |
101 | 102 | |
102 | 103 | def form_valid(self, form): |
... | ... | @@ -107,7 +108,7 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin, LogMixin, NotificationMixin,ge |
107 | 108 | self.object.save() |
108 | 109 | |
109 | 110 | super(CreatePoll, self).createNotification(message="created a Poll at "+ self.object.topic.name, actor=self.request.user, |
110 | - resource_name=self.object.name, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]), | |
111 | + resource_name=self.object.name, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]), | |
111 | 112 | users=self.object.topic.subject.students.all()) |
112 | 113 | for key in self.request.POST: |
113 | 114 | if(key != 'csrfmiddlewaretoken' and key != 'name' and key != 'limit_date' and key != 'all_students' and key != 'students'): |
... | ... | @@ -130,7 +131,14 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin, LogMixin, NotificationMixin,ge |
130 | 131 | |
131 | 132 | super(CreatePoll, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
132 | 133 | |
133 | - return self.render_to_response(self.get_context_data(form = form), status = 200) | |
134 | + return JsonResponse({"view":reverse_lazy('course:poll:render_poll_view', kwargs={'slug' : self.object.slug}), | |
135 | + "edit":reverse_lazy('course:poll:render_poll_edit', kwargs={'slug' : self.object.slug}), | |
136 | + }) | |
137 | + | |
138 | + | |
139 | + # def get_success_url(self): | |
140 | + # self.success_url = redirect('course:poll:render_poll', slug = self.object.slug) | |
141 | + # return self.success_url | |
134 | 142 | |
135 | 143 | def get_context_data(self, **kwargs): |
136 | 144 | context = super(CreatePoll, self).get_context_data(**kwargs) |
... | ... | @@ -141,6 +149,20 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin, LogMixin, NotificationMixin,ge |
141 | 149 | context['subjects'] = topic.subject.course.subjects.all() |
142 | 150 | return context |
143 | 151 | |
152 | +def render_poll_view(request, slug): | |
153 | + template_name = 'poll/poll_view.html' | |
154 | + context = { | |
155 | + 'poll': get_object_or_404(Poll, slug = slug) | |
156 | + } | |
157 | + return render(request, template_name, context) | |
158 | + | |
159 | +def render_poll_edit(request, slug): | |
160 | + template_name = 'poll/poll_edit.html' | |
161 | + context = { | |
162 | + 'poll': get_object_or_404(Poll, slug = slug) | |
163 | + } | |
164 | + return render(request, template_name, context) | |
165 | + | |
144 | 166 | class UpdatePoll(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.UpdateView): |
145 | 167 | log_component = "poll" |
146 | 168 | log_resource = "poll" |
... | ... | @@ -325,9 +347,9 @@ class AnswerStudentPoll(LoginRequiredMixin, LogMixin, generic.CreateView): |
325 | 347 | |
326 | 348 | date_time_click = datetime.datetime.strptime(self.request.session.get('time_spent'), "%Y-%m-%d %H:%M:%S.%f") |
327 | 349 | _now = datetime.datetime.now() |
328 | - | |
350 | + | |
329 | 351 | time_spent = _now - date_time_click |
330 | - | |
352 | + | |
331 | 353 | secs = time_spent.total_seconds() |
332 | 354 | hours = int(secs / 3600) |
333 | 355 | minutes = int(secs / 60) % 60 | ... | ... |