Commit 781db60eae51fb534b48dd9c1898ff0468748650

Authored by Jailson Dias
1 parent f12fc61b

ajustes em criar e responder enquete #379

courses/templatetags/list_topic_foruns.py
@@ -4,6 +4,7 @@ from links.models import Link @@ -4,6 +4,7 @@ from links.models import Link
4 from forum.models import Forum 4 from forum.models import Forum
5 from poll.models import Poll 5 from poll.models import Poll
6 from files.models import TopicFile 6 from files.models import TopicFile
  7 +from django.db.models import Q
7 register = template.Library() 8 register = template.Library()
8 9
9 """ 10 """
@@ -27,8 +28,13 @@ def list_topic_poll(request, topic): @@ -27,8 +28,13 @@ def list_topic_poll(request, topic):
27 context = { 28 context = {
28 'request': request, 29 'request': request,
29 } 30 }
30 -  
31 - context['polls'] = Poll.objects.filter(topic = topic) 31 + all_polls = Poll.objects.filter(topic = topic)
  32 + my_polls = []
  33 + for poll in all_polls.all():
  34 + if ((request.user in poll.students.all())
  35 + or request.user in poll.topic.subject.professors.all()):
  36 + my_polls.append(poll)
  37 + context['polls'] = my_polls
32 context['topic'] = topic 38 context['topic'] = topic
33 39
34 return context 40 return context
poll/static/js/modal_poll.js
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 1
9 var Answer = { 2 var Answer = {
10 init: function(url) { // utilizado para adicionar um novo campo de resposta 3 init: function(url) { // utilizado para adicionar um novo campo de resposta
@@ -38,7 +31,8 @@ var Submite = { @@ -38,7 +31,8 @@ var Submite = {
38 } 31 }
39 }); 32 });
40 $("#requisicoes_ajax").empty(); 33 $("#requisicoes_ajax").empty();
41 - alertify.alert('Poll successfully created!'); 34 + $('body').removeClass('modal-open');
  35 + alertify.success('Poll successfully created!');
