diff --git a/courses/templatetags/list_topic_foruns.py b/courses/templatetags/list_topic_foruns.py index 809e41c..ef38b60 100644 --- a/courses/templatetags/list_topic_foruns.py +++ b/courses/templatetags/list_topic_foruns.py @@ -4,6 +4,7 @@ from links.models import Link from forum.models import Forum from poll.models import Poll from files.models import TopicFile +from django.db.models import Q register = template.Library() """ @@ -27,8 +28,13 @@ def list_topic_poll(request, topic): context = { 'request': request, } - - context['polls'] = Poll.objects.filter(topic = topic) + all_polls = Poll.objects.filter(topic = topic) + my_polls = [] + for poll in all_polls.all(): + if ((request.user in poll.students.all()) + or request.user in poll.topic.subject.professors.all()): + my_polls.append(poll) + context['polls'] = my_polls context['topic'] = topic return context diff --git a/poll/static/js/modal_poll.js b/poll/static/js/modal_poll.js index 42e4557..b37b0c8 100644 --- a/poll/static/js/modal_poll.js +++ b/poll/static/js/modal_poll.js @@ -1,10 +1,3 @@ -// -// //controles do modal -// $(window).ready(function() { // utilizado para abrir o modal quando tiver tido algum erro no preenchimento do formulario -// if($('.not_submited').length){ -// $('#poll').modal('show'); -// } -// }); var Answer = { init: function(url) { // utilizado para adicionar um novo campo de resposta @@ -38,7 +31,8 @@ var Submite = { } }); $("#requisicoes_ajax").empty(); - alertify.alert('Poll successfully created!'); + $('body').removeClass('modal-open'); + alertify.success('Poll successfully created!'); $("div.modal-backdrop.fade.in").remove(); }).fail(function(data){ $("div.modal-backdrop.fade.in").remove(); @@ -52,7 +46,8 @@ var Submite = { $.post(url,dados, function(data){ $('#list-topic-'+ slug_topic +'-poll #'+slug_poll).replaceWith(data); $('#list-topic-'+ slug_topic +'-poll #'+slug_poll).replaceWith(data); - alertify.alert('Poll successfully updated!') + $('body').removeClass('modal-open'); + alertify.success('Poll successfully updated!') }).fail(function(data){ $("div.modal-backdrop.fade.in").remove(); $("#requisicoes_ajax").empty(); @@ -65,12 +60,25 @@ var Submite = { $.post(url,dados, function(data){ $(id_li_link).remove(); $(id_li_link+"_div").remove(); + $('body').removeClass('modal-open'); $("#requisicoes_ajax").empty(); $("div.modal-backdrop.fade.in").remove(); + alertify.success('Poll successfully removed') }).fail(function(){ $("#requisicoes_ajax").empty(); $("#requisicoes_ajax").append(data); $('#poll').modal('show'); }); + }, + answer: function(url,dados){ + $('#poll').modal('hide'); + $.post(url,dados, function(data){ + alertify.success('Poll successfully answered!') + }).fail(function(data){ + $("div.modal-backdrop.fade.in").remove(); + $("#requisicoes_ajax").empty(); + $("#requisicoes_ajax").append(data.responseText); + $('#poll').modal('show'); + }); } } diff --git a/poll/templates/poll/answer_student.html b/poll/templates/poll/answer_student.html index 5a66f3c..187dd3b 100644 --- a/poll/templates/poll/answer_student.html +++ b/poll/templates/poll/answer_student.html @@ -27,7 +27,7 @@ diff --git a/poll/templates/poll/view.html b/poll/templates/poll/view.html index bc00279..5d24da5 100644 --- a/poll/templates/poll/view.html +++ b/poll/templates/poll/view.html @@ -30,6 +30,6 @@ {% block button_save %} {% if not status %} - + {% endif %} {% endblock button_save %} diff --git a/poll/views.py b/poll/views.py index bfcb08a..d28adfe 100644 --- a/poll/views.py +++ b/poll/views.py @@ -116,6 +116,10 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin, LogMixin, NotificationMixin,ge answer = Answer(answer=self.request.POST[key],order=key,poll=self.object) answer.save() + if (self.request.POST.get('all_students')): + for student in topic.subject.students.all(): + self.object.students.add(student) + self.log_context['poll_id'] = self.object.id self.log_context['poll_slug'] = self.object.slug self.log_context['topic_id'] = self.object.topic.id @@ -136,11 +140,6 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin, LogMixin, NotificationMixin,ge "edit":reverse_lazy('course:poll:render_poll_edit', kwargs={'slug' : self.object.slug}), }) - - # def get_success_url(self): - # self.success_url = redirect('course:poll:render_poll', slug = self.object.slug) - # return self.success_url - def get_context_data(self, **kwargs): context = super(CreatePoll, self).get_context_data(**kwargs) topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) -- libgit2 0.21.2