2021-11-22 12:59:43 +00:00
|
|
|
import random
|
2021-09-28 13:10:22 +00:00
|
|
|
from django.shortcuts import render, redirect, get_object_or_404
|
2021-10-29 07:32:18 +00:00
|
|
|
from django.conf import settings
|
2021-09-28 13:10:22 +00:00
|
|
|
|
|
|
|
from . import models
|
|
|
|
|
2021-10-29 07:32:18 +00:00
|
|
|
def fallback(request, slug=''):
|
|
|
|
if not slug:
|
|
|
|
return redirect('index')
|
|
|
|
|
2021-10-10 15:06:43 +00:00
|
|
|
context = {}
|
|
|
|
return render(request, 'fallback.html', context)
|
|
|
|
|
2021-09-28 13:10:22 +00:00
|
|
|
def index(request):
|
2021-10-27 11:37:40 +00:00
|
|
|
from ..text.models import Text
|
2021-09-28 13:10:22 +00:00
|
|
|
context = {}
|
2023-03-02 14:59:40 +00:00
|
|
|
context['texts'] = Text.objects.filter(public=True, listed=True).order_by('title')
|
2021-09-28 13:10:22 +00:00
|
|
|
return render(request, 'index.html', context)
|
|
|
|
|
2021-10-11 12:26:51 +00:00
|
|
|
def page(request, slug=''):
|
2021-09-28 13:10:22 +00:00
|
|
|
context = {}
|
2023-03-02 14:59:40 +00:00
|
|
|
if slug == "":
|
|
|
|
return index(request)
|
|
|
|
elif request.user.is_staff:
|
2021-10-11 12:55:45 +00:00
|
|
|
page = models.Page.objects.filter(slug=slug).first()
|
|
|
|
else:
|
|
|
|
page = models.Page.objects.filter(slug=slug, public=True).first()
|
2021-10-11 12:26:51 +00:00
|
|
|
if page:
|
|
|
|
context['page'] = page
|
|
|
|
return render(request, 'page.html', context)
|
|
|
|
else:
|
2023-03-02 14:59:40 +00:00
|
|
|
return text(request, slug)
|
2021-10-11 12:26:51 +00:00
|
|
|
|
|
|
|
def about(request):
|
2021-10-21 15:24:26 +00:00
|
|
|
context = {}
|
2021-11-24 08:20:50 +00:00
|
|
|
context['pandora_url'] = settings.DEFAULT_PANDORA_API.replace('/api/', '')
|
2021-10-21 15:24:26 +00:00
|
|
|
return render(request, 'about.html', context)
|
2021-09-28 13:10:22 +00:00
|
|
|
|
2021-10-10 15:06:43 +00:00
|
|
|
def texts(request):
|
2021-09-28 13:10:22 +00:00
|
|
|
context = {}
|
2022-09-25 18:09:52 +00:00
|
|
|
all_texts = models.Text.objects.filter(public=True, listed=True).order_by('position', 'created')
|
2021-11-12 10:21:00 +00:00
|
|
|
context['texts'] = all_texts.filter()
|
2021-10-10 15:06:43 +00:00
|
|
|
return render(request, 'texts.html', context)
|
2021-09-28 13:10:22 +00:00
|
|
|
|
2021-10-10 15:06:43 +00:00
|
|
|
def text(request, slug):
|
2021-09-28 13:10:22 +00:00
|
|
|
context = {}
|
2021-10-11 12:55:45 +00:00
|
|
|
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)
|
2021-11-21 09:09:26 +00:00
|
|
|
context['pandora_url'] = settings.DEFAULT_PANDORA_API.replace('/api/', '')
|
2021-10-10 15:06:43 +00:00
|
|
|
return render(request, 'text.html', context)
|