|
|
|
|
@ -42,42 +42,17 @@ def list_of_teas(): |
|
|
|
|
return {'categories': dic, 'ms': [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500]} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def list_of_choices(request): |
|
|
|
|
arr = [] |
|
|
|
|
|
|
|
|
|
my_choice = Choice.objects.filter(users__in=[request.user]).first() |
|
|
|
|
if my_choice is not None: |
|
|
|
|
json.loads(my_choice.choice) |
|
|
|
|
arr.append({'voted': [user.username for user in my_choice.votes.all()], |
|
|
|
|
'chosed': [user.username for user in my_choice.users.all()], |
|
|
|
|
'teas': sorted([Tea.objects.get(id=int(tea_id)).name + ':' + str(mass) for tea_id, mass in |
|
|
|
|
json.loads(my_choice.choice).items()]), |
|
|
|
|
'class': 'my_choice', 'id': my_choice.id}) |
|
|
|
|
choices = list(Choice.objects.all().exclude(id=my_choice.id)) |
|
|
|
|
else: |
|
|
|
|
choices = list(Choice.objects.all()) |
|
|
|
|
for choice in choices: |
|
|
|
|
arr.append({'voted': [user.username for user in choice.votes.all()], |
|
|
|
|
'chosed': [user.username for user in choice.users.all()], |
|
|
|
|
'teas': sorted([Tea.objects.get(id=int(tea_id)).name + ':' + str(mass) for tea_id, mass in |
|
|
|
|
json.loads(choice.choice).items()]), |
|
|
|
|
'class': 'choice', 'id': choice.id}) |
|
|
|
|
return {'choices': arr} |
|
|
|
|
def list_of_choices(): |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_requiered |
|
|
|
|
def choose(request): |
|
|
|
|
def home(request): |
|
|
|
|
context = list_of_teas() |
|
|
|
|
template = loader.get_template('choose.html') |
|
|
|
|
return HttpResponse(template.render(context, request)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def home(request): |
|
|
|
|
context = list_of_choices(request) |
|
|
|
|
template = loader.get_template('vote.html') |
|
|
|
|
return HttpResponse(template.render(context, request)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def confirm_choose(request): |
|
|
|
|
if request.user.is_authenticated: |
|
|
|
|
choice = json.loads(request.body.decode(encoding='UTF-8')) |
|
|
|
|
@ -102,19 +77,3 @@ def confirm_choose(request): |
|
|
|
|
return JsonResponse({'response': 'ok'}) |
|
|
|
|
else: |
|
|
|
|
return JsonResponse({'response': 'unauthenticated'}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def confirm_vote(request): |
|
|
|
|
if request.user.is_authenticated: |
|
|
|
|
vote = json.loads(request.body.decode(encoding='UTF-8')) |
|
|
|
|
choice = Choice.objects.filter(id=vote['vote']).first() |
|
|
|
|
if choice is None: |
|
|
|
|
return JsonResponse({'response': 'not found'}) |
|
|
|
|
my_choice = Choice.objects.filter(users__in=[request.user]).first() |
|
|
|
|
if my_choice is not None: |
|
|
|
|
if my_choice.id == choice.id: |
|
|
|
|
return JsonResponse({'response': 'FUK U'}) |
|
|
|
|
choice.votes.add(request.user) |
|
|
|
|
return JsonResponse({'response': 'ok'}) |
|
|
|
|
else: |
|
|
|
|
return JsonResponse({'response': 'unauthenticated'}) |
|
|
|
|
|