Skip to content

Commit aae7b91

Browse files
committed
add: handlers
1 parent 755c3cb commit aae7b91

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
650 Bytes
Binary file not shown.
3.23 KB
Binary file not shown.

handlers/functions.py

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import aiohttp_jinja2
2+
from datetime import datetime
3+
from components.add_data import add_user, add_crossroad, add_vote
4+
from components.add_data import get_user, get_crossroads, get_user_crossroads, get_user_votes
5+
6+
7+
async def main_page(request):
8+
applications = await get_crossroads()
9+
return aiohttp_jinja2.render_template('index.html', request, {'applications': applications})
10+
11+
12+
async def account_page(request):
13+
if request.method == 'POST':
14+
data = await request.post()
15+
crossroad_id = int(data['card_id'])
16+
await add_vote(current_user, crossroad_id)
17+
applications = await get_crossroads()
18+
return aiohttp_jinja2.render_template('account_page.html', request, {'user_name': name,
19+
'user_city': city,
20+
'user_role': role,
21+
'user_address': address,
22+
'user_mobile': mobile,
23+
'user_sex': sex,
24+
'applications': applications})
25+
26+
27+
async def user_applications(request):
28+
applications = await get_user_crossroads(current_user)
29+
return aiohttp_jinja2.render_template('user_applications.html', request, {'applications': applications})
30+
31+
32+
async def user_votes(request):
33+
applications = await get_user_votes(current_user)
34+
return aiohttp_jinja2.render_template('user_votes.html', request, {'applications': applications})
35+
36+
37+
async def sign_up(request):
38+
if request.method == 'POST':
39+
try:
40+
data = await request.post()
41+
name = data['name']
42+
role = data['role']
43+
city = data['city']
44+
address = data['address']
45+
mobile = data['mobile']
46+
sex = data['sex']
47+
login = data['login']
48+
password = data['password']
49+
await add_user(login, password, name, sex, city, address, mobile, role)
50+
status = 'Пользователь зарегестрирован'
51+
except:
52+
status = 'Произошла ошибка регистации, попробуйте снова'
53+
54+
return aiohttp_jinja2.render_template('signup_form.html', request, {'status': status})
55+
else:
56+
return aiohttp_jinja2.render_template('signup_form.html', request, {'': ''})
57+
58+
59+
async def sign_in(request):
60+
if request.method == 'POST':
61+
data = await request.post()
62+
login = data['login']
63+
password = data['password']
64+
record = await get_user(login, password)
65+
if record:
66+
global current_user, name, city, role, address, mobile, sex
67+
name = record.name
68+
city = record.city
69+
role = record.role
70+
address = record.address
71+
mobile = record.mobile
72+
sex = record.sex
73+
current_user = record.user_id
74+
applications = await get_crossroads()
75+
return aiohttp_jinja2.render_template('account_page.html', request, {'user_name': name,
76+
'user_city': city,
77+
'user_role': role,
78+
'user_address': address,
79+
'user_mobile': mobile,
80+
'user_sex': sex,
81+
'applications': applications})
82+
else:
83+
status = 'Неверно введен логин или пароль'
84+
return aiohttp_jinja2.render_template('signin_form.html', request, {'status': status})
85+
else:
86+
return aiohttp_jinja2.render_template('signin_form.html', request, {'': ''})
87+
88+
89+
async def create_application(request):
90+
if request.method == 'POST':
91+
try:
92+
data = await request.post()
93+
date = datetime.today().date()
94+
location = data['location']
95+
longitude = float(data['longitude'])
96+
latitude = float(data['latitude'])
97+
map = bytearray("test".encode("ascii"))
98+
description = data['description']
99+
votes_number = 1
100+
status = data['status']
101+
user_id = current_user
102+
await add_crossroad(date, location, longitude, latitude, map, description, votes_number, status, user_id)
103+
status = 'Обращение подано'
104+
return aiohttp_jinja2.render_template('crossroad_form.html', request, {'status': status})
105+
except:
106+
status = 'Произошла ошибка, попробуйте снова'
107+
return aiohttp_jinja2.render_template('crossroad_form.html', request, {'status': status})
108+
109+
else:
110+
return aiohttp_jinja2.render_template('crossroad_form.html', request, {'': ''})

0 commit comments

Comments
 (0)