paov 4 years ago
parent bed78cea96
commit 9debcb9846
  1. 2
      choose/templates/vote.html
  2. 14
      choose/views.py

@ -7,7 +7,7 @@
<body>
<button class="btn" onclick="location.replace('/logout');">Выйти</button>
{% if not voted %}
<button class="btn" onclick="location.href='/choose'">Проголосовать</button>
<button class="btn" onclick="location.href='/choose'">Предложить свой набор чаев</button>
{% endif %}
<table>
<tbody>

@ -40,7 +40,7 @@ def list_of_teas():
tt.preferred.pic.href)
dic[tt.category.name][tt.name]['ms'] = [tt.preferred.m * x for x in range(0, 11)]
return {'categories': dic}
return dic
def list_of_choices(request):
@ -48,7 +48,7 @@ def list_of_choices(request):
voted = False
my_choice = Choice.objects.filter(users__in=[request.user]).first()
if my_choice is not None:
voted =True
voted = True
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()],
@ -69,9 +69,17 @@ def list_of_choices(request):
return {'choices': arr, 'voted': voted}
def get_my_choice(request):
my_choice = Choice.objects.filter(users__in=[request.user]).first()
if my_choice is None:
return {}
else:
return {tea_id: str(mass) for tea_id, mass in json.loads(my_choice.choice).items()}
@login_requiered
def choose(request):
context = list_of_teas()
context = {'categories': list_of_teas(), 'teas': get_my_choice(request)}
template = loader.get_template('choose.html')
return HttpResponse(template.render(context, request))

Loading…
Cancel
Save