forked from expo/troggle
should all be working, but isn't
This commit is contained in:
@@ -6,6 +6,8 @@ from django.shortcuts import render, redirect
|
|||||||
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
||||||
from django.urls import reverse, resolve
|
from django.urls import reverse, resolve
|
||||||
from django.template import Context, loader
|
from django.template import Context, loader
|
||||||
|
from django.views.decorators.csrf import ensure_csrf_cookie
|
||||||
|
|
||||||
import django.forms as forms
|
import django.forms as forms
|
||||||
|
|
||||||
from troggle.helper import login_required_if_public
|
from troggle.helper import login_required_if_public
|
||||||
@@ -147,6 +149,7 @@ def getmimetype(path):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
@login_required_if_public
|
@login_required_if_public
|
||||||
|
@ensure_csrf_cookie
|
||||||
def editflatpage(request, path):
|
def editflatpage(request, path):
|
||||||
try:
|
try:
|
||||||
r = Cave.objects.get(url = path)
|
r = Cave.objects.get(url = path)
|
||||||
@@ -156,7 +159,7 @@ def editflatpage(request, path):
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
filepath = os.path.normpath(settings.EXPOWEB + path)
|
filepath = Path(settings.EXPOWEB) / path
|
||||||
o = open(filepath, "r")
|
o = open(filepath, "r")
|
||||||
html = o.read()
|
html = o.read()
|
||||||
autogeneratedmatch = re.search(r"\<\!--\s*(.*?(Do not edit|auto-generated).*?)\s*--\>", html, re.DOTALL + re.IGNORECASE)
|
autogeneratedmatch = re.search(r"\<\!--\s*(.*?(Do not edit|auto-generated).*?)\s*--\>", html, re.DOTALL + re.IGNORECASE)
|
||||||
@@ -174,12 +177,15 @@ def editflatpage(request, path):
|
|||||||
else:
|
else:
|
||||||
return HttpResponse("Page could not be split into header and body")
|
return HttpResponse("Page could not be split into header and body")
|
||||||
except IOError:
|
except IOError:
|
||||||
|
print("### File not found ### ", filepath)
|
||||||
filefound = False
|
filefound = False
|
||||||
|
|
||||||
|
|
||||||
if request.method == 'POST': # If the form has been submitted...
|
if request.method == 'POST': # If the form has been submitted...
|
||||||
flatpageForm = FlatPageForm(request.POST) # A form bound to the POST data
|
flatpageForm = FlatPageForm(request.POST) # A form bound to the POST data
|
||||||
if flatpageForm.is_valid():# Form valid therefore write file
|
if flatpageForm.is_valid():# Form valid therefore write file
|
||||||
|
print("### \n", str(flatpageForm)[0:300])
|
||||||
|
print("### \n csrfmiddlewaretoken: ",request.POST['csrfmiddlewaretoken'])
|
||||||
if filefound:
|
if filefound:
|
||||||
headmatch = re.match(r"(.*)<title>.*</title>(.*)", head, re.DOTALL + re.IGNORECASE)
|
headmatch = re.match(r"(.*)<title>.*</title>(.*)", head, re.DOTALL + re.IGNORECASE)
|
||||||
if headmatch:
|
if headmatch:
|
||||||
@@ -209,7 +215,8 @@ def editflatpage(request, path):
|
|||||||
title = ""
|
title = ""
|
||||||
flatpageForm = FlatPageForm({"html": body, "title": title})
|
flatpageForm = FlatPageForm({"html": body, "title": title})
|
||||||
else:
|
else:
|
||||||
flatpageForm = FlatPageForm()
|
body = "### File not found ###\n" + str(filepath)
|
||||||
|
flatpageForm = FlatPageForm({"html": body, "title": "Missing"})
|
||||||
return render(request, 'editflatpage.html', {'path': path, 'form': flatpageForm, })
|
return render(request, 'editflatpage.html', {'path': path, 'form': flatpageForm, })
|
||||||
|
|
||||||
class FlatPageForm(forms.Form):
|
class FlatPageForm(forms.Form):
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{% extends "expobase.html" %}
|
{% extends "expobase.html" %}
|
||||||
{% block title %}Edit {{ path }}{% endblock %}
|
{% block title %}Edit {{ path }}{% endblock %}
|
||||||
{% block extrahead %}
|
{% block extrahead %}
|
||||||
{% load csrffaker %}
|
|
||||||
<!--<script src="{{ settings.TINY_MCE_MEDIA_URL }}tiny_mce.js" type="text/javascript"></script>-->
|
<!--<script src="{{ settings.TINY_MCE_MEDIA_URL }}tiny_mce.js" type="text/javascript"></script>-->
|
||||||
<!-- <script type="text/javascript"> tinyMCE.init({ mode : "textareas" }); </script>-->
|
<!-- <script type="text/javascript"> tinyMCE.init({ mode : "textareas" }); </script>-->
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{% autoescape off %}
|
{% autoescape off %}
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
<title>{% block title %}{% endblock %}</title>
|
<title>{% block title %}{% endblock %}</title>
|
||||||
<link rel="stylesheet" type="text/css" href="/css/main2.css" />
|
<link rel="stylesheet" type="text/css" href="/css/main2.css" />
|
||||||
{% block extrahead %}{% endblock %}
|
{% block extrahead %}{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user