Skip to content

Commit

Permalink
Merge pull request #99 from ademuk/fix-settings-attribute
Browse files Browse the repository at this point in the history
Fix FANDJANGO_SITE_URL settings attribute
  • Loading branch information
jgorset committed Jan 13, 2014
2 parents f127955 + 16c0ff4 commit 3bac298
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fandjango/settings.py
Expand Up @@ -37,4 +37,4 @@
FANDJANGO_CACHE_SIGNED_REQUEST = getattr(settings, 'FACEBOOK_SIGNED_REQUEST_COOKIE', True)

# A string describing the website URL.
FANDJANGO_SITE_URL = getattr(settings, 'FANDJANGO_SITE_URL')
FANDJANGO_SITE_URL = getattr(settings, 'FANDJANGO_SITE_URL', None)
14 changes: 11 additions & 3 deletions fandjango/utils.py
Expand Up @@ -76,7 +76,10 @@ def authorization_denied_view(request):
return authorization_denied_view(request)

def get_post_authorization_redirect_url(request, canvas=True):
"""Determine the URL users should be redirected to upon authorization the application."""
"""
Determine the URL users should be redirected to upon authorization the application.
If request is non-canvas use user defined site url if set, else the site hostname.
"""

path = request.get_full_path()

Expand All @@ -90,8 +93,13 @@ def get_post_authorization_redirect_url(request, canvas=True):
'path': path
}
else:
path = path.replace(urlparse(FANDJANGO_SITE_URL).path, '')
redirect_uri = FANDJANGO_SITE_URL + path
if FANDJANGO_SITE_URL:
site_url = FANDJANGO_SITE_URL
path = path.replace(urlparse(site_url).path, '')
else:
protocol = "https" if request.is_secure() else "http"
site_url = "%s://%s" % (protocol, request.get_host())
redirect_uri = site_url + path

return redirect_uri

Expand Down
2 changes: 0 additions & 2 deletions tests/project/settings.py
Expand Up @@ -20,8 +20,6 @@
FACEBOOK_APPLICATION_NAMESPACE = 'fandjango-test'
FACEBOOK_APPLICATION_CANVAS_URL = 'http://example.org/foo'

FANDJANGO_SITE_URL = FACEBOOK_APPLICATION_CANVAS_URL

SECRET_KEY = '123'

USE_TZ = True
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fandjango.py
Expand Up @@ -566,8 +566,8 @@ def test_get_post_authorization_redirect_url(self):
"""
request = request_factory.get('/foo/bar/baz')
redirect_url = get_post_authorization_redirect_url(request, canvas = False)

assert redirect_url == 'http://example.org/foo/bar/baz'
# RequestFactory has the hostname "testserver"
assert redirect_url == 'http://testserver/foo/bar/baz'

def test_querystring_removal(self):
"""
Expand Down

0 comments on commit 3bac298

Please sign in to comment.