<s> from urllib import urlencode <EOL> from django . http import HttpResponse <EOL> from django . shortcuts import render <EOL> from facepy import SignedRequest <EOL> from fandjango . models import User <EOL> from fandjango . settings import ( <EOL> FACEBOOK_APPLICATION_ID , FACEBOOK_APPLICATION_DOMAIN , <EOL> FACEBOOK_APPLICATION_NAMESPACE , FACEBOOK_APPLICATION_SECRET_KEY , <EOL> FACEBOOK_APPLICATION_INITIAL_PERMISSIONS <EOL> ) <EOL> def authorize_application ( <EOL> request , <EOL> redirect_uri = '<STR_LIT>' % ( FACEBOOK_APPLICATION_DOMAIN , FACEBOOK_APPLICATION_NAMESPACE ) , <EOL> permissions = FACEBOOK_APPLICATION_INITIAL_PERMISSIONS <EOL> ) : <EOL> """<STR_LIT>""" <EOL> query = { <EOL> '<STR_LIT>' : FACEBOOK_APPLICATION_ID , <EOL> '<STR_LIT>' : redirect_uri <EOL> } <EOL> if permissions : <EOL> query [ '<STR_LIT>' ] = '<STR_LIT:U+002CU+0020>' . join ( permissions ) <EOL> return render ( <EOL> request = request , <EOL> template_name = '<STR_LIT>' , <EOL> dictionary = { <EOL> '<STR_LIT:url>' : '<STR_LIT>' % urlencode ( query ) <EOL> } , <EOL> status = <NUM_LIT> <EOL> ) <EOL> def authorization_denied ( request ) : <EOL> """<STR_LIT>""" <EOL> return render ( <EOL> request = request , <EOL> template_name = '<STR_LIT>' , <EOL> status = <NUM_LIT> <EOL> ) <EOL> def deauthorize_application ( request ) : <EOL> """<STR_LIT>""" <EOL> if request . facebook : <EOL> user = User . objects . get ( <EOL> facebook_id = request . facebook . signed_request . user . id <EOL> ) <EOL> user . authorized = False <EOL> user . save ( ) <EOL> return HttpResponse ( ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) </s>
