From 143150bddf1a02498da0dcbdf0ad59d540c1519a Mon Sep 17 00:00:00 2001 From: Attila-Mihaly Balazs Date: Tue, 25 Mar 2014 13:07:53 +0200 Subject: [PATCH 1/1] Further fixes for subfolder hosting --- forum/sitemap.py | 15 +++++++-------- forum/utils/html.py | 9 ++++----- settings_local.py.dist | 5 +++++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/forum/sitemap.py b/forum/sitemap.py index 0bf8538..26e9d18 100644 --- a/forum/sitemap.py +++ b/forum/sitemap.py @@ -7,17 +7,14 @@ from django.conf import settings from django.http import HttpResponse, Http404 from django.template import loader from django.core import urlresolvers +from django.core.urlresolvers import get_script_prefix from django.utils.encoding import smart_str from django.core.paginator import EmptyPage, PageNotAnInteger def index(request, sitemaps): sites = [] - for section, site in sitemaps.items(): - if callable(site): - pages = site().paginator.num_pages - else: - pages = site.paginator.num_pages - sitemap_url = urlresolvers.reverse('sitemap_section_index', kwargs={'section': section}) + for section in sitemaps.keys(): + sitemap_url = urlresolvers.reverse('sitemap_section_index', prefix='/', kwargs={'section': section}) # Replace double forward slashes with single ones final_url = '%s%s' % (settings.APP_URL, sitemap_url) @@ -41,7 +38,7 @@ def sitemap_section_index(request, section, sitemaps): locations = [] for page in paginator.page_range: - location = urlresolvers.reverse('sitemap_section_page', kwargs={ 'page' : page, 'section' : section }) + location = urlresolvers.reverse('sitemap_section_page', prefix='/', kwargs={ 'page' : page, 'section' : section }) location = '%s%s' % (settings.APP_URL, location) location = re.sub("/+", "/", location) location = location.replace('http:/', 'http://') @@ -98,7 +95,9 @@ class OsqaSitemap(Sitemap): def get_urls(self, page=1): urls = [] for item in self.paginator.page(page).object_list: - loc = "%s%s" % (settings.APP_URL, self.__get('location', item)) + root_relative_url = self.__get('location', item) + relative_url = root_relative_url[len(get_script_prefix()):] + loc = "%s/%s" % (settings.APP_URL, relative_url) url_info = { 'location': loc, 'lastmod': self.__get('lastmod', item, None), diff --git a/forum/utils/html.py b/forum/utils/html.py index 88253e1..3657ef6 100644 --- a/forum/utils/html.py +++ b/forum/utils/html.py @@ -68,8 +68,7 @@ def hyperlink(url, title, **attrs): return mark_safe('%s' % (url, " ".join('%s="%s"' % i for i in attrs.items()), title)) def objlink(obj, **attrs): - return hyperlink(settings.APP_URL + obj.get_absolute_url(), unicode(obj), **attrs) - - - - + link = obj.get_absolute_url() + if not link.startswith(settings.APP_URL): + link = settings.APP_URL + link + return hyperlink(link, unicode(obj), **attrs) diff --git a/settings_local.py.dist b/settings_local.py.dist index 896a433..ad178f6 100644 --- a/settings_local.py.dist +++ b/settings_local.py.dist @@ -58,6 +58,11 @@ DATABASES = { CACHE_BACKEND = 'file://%s' % os.path.join(os.path.dirname(__file__),'cache').replace('\\','/') #CACHE_BACKEND = 'dummy://' SESSION_ENGINE = 'django.contrib.sessions.backends.db' +# Customize the values below if OSQA is in a subfolder and especially you're planning on +# running multiple Django applications (OSQA or others) on the same domain in different +# subfolders +#SESSION_COOKIE_PATH = '/' +#CSRF_COOKIE_PATH = '/' # This should be equal to your domain name, plus the web application context. # This shouldn't be followed by a trailing slash. -- 2.39.5