From: Javyer Der Derian Date: Thu, 17 Apr 2014 21:59:05 +0000 (-0300) Subject: Merge pull request #46 from udacity/subfolder_fixes X-Git-Tag: live~21 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/cdf6f5f965021228d2a411d23726eda56db0b5a7?hp=87761a02340d63155104e92a18983e3d01c6bdbb Merge pull request #46 from udacity/subfolder_fixes Fix OSQA-819: Link to profile in message is wrong if OSQA is installed in a subfolder --- diff --git a/forum/actions/user.py b/forum/actions/user.py index a9ec71a..ce277c3 100644 --- a/forum/actions/user.py +++ b/forum/actions/user.py @@ -22,7 +22,7 @@ class UserJoinsAction(ActionProxy): def describe(self, viewer=None): return _("%(user)s %(have_has)s joined the %(app_name)s Q&A community") % { - 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'user': self.hyperlink(self.user.get_absolute_url(), self.friendly_username(viewer, self.user)), 'have_has': self.viewer_or_user_verb(viewer, self.user, _('have'), _('has')), 'app_name': APP_SHORT_NAME, } @@ -32,7 +32,7 @@ class UserLoginAction(ActionProxy): def describe(self, viewer=None): return _("%(user)s %(have_has)s logged in") % { - 'user' : self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'user' : self.hyperlink(self.user.get_absolute_url(), self.friendly_username(viewer, self.user)), 'have_has': self.viewer_or_user_verb(viewer, self.user, _('have'), _('has')), } @@ -48,7 +48,7 @@ class EmailValidationAction(ActionProxy): def describe(self, viewer=None): return _("%(user)s %(have_has)s validated the e-mail %(email)s") % { - 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'user': self.hyperlink(self.user.get_absolute_url(), self.friendly_username(viewer, self.user)), 'have_has': self.viewer_or_user_verb(viewer, self.user, _('have'), _('has')), 'email' : self.user.email if viewer.is_superuser or viewer.is_staff or viewer == self.user else "" } @@ -58,9 +58,9 @@ class EditProfileAction(ActionProxy): def describe(self, viewer=None): return _("%(user)s edited %(hes_or_your)s %(profile_link)s") % { - 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'user': self.hyperlink(self.user.get_absolute_url(), self.friendly_username(viewer, self.user)), 'hes_or_your': self.viewer_or_user_verb(viewer, self.user, _('your'), _('his')), - 'profile_link': self.hyperlink(self.user.get_profile_url(), _('profile')), + 'profile_link': self.hyperlink(self.user.get_absolute_url(), _('profile')), } class BonusRepAction(ActionProxy): @@ -89,12 +89,12 @@ class BonusRepAction(ActionProxy): try: if int(value) > 0: return _("%(user)s awarded an extra %(value)s reputation points to %(users)s: %(message)s") % { - 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'user': self.hyperlink(self.user.get_absolute_url(), self.friendly_username(viewer, self.user)), 'value': value, 'users':self.affected_links(viewer), 'message': message } else: return _("%(user)s penalised %(users)s in %(value)s reputation points: %(message)s") % { - 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'user': self.hyperlink(self.user.get_absolute_url(), self.friendly_username(viewer, self.user)), 'value': value, 'users':self.affected_links(viewer), 'message': message } except Exception, e: @@ -125,12 +125,12 @@ class AwardPointsAction(ActionProxy): try: if int(value) > 0: return _("%(user)s awarded an extra %(value)s reputation points to %(users)s") % { - 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'user': self.hyperlink(self.user.get_absolute_url(), self.friendly_username(viewer, self.user)), 'value': value, 'users':self.affected_links(viewer), } else: return _("%(user)s penalised %(users)s in %(value)s reputation points") % { - 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'user': self.hyperlink(self.user.get_absolute_url(), self.friendly_username(viewer, self.user)), 'value': value, 'users':self.affected_links(viewer), } except Exception, e: @@ -189,7 +189,7 @@ class AwardAction(ActionProxy): def describe(self, viewer=None): return _("%(user)s %(were_was)s awarded the %(badge_name)s badge") % { - 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'user': self.hyperlink(self.user.get_absolute_url(), self.friendly_username(viewer, self.user)), 'were_was': self.viewer_or_user_verb(viewer, self.user, _('were'), _('was')), 'badge_name': self.award.badge.name, } @@ -218,7 +218,7 @@ class ReportAction(ActionProxy): def describe(self, viewer=None): return _("%(user)s reported %(reported) : %(msg)s") % { - 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'user': self.hyperlink(self.user.get_absolute_url(), self.friendly_username(viewer, self.user)), 'reporter': self.extra.get('reported').username, 'msg': self.extra.get('publicmsg', _('N/A')) } @@ -251,6 +251,6 @@ class SuspendAction(ActionProxy): suspension = _("indefinetely") return _("%(user)s suspended %(users)s %(suspension)s: %(msg)s") % { - 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'user': self.hyperlink(self.user.get_absolute_url(), self.friendly_username(viewer, self.user)), 'users': self.affected_links(viewer), 'suspension': suspension, 'msg': self.extra.get('publicmsg', _('Bad behaviour')) } diff --git a/forum/models/user.py b/forum/models/user.py index 0437614..131ae54 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -5,6 +5,7 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned from django.contrib.contenttypes.models import ContentType from django.contrib.auth.models import User as DjangoUser, AnonymousUser as DjangoAnonymousUser from django.db.models import Q, Manager +from django.core.urlresolvers import get_script_prefix from django.utils.encoding import smart_unicode @@ -221,7 +222,9 @@ class User(BaseModel, DjangoUser): return ('user_profile', (), keyword_arguments) def get_absolute_url(self): - return self.get_profile_url() + root_relative_url = self.get_profile_url() + relative_url = root_relative_url[len(get_script_prefix()):] + return '%s/%s' % (django_settings.APP_URL, relative_url) @models.permalink def get_asked_url(self): 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/forum/views/auth.py b/forum/views/auth.py index 01f6210..00b67dc 100644 --- a/forum/views/auth.py +++ b/forum/views/auth.py @@ -89,7 +89,7 @@ def prepare_provider_signin(request, provider): try: request_url = provider_class.prepare_authentication_request(request, - reverse('auth_provider_done', + reverse('auth_provider_done', prefix='/', kwargs={'provider': provider})) return HttpResponseRedirect(request_url) diff --git a/forum/views/writers.py b/forum/views/writers.py index 304032c..597ddba 100644 --- a/forum/views/writers.py +++ b/forum/views/writers.py @@ -98,7 +98,7 @@ def ask(request): if request.user.is_authenticated(): messages.info(request, _("Your question is pending until you %s.") % html.hyperlink( - reverse('send_validation_email'), _("validate your email") + django_settings.APP_URL + reverse('send_validation_email', prefix='/'), _("validate your email") )) return HttpResponseRedirect(reverse('index')) else: @@ -273,7 +273,7 @@ def answer(request, id): if request.user.is_authenticated(): messages.info(request, _("Your answer is pending until you %s.") % html.hyperlink( - reverse('send_validation_email'), _("validate your email") + django_settings.APP_URL + reverse('send_validation_email', prefix='/'), _("validate your email") )) return HttpResponseRedirect(question.get_absolute_url()) else: diff --git a/forum_modules/facebookauth/authentication.py b/forum_modules/facebookauth/authentication.py index b80c477..c98eaf1 100644 --- a/forum_modules/facebookauth/authentication.py +++ b/forum_modules/facebookauth/authentication.py @@ -8,6 +8,7 @@ from forum.authentication.base import AuthenticationConsumer, ConsumerTemplateCo from django.conf import settings as django_settings from django.utils.encoding import smart_unicode +from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ import settings @@ -30,7 +31,8 @@ class FacebookAuthConsumer(AuthenticationConsumer): def process_authentication_request(self, request): try: - args = dict(client_id=settings.FB_API_KEY, redirect_uri="%s%s" % (django_settings.APP_URL, request.path)) + redirect_uri = "%s%s" % (django_settings.APP_URL, reverse('auth_provider_done', prefix='/', kwargs={'provider': 'facebook'})) + args = dict(client_id=settings.FB_API_KEY, redirect_uri=redirect_uri) args["client_secret"] = settings.FB_APP_SECRET #facebook APP Secret diff --git a/forum_modules/oauthauth/consumer.py b/forum_modules/oauthauth/consumer.py index bbbaac8..ee9bf97 100644 --- a/forum_modules/oauthauth/consumer.py +++ b/forum_modules/oauthauth/consumer.py @@ -52,7 +52,7 @@ class OAuthAbstractAuthConsumer(AuthenticationConsumer): parameters = {} # If the installation is configured to automatically redirect to the Twitter provider done page -- do it. if bool(TWITTER_AUTO_CALLBACK_REDIRECT): - callback_url = '%s%s' % (APP_URL, reverse('auth_provider_done', kwargs={ 'provider' : 'twitter', })) + callback_url = '%s%s' % (APP_URL, reverse('auth_provider_done', prefix='/', kwargs={'provider' : 'twitter'})) # Pass parameters.update({ 'oauth_callback' : callback_url, diff --git a/settings_local.py.dist b/settings_local.py.dist index 81c1eaa..e687228 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.