def __call__(self): if isinstance(self.model, str): ModelClass = apps.get_app_config('lizard_auth_server').get_model( self.model) if not ModelClass: raise Exception('Unknown model {}'.format(self.model)) else: ModelClass = self.model key = gen_secret_key(64) while ModelClass.objects.filter(**{self.field: key}).exists(): key = gen_secret_key(64) return key
def __call__(self): if isinstance(self.model, str): ModelClass = apps.get_app_config("lizard_auth_server").get_model( self.model) if not ModelClass: raise Exception("Unknown model {}".format(self.model)) else: ModelClass = self.model key = gen_secret_key(64) while ModelClass.objects.filter(**{self.field: key}).exists(): key = gen_secret_key(64) return key
def create_for_portal(self, portal): """ Create a new token for a portal object. """ request_token = gen_secret_key(64) auth_token = gen_secret_key(64) # check unique constraints while self.filter( Q(request_token=request_token) | Q(auth_token=auth_token)).exists(): request_token = gen_secret_key(64) auth_token = gen_secret_key(64) return self.create( portal=portal, request_token=request_token, auth_token=auth_token, )