Skip to content

Instantly share code, notes, and snippets.

@kitsunde
Created September 11, 2012 16:59
Show Gist options
  • Select an option

  • Save kitsunde/3699827 to your computer and use it in GitHub Desktop.

Select an option

Save kitsunde/3699827 to your computer and use it in GitHub Desktop.
FacebookApplication lookup
class FacebookApplication(object):
def process_request(self, request):
current_url = request.get_absolute_path()
match_url = "^" + current_url.replace('http://', 'https://')
# This is admittedly a rather strange looking.. lookup.
# What we need to do is find out if the applications canvas_url is the
# start of the URL we are currently on. Once that has been established
# we also need to find out which canvas_url is longer to find out
# which is the closer match.
apps = FacebookApplication.objects.extra(
select={'canvas_url_length': 'Length(canvas_url)'},
where=["%s LIKE CONCAT(canvas_url, %s)"],
params=[match_url,'%']).order_by('-canvas_url_length')
try:
setattr(request, 'facebook', apps[0])
except IndexError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment