def dashboard_polls_create(request): if request.user.is_staff: if request.method == 'POST': Poll.createPoll(request) return redirect('app_poller:dashboard_polls') else: context = {} context['questions'] = Question.getAllQuestions() return render(request, 'dashboard/polls_create.html', context) else: return redirect('app_poller:dashboard')
def dashboard_polls(request): if request.user.is_staff: context = {} context['polls'] = Poll.getAllPolls() return render(request, 'dashboard/polls.html', context) else: return redirect('app_poller:dashboard')
def dashboard_answers_user(request, id, userid): if request.user.is_staff: context = {} answer = Answer.getUserAnswer(id, userid) context['answer'] = answer context['poll'] = Poll.getPollById(id) return render(request, 'dashboard/user_answer.html', context) else: return redirect('app_poller:dashboard')
def dashboard_tests(request): if request.user.is_staff: return redirect('app_poller:dashboard') elif request.user.is_authenticated: context = {} context['polls'] = Poll.getAllPolls() context['exists_answer'] = Answer.getExistAnswer(request) return render(request, 'dashboard/tests.html', context) else: return redirect('app_poller:home')
def dashboard_polls_edit(request, id): if request.user.is_staff: context = {} if request.method == 'POST': Poll.editPoll(request, id) return redirect('app_poller:dashboard_polls') else: poll = Poll.getEditPoll(id) if poll == None: raise Http404 else: poll.time_to_answer = time.strftime( '%H:%M', time.gmtime(poll.time_to_answer)) context['poll'] = poll context['ids'] = [x.id for x in poll.questions.all()] context['questions'] = Question.getAllQuestions() return render(request, 'dashboard/polls_edit.html', context) else: return redirect('app_poller:dashboard')
def dashboard_tests_take(request, id): if request.user.is_staff: return redirect('app_poller:dashboard') elif request.user.is_authenticated: if request.method == 'POST': Answer.saveAnswer(request, id) return redirect('app_poller:dashboard_tests') if Answer.objects.filter(poll=id, user=request.user.id).exists(): raise Http404 poll = Poll.getPollById(id) if poll == None: raise Http404 now = date.today() pub = poll[0].publishing_time fin = poll[0].finishing_time if now < pub or now > fin: raise Http404 context = {} context['poll'] = poll return render(request, 'dashboard/tests_take.html', context) else: return redirect('app_poller:home')
def dashboard_polls_delete(request, id): if request.user.is_staff: Poll.deletePoll(id) return redirect('app_poller:dashboard_polls') else: return redirect('app_poller:dashboard')