3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-05 17:36:28 +00:00
coope/coopeV3/views.py

53 lines
2 KiB
Python
Raw Normal View History

2019-07-03 16:41:41 +00:00
import os
2019-01-19 22:39:48 +00:00
from django.shortcuts import redirect, render
from django.urls import reverse
2019-07-03 16:41:41 +00:00
from django.conf import settings
2019-01-19 22:39:48 +00:00
from preferences.models import GeneralPreferences
from gestion.models import Keg
def home(request):
2019-02-28 12:18:41 +00:00
"""
Redirect the user either to :func:`~gestion.views.manage` view (if connected and staff) or :func:`~coopeV3.views.homepage` view (if connected and not staff) or :func:`~users.views.loginView` view (if not connected).
"""
2018-10-05 22:03:02 +00:00
if request.user.is_authenticated:
if(request.user.has_perm('gestion.can_manage')):
return redirect(reverse('gestion:manage'))
else:
2019-01-19 22:39:48 +00:00
return redirect(reverse('homepage'))
else:
return redirect(reverse('users:login'))
2019-01-19 22:39:48 +00:00
def homepage(request):
2019-02-28 12:18:41 +00:00
"""
View which displays the :attr:`~preferences.models.GeneralPreferences.home_text` and active :class:`Kegs <gestion.models.Keg>`.
"""
2019-01-19 22:39:48 +00:00
gp, _ = GeneralPreferences.objects.get_or_create(pk=1)
kegs = Keg.objects.filter(is_active=True)
return render(request, "home.html", {"home_text": gp.home_text, "kegs": kegs})
2019-01-20 08:28:11 +00:00
def coope_runner(request):
2019-02-28 12:18:41 +00:00
"""
Just an easter egg
"""
2019-01-20 08:28:11 +00:00
return render(request, "coope-runner.html")
2019-07-03 16:41:41 +00:00
def about(request):
"""
A page about the project
"""
os.system("git -C " + settings.BASE_DIR + " shortlog -n $@ | grep \"):\" | sed 's|:||' >> " + settings.BASE_DIR + "/contributors.txt")
contributors = []
with open(settings.BASE_DIR + "/contributors.txt", "r") as f:
for line in f:
print(line)
print(line.split(" ")[0])
contributors.append((line.split(" ")[0], int(line.split(" ")[1].replace("(", "").replace(")", "").replace("\n", ""))))
os.system("rm " + settings.BASE_DIR + "/contributors.txt")
license = []
with open(settings.BASE_DIR + "/LICENSE", "r") as f:
for line in f:
license.append(line)
return render(request, "about.html", {"contributors": contributors, "license": license})