def consumer_get_or_create(user, consumer_name, consumer_desc, consumer_target): key = myutil.new_key() secret = myutil.new_secret() # need to check and set status consumer = Consumer.objects.get_or_create( name=consumer_name, desc=consumer_desc, target=consumer_target, key = key, secret = secret, user = user ) return consumer
def tokenmanager_get_or_create(user, resource, consumer): isone = TokenManager.objects.filter(user=user, resource=resource, consumer=consumer).count() print "**isone:"+str(isone) if isone == 0: token_key = myutil.new_token() token_type = Token.REQUEST time_validate = 1000 mini_frequency = 0 token = Token.objects.create(key=token_key, token_type=token_type, time_validate=time_validate, mini_frequency=mini_frequency) tokenmanager = TokenManager.objects.get_or_create( user=user, resource=resource, consumer=consumer, token_request=token, key=myutil.new_key(), secret=myutil.new_secret() ) print tokenmanager return isone