]> git.openstreetmap.org Git - osqa.git/commitdiff
Merge pull request #46 from udacity/subfolder_fixes
authorJavyer Der Derian <javier@tribalo.net>
Thu, 17 Apr 2014 21:59:05 +0000 (18:59 -0300)
committerJavyer Der Derian <javier@tribalo.net>
Thu, 17 Apr 2014 21:59:05 +0000 (18:59 -0300)
Fix OSQA-819: Link to profile in message is wrong if OSQA is installed in a subfolder

forum/actions/user.py
forum/models/user.py
forum/sitemap.py
forum/utils/html.py
forum/views/auth.py
forum/views/writers.py
forum_modules/facebookauth/authentication.py
forum_modules/oauthauth/consumer.py
settings_local.py.dist

index a9ec71ae605309bf6cd961a42d196fcf2a536dc1..ce277c32b9e9195d180a63e905f8bb3eb513e4d4 100644 (file)
@@ -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'))
         }
index 043761481eae3a81989c341eb15ae2e992e05ace..131ae5491d06c013f5b317c794ace47a611cb07e 100644 (file)
@@ -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):
index 0bf8538ce49b41c6f840d2325d75924f0c9fc0eb..26e9d18b443fba9230e6e10ab67e4de67c9341aa 100644 (file)
@@ -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),
index 88253e12e60c8ea92d8cc5a064bdc426f5d54ea2..3657ef6af0a6ecd6813a9d4eaf35840c76e94060 100644 (file)
@@ -68,8 +68,7 @@ def hyperlink(url, title, **attrs):
     return mark_safe('<a href="%s" %s>%s</a>' % (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)
index 01f62105e167792ca358a1d992808fe31c77f7d1..00b67dc2a7f1553ea7fdac52a1b43833dcb720f5 100644 (file)
@@ -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)
index 304032c52d33f4f992a89c38b305ba15f0474e17..597ddbaf09e5234a6f4a78e7e49299c21af947ac 100644 (file)
@@ -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:
index b80c47767ff08846e8b49e960e6c675d30bf5871..c98eaf1b193ea29aff2192e19a143612496b4430 100644 (file)
@@ -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
 
index bbbaac8d53757ec48fa9e20fd648c93ce98764c5..ee9bf97fb576a6e10837421d5f67f76ed08ed263 100644 (file)
@@ -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,
index 81c1eaaf7093bc065e4bde3b61eb4eaf09736e13..e687228a3084c98c9c8ced11f603ad2e9589be6b 100644 (file)
@@ -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.