Created
September 11, 2012 16:59
-
-
Save kitsunde/3699827 to your computer and use it in GitHub Desktop.
FacebookApplication lookup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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