53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
import os
|
|
|
|
from django.http import HttpResponse, HttpResponseRedirect
|
|
from django.shortcuts import render
|
|
# from django.db.models import Manager
|
|
from django.contrib.auth import authenticate, login
|
|
|
|
# только для тестирования!
|
|
import requests
|
|
|
|
TEST_BASE_FETCH = "https://test.wawaa.ru/dev-fetch.php"
|
|
|
|
|
|
def view_index(request):
|
|
return render(request, 'index.html')
|
|
# if request.user.is_authenticated:
|
|
# return render(request, 'index.html')
|
|
# else:
|
|
# return HttpResponseRedirect()
|
|
|
|
|
|
def view_stats(request):
|
|
# только для тестирования!
|
|
res = requests.get(TEST_BASE_FETCH + "?stats", headers={'Authorization': os.getenv("TEST_AUTH")})
|
|
response = HttpResponse(res.content)
|
|
response.headers["Content-type"] = response.headers["Content-type"]
|
|
return response
|
|
|
|
|
|
def view_tank_chart(request):
|
|
# только для тестирования!
|
|
days = request.GET.get('days', '7')
|
|
res = requests.get(TEST_BASE_FETCH + "?tank_chart=" + days, headers={'Authorization': os.getenv("TEST_AUTH")})
|
|
response = HttpResponse(res.content)
|
|
response.headers["Content-type"] = response.headers["Content-type"]
|
|
return response
|
|
|
|
|
|
# вход
|
|
|
|
|
|
def view_login(request):
|
|
username = request.POST["username"]
|
|
password = request.POST["password"]
|
|
user = authenticate(request, username=username, password=password)
|
|
if user is not None:
|
|
login(request, user)
|
|
return HttpResponseRedirect('/')
|
|
else:
|
|
# Return an 'invalid login' error message.
|
|
pass
|
|
|