#NEWLINE# def dropbox_auth_finish( self , request ) : #NEWLINE# #INDENT# from dropbox.client import DropboxOAuth2Flow , DropboxClient #NEWLINE# access_token = None #NEWLINE# try : #NEWLINE# #INDENT# auth_flow = self . get_dropbox_auth_flow ( request ) #NEWLINE# ( access_token , user_id , url_state ) = auth_flow . finish ( request . DATA ) #NEWLINE# #UNINDENT# except DropboxOAuth2Flow . BadRequestException : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# except DropboxOAuth2Flow . BadStateException : #NEWLINE# #INDENT# return HttpResponseRedirect ( '/api/dropbox/auth-start' ) #NEWLINE# #UNINDENT# except DropboxOAuth2Flow . CsrfException : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# except DropboxOAuth2Flow . NotApprovedException : #NEWLINE# #INDENT# return HttpResponseRedirect ( '/' ) #NEWLINE# #UNINDENT# except DropboxOAuth2Flow . ProviderException : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# client = DropboxClient ( oauth2_access_token = access_token ) #NEWLINE# try : #NEWLINE# #INDENT# account_info = client . account_info ( ) #NEWLINE# temporary_flow = models . TemporaryFlowModel . objects . get ( email = account_info [ 'email' ] , type = 'DROPBOX' , user = request . user ) #NEWLINE# try : #NEWLINE# #INDENT# account_check = models . AccountModel . objects . get ( type = 'DROPBOX' , email = account_info [ 'email' ] ) #NEWLINE# account_check . is_active = 1 #NEWLINE# account_check . status = 1 #NEWLINE# account_check . save ( ) #NEWLINE# #UNINDENT# except models . AccountModel . DoesNotExist : #NEWLINE# #INDENT# account = models . AccountModel ( ) #NEWLINE# account . owner = request . user #NEWLINE# account . email = account_info [ 'email' ] #NEWLINE# account . access_token = access_token #NEWLINE# account . description = ( ( ( account_info [ 'display_name' ] + '(' ) + account_info [ 'email' ] ) + ')' ) #NEWLINE# account . type = 'DROPBOX' #NEWLINE# account . quota = account_info [ 'quota_info' ] [ 'quota' ] #NEWLINE# account . used_space = account_info [ 'quota_info' ] [ 'normal' ] #NEWLINE# account . is_active = 1 #NEWLINE# account . name = 'Dropbox' #NEWLINE# account . status = 1 #NEWLINE# account . assigned_space = account_info [ 'quota_info' ] [ 'quota' ] #NEWLINE# account . save ( ) #NEWLINE# #UNINDENT# temporary_flow . delete ( ) #NEWLINE# #UNINDENT# except models . TemporaryFlowModel . DoesNotExist : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return HttpResponseRedirect ( '/accounts' )