42 $("div.modal-backdrop.fade.in").remove(); 36 $("div.modal-backdrop.fade.in").remove();
43 }).fail(function(data){ 37 }).fail(function(data){
44 $("div.modal-backdrop.fade.in").remove(); 38 $("div.modal-backdrop.fade.in").remove();
@@ -52,7 +46,8 @@ var Submite = { @@ -52,7 +46,8 @@ var Submite = {
52 $.post(url,dados, function(data){ 46 $.post(url,dados, function(data){
53 $('#list-topic-'+ slug_topic +'-poll #'+slug_poll).replaceWith(data); 47 $('#list-topic-'+ slug_topic +'-poll #'+slug_poll).replaceWith(data);
54 $('#list-topic-'+ slug_topic +'-poll #'+slug_poll).replaceWith(data); 48 $('#list-topic-'+ slug_topic +'-poll #'+slug_poll).replaceWith(data);
55 - alertify.alert('Poll successfully updated!') 49 + $('body').removeClass('modal-open');
  50 + alertify.success('Poll successfully updated!')
56 }).fail(function(data){ 51 }).fail(function(data){
57 $("div.modal-backdrop.fade.in").remove(); 52 $("div.modal-backdrop.fade.in").remove();
58 $("#requisicoes_ajax").empty(); 53 $("#requisicoes_ajax").empty();
@@ -65,12 +60,25 @@ var Submite = { @@ -65,12 +60,25 @@ var Submite = {
65 $.post(url,dados, function(data){ 60 $.post(url,dados, function(data){
66 $(id_li_link).remove(); 61 $(id_li_link).remove();
67 $(id_li_link+"_div").remove(); 62 $(id_li_link+"_div").remove();
  63 + $('body').removeClass('modal-open');
68 $("#requisicoes_ajax").empty(); 64 $("#requisicoes_ajax").empty();
69 $("div.modal-backdrop.fade.in").remove(); 65 $("div.modal-backdrop.fade.in").remove();
  66 + alertify.success('Poll successfully removed')
70 }).fail(function(){ 67 }).fail(function(){
71 $("#requisicoes_ajax").empty(); 68 $("#requisicoes_ajax").empty();
72 $("#requisicoes_ajax").append(data); 69 $("#requisicoes_ajax").append(data);
73 $('#poll').modal('show'); 70 $('#poll').modal('show');
74 }); 71 });
  72 + },
  73 + answer: function(url,dados){
  74 + $('#poll').modal('hide');
  75 + $.post(url,dados, function(data){
  76 + alertify.success('Poll successfully answered!')
  77 + }).fail(function(data){
  78 + $("div.modal-backdrop.fade.in").remove();
  79 + $("#requisicoes_ajax").empty();
  80 + $("#requisicoes_ajax").append(data.responseText);
  81 + $('#poll').modal('show');
  82 + });
75 } 83 }
76 } 84 }
poll/templates/poll/answer_student.html
@@ -27,7 +27,7 @@ @@ -27,7 +27,7 @@
27 <button type="submite" id="button" form="answer_form" class="btn btn-primary btn-raised">{% trans "Answer" %}</button> 27 <button type="submite" id="button" form="answer_form" class="btn btn-primary btn-raised">{% trans "Answer" %}</button>
28 <script> 28 <script>
29 $("#answer_form").submit(function(event) { 29 $("#answer_form").submit(function(event) {
30 - Submite.post("{% url 'course:poll:answer_student_poll' poll.slug %}",$(this).serialize()); 30 + Submite.answer("{% url 'course:poll:answer_student_poll' poll.slug %}",$(this).serialize());
31 event.preventDefault(); 31 event.preventDefault();
32 }); 32 });
33 </script> 33 </script>
poll/templates/poll/view.html
@@ -30,6 +30,6 @@ @@ -30,6 +30,6 @@
30 {% block button_save %} 30 {% block button_save %}
31 <!-- Put curtom buttons here!!! --> 31 <!-- Put curtom buttons here!!! -->
32 {% if not status %} 32 {% if not status %}
33 -<button type="button" onclick="javascript:modal.get('{% url 'course:poll:answer_student_poll' poll.slug%}','#poll','#modal_poll');$('div.modal-backdrop.fade.in').remove();" class="btn btn-primary btn-raised">{% trans "Answer" %}</button> 33 +<button type="button" onclick="javascript:modal.get('{% url 'course:poll:answer_student_poll' poll.slug%}','#poll','#requisicoes_ajax');$('div.modal-backdrop.fade.in').remove();" class="btn btn-primary btn-raised">{% trans "Answer" %}</button>
34 {% endif %} 34 {% endif %}
35 {% endblock button_save %} 35 {% endblock button_save %}
@@ -116,6 +116,10 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin, LogMixin, NotificationMixin,ge @@ -116,6 +116,10 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin, LogMixin, NotificationMixin,ge
116 answer = Answer(answer=self.request.POST[key],order=key,poll=self.object) 116 answer = Answer(answer=self.request.POST[key],order=key,poll=self.object)
117 answer.save() 117 answer.save()
118 118
  119 + if (self.request.POST.get('all_students')):
  120 + for student in topic.subject.students.all():
  121 + self.object.students.add(student)
  122 +
119 self.log_context['poll_id'] = self.object.id 123 self.log_context['poll_id'] = self.object.id
120 self.log_context['poll_slug'] = self.object.slug 124 self.log_context['poll_slug'] = self.object.slug
121 self.log_context['topic_id'] = self.object.topic.id 125 self.log_context['topic_id'] = self.object.topic.id
@@ -136,11 +140,6 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin, LogMixin, NotificationMixin,ge @@ -136,11 +140,6 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin, LogMixin, NotificationMixin,ge
136 "edit":reverse_lazy('course:poll:render_poll_edit', kwargs={'slug' : self.object.slug}), 140 "edit":reverse_lazy('course:poll:render_poll_edit', kwargs={'slug' : self.object.slug}),
137 }) 141 })
138 142
139 -  
140 - # def get_success_url(self):  
141 - # self.success_url = redirect('course:poll:render_poll', slug = self.object.slug)  
142 - # return self.success_url  
143 -  
144 def get_context_data(self, **kwargs): 143 def get_context_data(self, **kwargs):
145 context = super(CreatePoll, self).get_context_data(**kwargs) 144 context = super(CreatePoll, self).get_context_data(**kwargs)
146 topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) 145 topic = get_object_or_404(Topic, slug = self.kwargs.get('slug'))