njpma/app/text/views.py
2021-10-25 12:22:03 +05:30

44 lines
1.3 KiB
Python
Executable file

from django.shortcuts import render, redirect, get_object_or_404
from . import models
def fallback(request):
context = {}
return render(request, 'fallback.html', context)
def index(request):
context = {}
return render(request, 'index.html', context)
#def index_alt(request):
#context = {}
#return render(request, 'index-alt.html', context)
def page(request, slug=''):
context = {}
if request.user.is_staff:
page = models.Page.objects.filter(slug=slug).first()
else:
page = models.Page.objects.filter(slug=slug, public=True).first()
if page:
context['page'] = page
return render(request, 'page.html', context)
else:
return render(request, 'fallback.html', context)
def about(request):
context = {}
return render(request, 'about.html', context)
def texts(request):
context = {}
context['texts'] = models.Text.objects.filter(public=True).order_by('position', 'created')
return render(request, 'texts.html', context)
def text(request, slug):
context = {}
if request.user.is_staff:
context['text'] = get_object_or_404(models.Text, slug=slug)
else:
context['text'] = get_object_or_404(models.Text, slug=slug, public=True)
return render(request, 'text.html', context)