Commit f91fd3cadab4d380210917a224ca06fcc2311d06
Exists in
master
and in
5 other branches
Merge branch 'dev' of https://github.com/amadeusproject/amadeuslms into dev
Showing
5 changed files
with
85 additions
and
21 deletions
Show diff stats
courses/templates/topic/index.html
@@ -148,23 +148,4 @@ | @@ -148,23 +148,4 @@ | ||
148 | 148 | ||
149 | </div> | 149 | </div> |
150 | </div> | 150 | </div> |
151 | - | ||
152 | -<button id="poll_teste">poll</button> | ||
153 | -<script type="text/javascript"> | ||
154 | - $("#poll_teste").click(function(){ | ||
155 | - if($('#poll').length){ | ||
156 | - $('#poll').modal('show'); | ||
157 | - } else { | ||
158 | - var url = "{% url 'course:poll:create_poll' topic.slug%}"; | ||
159 | - // alert(url); | ||
160 | - $.get(url, function(data){ | ||
161 | - $("#poll_t").append(data); | ||
162 | - $('#poll').modal('show'); | ||
163 | - }); | ||
164 | - } | ||
165 | - }); | ||
166 | -</script> | ||
167 | - | ||
168 | -<div class="row" id="poll_t"> | ||
169 | -</div> | ||
170 | {% endblock %} | 151 | {% endblock %} |
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +{% extends "poll/create.html" %} | ||
2 | + | ||
3 | +{% load i18n static dict_access %} | ||
4 | + | ||
5 | +{% block title_poll %} | ||
6 | +<!-- Put your title here!!! --> | ||
7 | +<h4 class="modal-title" id="myModalLabel">{{poll.name}}</h4> | ||
8 | +{% endblock title_poll %} | ||
9 | + | ||
10 | +{% block content_poll %} | ||
11 | +<form id="answer_form" class="" action="" method="post"> | ||
12 | + {% csrf_token %} | ||
13 | + {% for key in keys %} | ||
14 | + <div class="row form-group {% if form.has_error %} has-error {% endif %}"> | ||
15 | + <div class="col-md-10 col-sm-10 col-xs-10 col-lg-10"> | ||
16 | + <div class="checkbox"> | ||
17 | + <label> | ||
18 | + <input type="checkbox" name="{{key}}"><span class="checkbox-material"><span class="check"></span></span> {{ answers|value:key }} | ||
19 | + </label> | ||
20 | + </div> | ||
21 | + </div> | ||
22 | + </div> | ||
23 | + {% endfor %} | ||
24 | +</form> | ||
25 | +{% endblock content_poll %} | ||
26 | +{% block button_save %} | ||
27 | +<button type="submite" id="button" form="answer_form" class="btn btn-primary btn-raised">{% trans "Answer" %}</button> | ||
28 | +<script> | ||
29 | + $("#answer_form").submit(function(event) { | ||
30 | + Submite.post("{% url 'course:poll:answer_student_poll' poll.slug %}",$(this).serialize()); | ||
31 | + event.preventDefault(); | ||
32 | + }); | ||
33 | +</script> | ||
34 | +{% endblock button_save %} |
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" class="btn btn-primary btn-raised">{% trans "Answer" %}</button> | 33 | +<button type="button" onclick="javascript: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> |
34 | {% endif %} | 34 | {% endif %} |
35 | {% endblock button_save %} | 35 | {% endblock button_save %} |
poll/urls.py
@@ -8,4 +8,5 @@ urlpatterns = [ | @@ -8,4 +8,5 @@ urlpatterns = [ | ||
8 | url(r'^update/(?P<slug>[\w\-_]+)/$', views.UpdatePoll.as_view(), name='update_poll'), # poll slug | 8 | url(r'^update/(?P<slug>[\w\-_]+)/$', views.UpdatePoll.as_view(), name='update_poll'), # poll slug |
9 | url(r'^delete/(?P<slug>[\w\-_]+)/$', views.DeletePoll.as_view(), name='delete_poll'), # poll | 9 | url(r'^delete/(?P<slug>[\w\-_]+)/$', views.DeletePoll.as_view(), name='delete_poll'), # poll |
10 | url(r'^answer/$', views.AnswerPoll.as_view(), name='answer_poll'), # poll | 10 | url(r'^answer/$', views.AnswerPoll.as_view(), name='answer_poll'), # poll |
11 | + url(r'^answer-poll/(?P<slug>[\w\-_]+)/$', views.AnswerStudentPoll.as_view(), name='answer_student_poll'), # poll slug | ||
11 | ] | 12 | ] |
poll/views.py
@@ -33,7 +33,12 @@ class ViewPoll(LoginRequiredMixin,generic.DetailView): | @@ -33,7 +33,12 @@ class ViewPoll(LoginRequiredMixin,generic.DetailView): | ||
33 | context['course'] = poll.topic.subject.course | 33 | context['course'] = poll.topic.subject.course |
34 | context['subject'] = poll.topic.subject | 34 | context['subject'] = poll.topic.subject |
35 | context['subjects'] = poll.topic.subject.course.subjects.all() | 35 | context['subjects'] = poll.topic.subject.course.subjects.all() |
36 | - context['status'] = AnswersStudent.objects.get(poll=poll, student=self.request.user).status | 36 | + answered = AnswersStudent.objects.filter(poll = poll, student=self.request.user) |
37 | + print (answered) | ||
38 | + if answered.count()<1: | ||
39 | + context['status'] = False | ||
40 | + else: | ||
41 | + context['status'] = answered[0].status | ||
37 | return context | 42 | return context |
38 | 43 | ||
39 | 44 | ||
@@ -183,3 +188,46 @@ class DeletePoll(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | @@ -183,3 +188,46 @@ class DeletePoll(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | ||
183 | 188 | ||
184 | class AnswerPoll(generic.TemplateView): | 189 | class AnswerPoll(generic.TemplateView): |
185 | template_name = 'poll/answer.html' | 190 | template_name = 'poll/answer.html' |
191 | + | ||
192 | +class AnswerStudentPoll(LoginRequiredMixin,generic.CreateView): | ||
193 | + | ||
194 | + model = AnswersStudent | ||
195 | + fields = ['status'] | ||
196 | + context_object_name = 'answer' | ||
197 | + template_name = 'poll/answer_student.html' | ||
198 | + | ||
199 | + def form_valid(self, form): | ||
200 | + poll = get_object_or_404(Poll, slug = self.kwargs.get('slug')) | ||
201 | + answers = AnswersStudent( | ||
202 | + status = True, | ||
203 | + poll = poll, | ||
204 | + student = self.request.user, | ||
205 | + ) | ||
206 | + answers.save() | ||
207 | + | ||
208 | + for key in self.request.POST: | ||
209 | + if(key != 'csrfmiddlewaretoken'): | ||
210 | + answers.answer.add(poll.answers.all().filter(order=key)[0]) | ||
211 | + | ||
212 | + return self.render_to_response(self.get_context_data(form = form), status = 200) | ||
213 | + | ||
214 | + def get_context_data(self, **kwargs): | ||
215 | + context = super(AnswerStudentPoll, self).get_context_data(**kwargs) | ||
216 | + print (self.kwargs.get('slug')) | ||
217 | + poll = get_object_or_404(Poll, slug = self.kwargs.get('slug')) | ||
218 | + context['poll'] = poll | ||
219 | + context['topic'] = poll.topic | ||
220 | + context['course'] = poll.topic.subject.course | ||
221 | + context['subject'] = poll.topic.subject | ||
222 | + context['subjects'] = poll.topic.subject.course.subjects.all() | ||
223 | + | ||
224 | + print (self.request.method) | ||
225 | + answers = {} | ||
226 | + for answer in poll.answers.all(): | ||
227 | + answers[answer.order] = answer.answer | ||
228 | + | ||
229 | + keys = sorted(answers) | ||
230 | + context['answers'] = answers | ||
231 | + context['keys'] = keys | ||
232 | + | ||
233 | + return context |