#NEWLINE# def create_profile_from_slug( url_slug , profile_request_dict , db ) : #NEWLINE# #INDENT# profile_dict = { k : unicode ( v ) for ( k , v ) in profile_request_dict . iteritems ( ) } #NEWLINE# profile_dict [ 'url_slug' ] = unicode ( url_slug ) #NEWLINE# profile_dict [ 'email' ] = profile_dict [ 'email' ] . lower ( ) #NEWLINE# password = profile_dict [ 'password' ] #NEWLINE# del profile_dict [ 'password' ] #NEWLINE# profile_with_this_slug = Profile . query . filter ( ( func . lower ( Profile . url_slug ) == func . lower ( profile_dict [ 'url_slug' ] ) ) ) . first ( ) #NEWLINE# if ( profile_with_this_slug is not None ) : #NEWLINE# #INDENT# profile_dict [ 'url_slug' ] += str ( random . randint ( 1 , 9999 ) ) #NEWLINE# #UNINDENT# profile_with_this_email = Profile . query . filter ( ( Profile . email == profile_dict [ 'email' ] ) ) . first ( ) #NEWLINE# if ( profile_with_this_email is not None ) : #NEWLINE# #INDENT# raise EmailExistsError #NEWLINE# #UNINDENT# profile = Profile ( ** profile_dict ) #NEWLINE# db . session . add ( profile ) #NEWLINE# profile . set_password ( password ) #NEWLINE# commit ( db ) #NEWLINE# logger . debug ( "Finished creating profile {id} with slug '{slug}'" . format ( id = profile . id , slug = profile . url_slug ) ) #NEWLINE# return profile