diff --git a/choose/templates/choose.html b/choose/templates/choose.html index 060789e..7453280 100644 --- a/choose/templates/choose.html +++ b/choose/templates/choose.html @@ -2,11 +2,9 @@ - Title + Choose your set of tea - @@ -33,15 +31,20 @@
- + {{ type_name }} {{ type.price }} - +
+ +
+
+
0 @@ -52,7 +55,7 @@ {% endfor %}

0

- + @@ -159,8 +165,8 @@ text-align: left; border: none; padding: 10px 15px; - font-size: 14px; - vertical-align: top; + font-size: 16px; + vertical-align: center; } table tbody tr:nth-child(even) { @@ -184,5 +190,96 @@ margin-top: 0px; margin-bottom: 0px; } + + + .selector { + padding-left: 10px; + } + + .select-wrapper { + width: 65px; + position: relative; + height: 38px; + color: #444; + background: transparent; + border: 1px solid #bcbcbc; + border-radius: 5px; + + } + + .select-wrapper > select { + width: 100%; + height: 37px; + background: transparent; + border: 0; + appearance: none; + z-index: 1; + -webkit-appearance: none; + -moz-appearance: none; + } + + .select-wrapper > select::-ms-expand { + display: none; + } + + .select-arrow { + position: absolute; + z-index: -1; + border: 8px solid transparent; + border-bottom: 0; + right: 11px; + } + + .select-arrow:nth-child(2) { + top: 15px; + border-top-color: #bdbdbd; + } + + .select-arrow:nth-child(3) { + top: 13px; + border-top-color: #FFF; + } + + .btn { + display: inline-block; + box-sizing: border-box; + padding: 0 13px; + margin: 0 15px 15px 0; + outline: none; + border: 1px solid transparent; + border-radius: 3px; + height: 32px; + line-height: 32px; + font-size: 14px; + font-weight: 500; + text-decoration: none; + color: #fff; + background-color: #65a3be; + cursor: pointer; + user-select: none; + appearance: none; + touch-action: manipulation; + } + + .btn:focus-visible { + box-shadow: 0 0 0 3px lightskyblue; + } + + .btn:hover { + border-color: transparent; + background-color: #4986a1; + color: #fff; + } + + .btn:active { + border-color: #6f9cbc !important; + background-color: #367089 !important; + } + + .btn:disabled { + background-color: #afafaf; + color: #fff; + pointer-events: none; + } \ No newline at end of file diff --git a/choose/templates/vote.html b/choose/templates/vote.html index e5aaf31..20e8322 100644 --- a/choose/templates/vote.html +++ b/choose/templates/vote.html @@ -5,12 +5,16 @@ Title +{% if not voted %} + +{% endif %} + {% for choice in choices %} @@ -37,11 +41,19 @@ + @@ -77,8 +89,8 @@ text-align: left; border: none; padding: 10px 15px; - font-size: 14px; - vertical-align: top; + font-size: 16px; + vertical-align: center; } table tbody tr:nth-child(even) { @@ -107,6 +119,48 @@ padding-inline-start: 10px; } + .btn { + display: inline-block; + box-sizing: border-box; + padding: 0 13px; + margin: 0 15px 15px 0; + outline: none; + border: 1px solid transparent; + border-radius: 3px; + height: 32px; + line-height: 32px; + font-size: 14px; + font-weight: 500; + text-decoration: none; + color: #fff; + background-color: #65a3be; + cursor: pointer; + user-select: none; + appearance: none; + touch-action: manipulation; + } + + .btn:focus-visible { + box-shadow: 0 0 0 3px lightskyblue; + } + + .btn:hover { + border-color: transparent; + background-color: #4986a1; + color: #fff; + } + + .btn:active { + border-color: #6f9cbc !important; + background-color: #367089 !important; + } + + .btn:disabled { + background-color: #afafaf; + color: #fff; + pointer-events: none; + } + diff --git a/choose/views.py b/choose/views.py index 81a2c16..b9b0ed0 100644 --- a/choose/views.py +++ b/choose/views.py @@ -44,12 +44,14 @@ def list_of_teas(): def list_of_choices(request): arr = [] - + voted = False my_choice = Choice.objects.filter(users__in=[request.user]).first() if my_choice is not None: + 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()], + 'votes': len(list(my_choice.votes.all())) + len(list(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}) @@ -59,10 +61,11 @@ def list_of_choices(request): for choice in choices: arr.append({'voted': [user.username for user in choice.votes.all()], 'chosed': [user.username for user in choice.users.all()], + 'votes': len(list(choice.votes.all())) + len(list(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} + return {'choices': arr, 'voted': voted} @login_requiered @@ -72,6 +75,7 @@ def choose(request): return HttpResponse(template.render(context, request)) +@login_requiered def home(request): context = list_of_choices(request) template = loader.get_template('vote.html') @@ -118,3 +122,19 @@ def confirm_vote(request): return JsonResponse({'response': 'ok'}) else: return JsonResponse({'response': 'unauthenticated'}) + + +def confirm_cancel_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': 'WAT'}) + choice.votes.remove(request.user) + return JsonResponse({'response': 'ok'}) + else: + return JsonResponse({'response': 'unauthenticated'}) diff --git a/tea/urls.py b/tea/urls.py index abb491b..115fd5d 100644 --- a/tea/urls.py +++ b/tea/urls.py @@ -1,18 +1,3 @@ -"""tea URL Configuration - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/4.1/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" from django.contrib import admin from django.urls import path, include from django.conf import settings @@ -26,7 +11,8 @@ urlpatterns = [ path('choose', choose.views.choose, name='choose'), path('vote', choose.views.home, name='home'), path('confirm-choice', choose.views.confirm_choose), - path('confirm-vote', choose.views.confirm_choose), + path('confirm-vote', choose.views.confirm_vote), + path('confirm-cancel-vote', choose.views.confirm_cancel_vote), path('login', choose.views.login_view, name='login_view') ] if settings.DEBUG:
Список чаев Выбрали ПроголосовалиВсего голосов
+ {{ choice.votes }} + {% if choice.class == 'choice' %} - + + {% endif %} {% if choice.class == 'my_choice' %} - + {% endif %}