Release 15 - Revamp #38
5 changed files with 10 additions and 21 deletions
|
@ -26,7 +26,6 @@ class CustomAdminSite(admin.AdminSite):
|
||||||
|
|
||||||
@method_decorator(never_cache)
|
@method_decorator(never_cache)
|
||||||
def index(self, request, extra_context=None):
|
def index(self, request, extra_context=None):
|
||||||
|
|
||||||
return super().index(request, extra_context={
|
return super().index(request, extra_context={
|
||||||
"admin_info": Global.objects.get(name="admin_info").value_string,
|
"admin_info": Global.objects.get(name="admin_info").value_string,
|
||||||
**(extra_context or {})
|
**(extra_context or {})
|
||||||
|
|
|
@ -2,8 +2,8 @@ from django.conf import settings
|
||||||
|
|
||||||
from .models import Global
|
from .models import Global
|
||||||
|
|
||||||
def app_version(request):
|
|
||||||
|
|
||||||
|
def app_version(request):
|
||||||
try:
|
try:
|
||||||
global_message = Global.objects.get(pk="global_message").value_string
|
global_message = Global.objects.get(pk="global_message").value_string
|
||||||
except Global.DoesNotExist:
|
except Global.DoesNotExist:
|
||||||
|
|
|
@ -6,7 +6,6 @@ from django.forms import ValidationError
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Custom user model
|
# Custom user model
|
||||||
class User(AbstractUser):
|
class User(AbstractUser):
|
||||||
|
|
||||||
|
@ -24,8 +23,6 @@ class User(AbstractUser):
|
||||||
self.email = ""
|
self.email = ""
|
||||||
super().save()
|
super().save()
|
||||||
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
class Drink(models.Model):
|
class Drink(models.Model):
|
||||||
|
|
||||||
|
@ -45,7 +42,8 @@ class Drink(models.Model):
|
||||||
self.deleted = True
|
self.deleted = True
|
||||||
super().save()
|
super().save()
|
||||||
|
|
||||||
def __str__(self): return f"{self.product_name} ({float(self.content_litres):.2f}l) - {self.price}{settings.CURRENCY_SUFFIX}"
|
def __str__(self):
|
||||||
|
return f"{self.product_name} ({float(self.content_litres):.2f}l) - {self.price}{settings.CURRENCY_SUFFIX}"
|
||||||
|
|
||||||
|
|
||||||
class RegisterTransaction(models.Model):
|
class RegisterTransaction(models.Model):
|
||||||
|
|
|
@ -60,6 +60,7 @@ def select_yopml12m(user) -> list:
|
||||||
""")
|
""")
|
||||||
return [list(row) for row in result]
|
return [list(row) for row in result]
|
||||||
|
|
||||||
|
|
||||||
def select_aopml12m() -> list:
|
def select_aopml12m() -> list:
|
||||||
# number of orders per month (last 12 months)
|
# number of orders per month (last 12 months)
|
||||||
result = _select_from_db(f"""
|
result = _select_from_db(f"""
|
||||||
|
@ -92,6 +93,7 @@ def select_yopwd(user) -> list:
|
||||||
return [list(row) for row in result]
|
return [list(row) for row in result]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def select_aopwd() -> list:
|
def select_aopwd() -> list:
|
||||||
# number of orders per weekday (all time)
|
# number of orders per weekday (all time)
|
||||||
result = _select_from_db(f"""
|
result = _select_from_db(f"""
|
||||||
|
@ -123,6 +125,7 @@ def select_noyopd(user) -> list:
|
||||||
""")
|
""")
|
||||||
return [list(row) for row in result]
|
return [list(row) for row in result]
|
||||||
|
|
||||||
|
|
||||||
def select_noaopd() -> list:
|
def select_noaopd() -> list:
|
||||||
# number of orders per drink (all time)
|
# number of orders per drink (all time)
|
||||||
result = _select_from_db(f"""
|
result = _select_from_db(f"""
|
||||||
|
@ -134,4 +137,4 @@ def select_noaopd() -> list:
|
||||||
group by d.product_name
|
group by d.product_name
|
||||||
order by "data" desc;
|
order by "data" desc;
|
||||||
""")
|
""")
|
||||||
return [list(row) for row in result]
|
return [list(row) for row in result]
|
||||||
|
|
17
app/views.py
17
app/views.py
|
@ -25,17 +25,12 @@ from .models import RegisterTransaction
|
||||||
|
|
||||||
|
|
||||||
def login_page(request):
|
def login_page(request):
|
||||||
|
|
||||||
userlist = get_user_model().objects.filter(is_superuser=False).filter(is_active=True).order_by("username")
|
userlist = get_user_model().objects.filter(is_superuser=False).filter(is_active=True).order_by("username")
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
|
|
||||||
form = AuthenticationForm(request.POST)
|
form = AuthenticationForm(request.POST)
|
||||||
username = request.POST['username']
|
username = request.POST['username']
|
||||||
password = request.POST['password']
|
password = request.POST['password']
|
||||||
|
|
||||||
user = authenticate(username=username,password=password)
|
user = authenticate(username=username,password=password)
|
||||||
|
|
||||||
if user:
|
if user:
|
||||||
if user.is_active:
|
if user.is_active:
|
||||||
login(request, user)
|
login(request, user)
|
||||||
|
@ -46,14 +41,10 @@ def login_page(request):
|
||||||
"user_list": userlist,
|
"user_list": userlist,
|
||||||
"error_message": _("Invalid username or password.")
|
"error_message": _("Invalid username or password.")
|
||||||
})
|
})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
return HttpResponseRedirect("/")
|
return HttpResponseRedirect("/")
|
||||||
|
|
||||||
form = AuthenticationForm()
|
form = AuthenticationForm()
|
||||||
|
|
||||||
return render(request,'registration/login.html', {
|
return render(request,'registration/login.html', {
|
||||||
"form": form,
|
"form": form,
|
||||||
"user_list": userlist
|
"user_list": userlist
|
||||||
|
@ -80,9 +71,7 @@ def history(request):
|
||||||
def order(request, drinkid):
|
def order(request, drinkid):
|
||||||
try:
|
try:
|
||||||
drink_ = Drink.objects.get(pk=drinkid)
|
drink_ = Drink.objects.get(pk=drinkid)
|
||||||
context = {
|
context = {"drink": drink_}
|
||||||
"drink": drink_
|
|
||||||
}
|
|
||||||
return render(request, "order.html", context)
|
return render(request, "order.html", context)
|
||||||
except Drink.DoesNotExist:
|
except Drink.DoesNotExist:
|
||||||
return HttpResponseRedirect("/")
|
return HttpResponseRedirect("/")
|
||||||
|
@ -150,14 +139,14 @@ def api_deposit(request):
|
||||||
transaction_sum=amount,
|
transaction_sum=amount,
|
||||||
comment=f"User deposit by user {user.username}",
|
comment=f"User deposit by user {user.username}",
|
||||||
is_user_deposit=True,
|
is_user_deposit=True,
|
||||||
user=user
|
user=user)
|
||||||
)
|
|
||||||
return HttpResponse("success", status=200)
|
return HttpResponse("success", status=200)
|
||||||
else: raise Exception("Deposit amount too big or small.")
|
else: raise Exception("Deposit amount too big or small.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An exception occured while processing a transaction: User: {user.username} - Exception: {e}", file=sys.stderr)
|
print(f"An exception occured while processing a transaction: User: {user.username} - Exception: {e}", file=sys.stderr)
|
||||||
return HttpResponse(b"", status=500)
|
return HttpResponse(b"", status=500)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def api_supply(request):
|
def api_supply(request):
|
||||||
# check request -> supply
|
# check request -> supply
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue