Commit fd16faeeed70b62841181989ff2980c18b1ce8f2
1 parent
4592a965
Exists in
master
and in
5 other branches
Adding time spent to answer poll in log [Issue: #244]
Showing
1 changed file
with
21 additions
and
0 deletions
Show diff stats
poll/views.py
... | ... | @@ -290,6 +290,12 @@ class AnswerStudentPoll(LoginRequiredMixin, LogMixin, generic.CreateView): |
290 | 290 | context_object_name = 'answer' |
291 | 291 | template_name = 'poll/answer_student.html' |
292 | 292 | |
293 | + def dispatch(self, *args, **kwargs): | |
294 | + if self.request.method == 'GET': | |
295 | + self.request.session['time_spent'] = str(datetime.datetime.now()) | |
296 | + | |
297 | + return super(AnswerStudentPoll, self).dispatch(*args, **kwargs) | |
298 | + | |
293 | 299 | def form_valid(self, form): |
294 | 300 | poll = get_object_or_404(Poll, slug = self.kwargs.get('slug')) |
295 | 301 | answers = AnswersStudent( |
... | ... | @@ -317,6 +323,21 @@ class AnswerStudentPoll(LoginRequiredMixin, LogMixin, generic.CreateView): |
317 | 323 | self.log_context['course_category_id'] = poll.topic.subject.course.category.id |
318 | 324 | self.log_context['course_category_name'] = poll.topic.subject.course.category.name |
319 | 325 | |
326 | + date_time_click = datetime.datetime.strptime(self.request.session.get('time_spent'), "%Y-%m-%d %H:%M:%S.%f") | |
327 | + _now = datetime.datetime.now() | |
328 | + | |
329 | + time_spent = _now - date_time_click | |
330 | + | |
331 | + secs = time_spent.total_seconds() | |
332 | + hours = int(secs / 3600) | |
333 | + minutes = int(secs / 60) % 60 | |
334 | + secs = secs % 60 | |
335 | + | |
336 | + self.log_context['time_spent'] = {} | |
337 | + self.log_context['time_spent']['hours'] = hours | |
338 | + self.log_context['time_spent']['minutes'] = minutes | |
339 | + self.log_context['time_spent']['seconds'] = secs | |
340 | + | |
320 | 341 | super(AnswerStudentPoll, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
321 | 342 | |
322 | 343 | return self.render_to_response(self.get_context_data(form = form), status = 200) | ... | ... |