-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
64 lines (55 loc) · 2.34 KB
/
views.py
File metadata and controls
64 lines (55 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from django.shortcuts import render
from django.http import HttpResponse
from .load_data import load_data, load_name
from .models import Wallet_indentificator, Wallet_value
from .ClearRepeatedDate import clear_repeated_date
def get_date(request, wallet_name_):
print('get_date')
try:
wallet = Wallet_indentificator.objects.get(wallet_name=wallet_name_)
wallet_values = Wallet_value.objects.filter(wallet=wallet).order_by(
'-date')
except:
clear_repeated_date()
wallet = Wallet_indentificator.objects.get(wallet_name=wallet_name_)
wallet_values = Wallet_value.objects.filter(wallet=wallet).order_by(
'-date')
if len(wallet_values) > 10:
wallet_values = wallet_values[:10]
dates = []
for i in wallet_values:
dates += [str(i.date)]
return render(request, 'Wallet/choose_date.html',
{'wallet': wallet, 'dates_in_memory': dates})
def add_date(request, wallet_name_):
date_ = '-'.join(request.POST['date'].split('/')[::-1])
wallet = Wallet_indentificator.objects.get(wallet_name=wallet_name_)
try:
load_data(request.POST['date'])
wallet_info = Wallet_value.objects.get(wallet=wallet, date=date_)
return render(request, 'Wallet/wallet.html',
{'wallet': wallet, 'wallet_info': wallet_info})
except:
return HttpResponse('Нет данных на этот день')
def show_wallet(request, wallet_name_, wallet_date_=None):
if wallet_date_ is None:
date_ = '-'.join(request.POST['date'].split('/')[::-1])
else:
date_ = wallet_date_
wallet = Wallet_indentificator.objects.get(wallet_name=wallet_name_)
try:
wallet_info = Wallet_value.objects.get(wallet=wallet, date=date_)
return render(request, 'Wallet/wallet.html',
{'wallet': wallet, 'wallet_info': wallet_info})
except:
return add_date(request, wallet_name_)
def main_page(request):
wallet_names = []
wallets_list = Wallet_indentificator.objects.all().order_by('wallet_name')
if len(wallets_list) == 0:
load_name()
wallets_list = Wallet_indentificator.objects.all()
for wallet in wallets_list:
wallet_names += [wallet.wallet_name]
return render(request, 'Wallet/list.html',
{'wallets_list': wallet_names})