def admin(request): current_user = request.user if current_user is None or not current_user.is_authenticated: return redirect('login') if current_user.is_superuser: logger.info('Admin joined %s', current_user.get_username()) running = RunningPolls().POLL_RUNNING submit = RunningPolls().SUBMIT return render(request, 'admin.html', context={ 'running': running, 'submit': submit, 'username': current_user.get_username(), 'top': RunningPolls().current_top() }) else: return redirect('index', is_first=0)
def index(request, is_first): current_user = request.user if current_user is None or not current_user.is_authenticated: return redirect('login') if request.method == 'GET': logger.info('%s is first %d', current_user.get_username(), is_first) if type(is_first) != int or is_first > 2 or is_first < 0: return redirect('index', is_first=0) if is_first > 0 and not RunningPolls().POLL_RUNNING: return redirect('index', is_first=0) return render(request, 'index.html', context={ 'rnd_text': random.choice([[ 'Засылай', 'Жми', 'Тыкай', 'Давай', 'Го', 'Не спеши', 'Подумай', 'Ясно жми', ':)' ], [ 'Хорош', 'Ну все - ты первый', 'Ура', 'Молодчина', ], [ 'В следующий раз повезет', 'Тормоз', 'Черепаха', 'Быстрее надо было', 'Долго думаешь' ]][is_first]), 'button_cls': ['btn-primary', 'btn-success', 'btn-danger'][is_first], 'username': current_user.get_username(), 'top': RunningPolls().current_top() }) else: return redirect('submit')
def submit(request): username = request.user.get_username() logger.info('Username %s submitted', username) is_first = RunningPolls().ask(username) return redirect('index', is_first=is_first)
def skip(request): if request.user is None or not request.user.is_superuser: return redirect('login') RunningPolls().skip_submit() return redirect('admin')
def decline(request): if request.user is None or not request.user.is_superuser: return redirect('login') RunningPolls().decline_winner() RunningPolls().stop_poll() return redirect('admin')
def run_poll(request): if request.user is None or not request.user.is_superuser: return redirect('login') RunningPolls().run_poll() return redirect('admin')