univnautes: custom templates&static (#5570)
This commit is contained in:
parent
202e2f2c04
commit
9344d387ed
|
@ -995,7 +995,7 @@ url.rewrite-if-not-file = (
|
|||
url.rewrite-once = (
|
||||
"^/favicon\.ico$" => "/static/favicon.ico",
|
||||
"^/*$" => "/django.fcgi/",
|
||||
"^/(accounts|authsaml2|page)(.*)$" => "/django.fcgi/$1$2",
|
||||
"^/(accounts|authsaml2|page|static)(.*)$" => "/django.fcgi/$1$2",
|
||||
)
|
||||
|
||||
EOD;
|
||||
|
|
|
@ -95,6 +95,7 @@ except IOError:
|
|||
|
||||
# List of callables to import templates from various sources.
|
||||
TEMPLATE_LOADERS = (
|
||||
'sp.template_loader.Loader',
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
)
|
||||
|
@ -113,7 +114,10 @@ ROOT_URLCONF = 'sp.urls'
|
|||
# Python dotted path to the WSGI application used by Django's runserver.
|
||||
WSGI_APPLICATION = 'sp.wsgi.application'
|
||||
|
||||
CPELEMENTS = '/var/db/cpelements'
|
||||
|
||||
TEMPLATE_DIRS = (
|
||||
CPELEMENTS,
|
||||
os.path.join(PROJECT_PATH, 'sp', 'templates'),
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import os
|
||||
from django.conf import settings
|
||||
from django.template.loaders.filesystem import Loader as FileSystemLoader
|
||||
|
||||
class Loader(FileSystemLoader):
|
||||
|
||||
def get_template_sources(self, template_name, template_dirs=None):
|
||||
filename = os.path.join(settings.CPELEMENTS,
|
||||
'captiveportal-template-%s' % template_name.replace('/', '-'))
|
||||
return (filename,)
|
|
@ -27,6 +27,7 @@ urlpatterns = patterns('',
|
|||
url(r'^accounts/login/', 'sp.views.login', name='login'),
|
||||
url(r'^accounts/', include('django.contrib.auth.urls')),
|
||||
url(r'^authsaml2/', include('authentic2.authsaml2.urls')),
|
||||
url(r'^static/(?P<path>.*)$', 'sp.views.static_serve'),
|
||||
)
|
||||
|
||||
if 'django.contrib.admin' in settings.INSTALLED_APPS:
|
||||
|
|
|
@ -16,18 +16,22 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import urllib2
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.views import login as django_login
|
||||
from django.template import Template, Context
|
||||
import urllib2
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import redirect
|
||||
import subprocess
|
||||
from django.views.static import serve as django_static_serve
|
||||
|
||||
import pfconfigxml
|
||||
|
||||
|
||||
class Homepage(TemplateView):
|
||||
'''Homepage View, displays a welcome message'''
|
||||
template_name = 'homepage.html'
|
||||
|
@ -75,3 +79,10 @@ def logout(request):
|
|||
# 2. disconnect from django
|
||||
return redirect('django_logout_then_login')
|
||||
|
||||
def static_serve(request, path):
|
||||
# if path is "this/file.css", search for "captiveportal-static-this-file.css"
|
||||
custom_path = 'captiveportal-static-%s' % path.replace('/', '-')
|
||||
document_root = settings.CPELEMENTS
|
||||
if os.path.exists(os.path.join(document_root, custom_path)):
|
||||
return django_static_serve(request, custom_path, document_root=document_root)
|
||||
return django_static_serve(request, path, document_root=settings.STATIC_ROOT)
|
||||
|
|
Reference in New Issue