mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
when running plinth with default server_dir '/' some static files and redirects were wrong -- fixed that;
This commit is contained in:
parent
a8ed02b723
commit
d4d6948eb9
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
|||||||
current-*.tar.gz
|
current-*.tar.gz
|
||||||
*.pyc
|
*.pyc
|
||||||
*.py.bak
|
*.py.bak
|
||||||
|
*.swp
|
||||||
*.tiny.css
|
*.tiny.css
|
||||||
data/*.log
|
data/*.log
|
||||||
data/cherrypy_sessions
|
data/cherrypy_sessions
|
||||||
|
|||||||
@ -101,7 +101,7 @@ def setup_server():
|
|||||||
'/': {'tools.staticdir.root': '%s/static' % cfg.file_root,
|
'/': {'tools.staticdir.root': '%s/static' % cfg.file_root,
|
||||||
'tools.staticdir.on': True,
|
'tools.staticdir.on': True,
|
||||||
'tools.staticdir.dir': '.'}}
|
'tools.staticdir.dir': '.'}}
|
||||||
cherrypy.tree.mount(None, cfg.server_dir + '/static', config)
|
cherrypy.tree.mount(None, django.conf.settings.STATIC_URL, config)
|
||||||
|
|
||||||
if not cfg.no_daemon:
|
if not cfg.no_daemon:
|
||||||
Daemonizer(cherrypy.engine).subscribe()
|
Daemonizer(cherrypy.engine).subscribe()
|
||||||
@ -185,7 +185,7 @@ def configure_django():
|
|||||||
ROOT_URLCONF='urls',
|
ROOT_URLCONF='urls',
|
||||||
SESSION_ENGINE='django.contrib.sessions.backends.file',
|
SESSION_ENGINE='django.contrib.sessions.backends.file',
|
||||||
SESSION_FILE_PATH=sessions_directory,
|
SESSION_FILE_PATH=sessions_directory,
|
||||||
STATIC_URL=cfg.server_dir + '/static/',
|
STATIC_URL=os.path.join(cfg.server_dir, 'static/'),
|
||||||
TEMPLATE_CONTEXT_PROCESSORS=context_processors,
|
TEMPLATE_CONTEXT_PROCESSORS=context_processors,
|
||||||
TEMPLATE_DIRS=template_directories)
|
TEMPLATE_DIRS=template_directories)
|
||||||
|
|
||||||
|
|||||||
50
util.py
50
util.py
@ -1,24 +1,48 @@
|
|||||||
import os
|
import os
|
||||||
|
from django.http.response import HttpResponseRedirect
|
||||||
|
import cfg
|
||||||
|
|
||||||
|
|
||||||
|
class PlinthRedirect(HttpResponseRedirect):
|
||||||
|
"""
|
||||||
|
We do not fully use django and thus cannot use its named URLs to construct
|
||||||
|
links/redirects, so we have to take care of cfg.server_dir manually.
|
||||||
|
This temporary helper class makes sure that plinth-internal redirects
|
||||||
|
have the correct server_dir prefix.
|
||||||
|
"""
|
||||||
|
def __init__(self, redirect_to, *args, **kwargs):
|
||||||
|
if not redirect_to.startswith(cfg.server_dir):
|
||||||
|
redirect_to = urljoin([cfg.server_dir, redirect_to])
|
||||||
|
return super(PlinthRedirect, self).__init__(redirect_to,
|
||||||
|
*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def urljoin(parts):
|
||||||
|
"""
|
||||||
|
urllibs' urljoin joins ("foo", "/bar") to "/bar".
|
||||||
|
Instead, just concatenate the parts with "/" to i.e. /foo/bar
|
||||||
|
"""
|
||||||
|
return '/' + '/'.join(s.strip('/') for s in parts)
|
||||||
|
|
||||||
|
|
||||||
def mkdir(newdir):
|
def mkdir(newdir):
|
||||||
"""works the way a good mkdir should :)
|
"""works the way a good mkdir should :)
|
||||||
- already exists, silently complete
|
- already exists, silently complete
|
||||||
- regular file in the way, raise an exception
|
- regular file in the way, raise an exception
|
||||||
- parent directory(ies) does not exist, make them as well
|
- parent directory(ies) does not exist, make them as well
|
||||||
"""
|
"""
|
||||||
if os.path.isdir(newdir):
|
if os.path.isdir(newdir):
|
||||||
pass
|
pass
|
||||||
elif os.path.isfile(newdir):
|
elif os.path.isfile(newdir):
|
||||||
raise OSError("a file with the same name as the desired " \
|
raise OSError("a file with the same name as the desired " \
|
||||||
"dir, '%s', already exists." % newdir)
|
"dir, '%s', already exists." % newdir)
|
||||||
else:
|
else:
|
||||||
head, tail = os.path.split(newdir)
|
head, tail = os.path.split(newdir)
|
||||||
if head and not os.path.isdir(head):
|
if head and not os.path.isdir(head):
|
||||||
mkdir(head)
|
mkdir(head)
|
||||||
#print "mkdir %s" % repr(newdir)
|
#print "mkdir %s" % repr(newdir)
|
||||||
if tail:
|
if tail:
|
||||||
os.mkdir(newdir)
|
os.mkdir(newdir)
|
||||||
|
|
||||||
|
|
||||||
def slurp(filespec):
|
def slurp(filespec):
|
||||||
|
|||||||
11
views.py
11
views.py
@ -19,7 +19,7 @@
|
|||||||
Main Plinth views
|
Main Plinth views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.http.response import HttpResponseRedirect
|
from util import PlinthRedirect
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import cfg
|
import cfg
|
||||||
@ -37,14 +37,13 @@ def index(request):
|
|||||||
# Permanent redirect causes the browser to cache the redirect,
|
# Permanent redirect causes the browser to cache the redirect,
|
||||||
# preventing the user from navigating to /plinth until the
|
# preventing the user from navigating to /plinth until the
|
||||||
# browser is restarted.
|
# browser is restarted.
|
||||||
return HttpResponseRedirect(cfg.server_dir + '/firstboot')
|
return PlinthRedirect('/firstboot')
|
||||||
|
|
||||||
if database['state'] < 5:
|
if database['state'] < 5:
|
||||||
LOGGER.info('First boot state - %d', database['state'])
|
LOGGER.info('First boot state - %d', database['state'])
|
||||||
return HttpResponseRedirect(
|
return PlinthRedirect('/firstboot/state%d' % database['state'])
|
||||||
cfg.server_dir + '/firstboot/state%d' % database['state'])
|
|
||||||
|
|
||||||
if request.user.is_authenticated():
|
if request.user.is_authenticated():
|
||||||
return HttpResponseRedirect(cfg.server_dir + '/apps')
|
return PlinthRedirect('/apps')
|
||||||
|
|
||||||
return HttpResponseRedirect(cfg.server_dir + '/help/about')
|
return PlinthRedirect('/help/about')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user