mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-15 03:17:12 +00:00
Convert codebase for python3 usage
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
import troggle.settings as settings
|
||||
from troggle.helper import login_required_if_public
|
||||
from django.shortcuts import render
|
||||
import os
|
||||
import re
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template import Context, loader
|
||||
import django.forms as forms
|
||||
|
||||
from tinymce.widgets import TinyMCE
|
||||
|
||||
from troggle.helper import login_required_if_public
|
||||
from troggle.flatpages.models import Redirect, EntranceRedirect
|
||||
from troggle.core.models import Cave
|
||||
import troggle.core.views_caves
|
||||
|
||||
import os
|
||||
import re
|
||||
import troggle.settings as settings
|
||||
|
||||
def flatpage(request, path):
|
||||
try:
|
||||
@@ -35,7 +36,7 @@ def flatpage(request, path):
|
||||
|
||||
|
||||
if path.startswith("noinfo") and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
||||
print("flat path noinfo", path)
|
||||
print(("flat path noinfo", path))
|
||||
return HttpResponseRedirect(reverse("auth_login") + '?next=%s' % request.path)
|
||||
|
||||
if path.endswith("/") or path == "":
|
||||
@@ -57,32 +58,32 @@ def flatpage(request, path):
|
||||
if path.endswith(".htm") or path.endswith(".html"):
|
||||
html = o.read()
|
||||
|
||||
m = re.search(r"(.*)<\s*head([^>]*)>(.*)<\s*/head\s*>(.*)<\s*body([^>]*)>(.*)<\s*/body\s*>(.*)", html, re.DOTALL + re.IGNORECASE)
|
||||
m = re.search(rb'(.*)<\s*head([^>]*)>(.*)<\s*/head\s*>(.*)<\s*body([^>]*)>(.*)<\s*/body\s*>(.*)', html, re.DOTALL + re.IGNORECASE)
|
||||
if m:
|
||||
preheader, headerattrs, head, postheader, bodyattrs, body, postbody = m.groups()
|
||||
else:
|
||||
return HttpResponse(html + "Page could not be split into header and body")
|
||||
m = re.search(r"<title>(.*)</title>", head, re.DOTALL + re.IGNORECASE)
|
||||
m = re.search(rb"<title>(.*)</title>", head, re.DOTALL + re.IGNORECASE)
|
||||
if m:
|
||||
title, = m.groups()
|
||||
else:
|
||||
title = ""
|
||||
m = re.search(r"<meta([^>]*)noedit", head, re.DOTALL + re.IGNORECASE)
|
||||
m = re.search(rb"<meta([^>]*)noedit", head, re.DOTALL + re.IGNORECASE)
|
||||
if m:
|
||||
editable = False
|
||||
else:
|
||||
editable = True
|
||||
|
||||
has_menu = False
|
||||
menumatch = re.match('(.*)<div id="menu">', body, re.DOTALL + re.IGNORECASE)
|
||||
menumatch = re.match(rb'(.*)<div id="menu">', body, re.DOTALL + re.IGNORECASE)
|
||||
if menumatch:
|
||||
has_menu = True
|
||||
menumatch = re.match('(.*)<ul id="links">', body, re.DOTALL + re.IGNORECASE)
|
||||
menumatch = re.match(rb'(.*)<ul id="links">', body, re.DOTALL + re.IGNORECASE)
|
||||
if menumatch:
|
||||
has_menu = True
|
||||
#body, = menumatch.groups()
|
||||
if re.search(r"iso-8859-1", html):
|
||||
body = unicode(body, "iso-8859-1")
|
||||
if re.search(rb"iso-8859-1", html):
|
||||
body = str(body, "iso-8859-1")
|
||||
body.strip
|
||||
return render(request, 'flatpage.html', {'editable': editable, 'path': path, 'title': title, 'body': body, 'homepage': (path == "index.htm"), 'has_menu': has_menu})
|
||||
else:
|
||||
@@ -129,7 +130,7 @@ def editflatpage(request, path):
|
||||
if linksmatch:
|
||||
body, links = linksmatch.groups()
|
||||
if re.search(r"iso-8859-1", html):
|
||||
body = unicode(body, "iso-8859-1")
|
||||
body = str(body, "iso-8859-1")
|
||||
else:
|
||||
return HttpResponse("Page could not be split into header and body")
|
||||
except IOError:
|
||||
@@ -154,7 +155,7 @@ def editflatpage(request, path):
|
||||
postbody = "</html>"
|
||||
body = flatpageForm.cleaned_data["html"]
|
||||
body = body.replace("\r", "")
|
||||
result = u"%s<head%s>%s</head>%s<body%s>\n%s</body>%s" % (preheader, headerargs, head, postheader, bodyargs, body, postbody)
|
||||
result = "%s<head%s>%s</head>%s<body%s>\n%s</body>%s" % (preheader, headerargs, head, postheader, bodyargs, body, postbody)
|
||||
f = open(filepath, "w")
|
||||
f.write(result)
|
||||
f.close()
|
||||
|
||||
Reference in New Issue
Block a user