Fix image loading.
This commit is contained in:
parent
f482cb562b
commit
ff7c31701e
6 changed files with 59 additions and 5 deletions
|
@ -5,8 +5,12 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
path('login', views.login_view, name="login"),
|
||||
path('schedule', views.schedule, name="schedule"),
|
||||
path("thingstodo", views.things_to_do, name="thingstodo"),
|
||||
path("travel", views.travel, name="travel"),
|
||||
path("accommodation", views.accommodation, name="accommodation"),
|
||||
path("landing", views.landing, name="landing"),
|
||||
path("faq", views.faq, name="faq"),
|
||||
]
|
||||
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
from django.shortcuts import render
|
||||
from django.shortcuts import render, redirect
|
||||
from django.http import HttpResponse
|
||||
|
||||
from django.template import Template
|
||||
from django.template import Context
|
||||
from django.contrib.auth import authenticate, login
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
import markdown
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from .models import Site, Page
|
||||
from .models import Site, Page, Image
|
||||
|
||||
_TEMPLATE = """
|
||||
<!DOCTYPE html>
|
||||
|
@ -42,6 +45,19 @@ def index(request):
|
|||
soup = BeautifulSoup(template.render(context))
|
||||
return HttpResponse(soup.prettify())
|
||||
|
||||
def login_view(request):
|
||||
token = request.POST["token"]
|
||||
user = authenticate(request, username="guest", password=token)
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
return redirect("landing")
|
||||
else:
|
||||
return redirect("index")
|
||||
|
||||
@login_required(login_url="/")
|
||||
def landing(request):
|
||||
return get_page("Landing")
|
||||
|
||||
def get_page_header(site: Site):
|
||||
|
||||
pages = site.page_set.filter(navigable=True)
|
||||
|
@ -66,13 +82,30 @@ def get_page(name:str):
|
|||
|
||||
content = template.render(context)
|
||||
soup = BeautifulSoup(content, features="html.parser")
|
||||
|
||||
for img in soup.find_all('img'):
|
||||
img_name = img["src"]
|
||||
img["src"] = Image.objects.get(name=img_name).content.url
|
||||
|
||||
return HttpResponse(soup.prettify())
|
||||
|
||||
@login_required(login_url="/")
|
||||
def schedule(request):
|
||||
return get_page("Schedule")
|
||||
|
||||
@login_required(login_url="/")
|
||||
def things_to_do(request):
|
||||
return get_page("ThingsToDo")
|
||||
|
||||
@login_required(login_url="/")
|
||||
def travel(request):
|
||||
return get_page("Travel")
|
||||
return get_page("Travel")
|
||||
|
||||
@login_required(login_url="/")
|
||||
def faq(request):
|
||||
return get_page("Faq")
|
||||
|
||||
@login_required(login_url="/")
|
||||
def accommodation(request):
|
||||
return get_page("Accomodation")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue