def _create_session(cls, user, inicio, fim): sessao = ApiSession() sessao.user = user sessao.inicio = inicio sessao.fim = fim sessao.save() return sessao
def _wrap(*args, **kwargs): request = args[0] email, token = request.META['HTTP_AUTHORIZATION'].split(' ') try: usuario = ApiUser.objects.get(email=email, token=token) sessao = ApiSession.cria_sessao(usuario) except ObjectDoesNotExist: return HttpResponse('Credencial invalida', status=401) kwargs['usuario'] = usuario kwargs['sessao'] = sessao return funcao(request, *args, **kwargs)
def _get_connection(cls, config='config.json'): conf = json.load(open(config, 'r')) cls._con = Connector(conf['host'], conf['path'], conf['token']) renew = conf.get('renew', None) if renew: #It's not the best option, but is only used for that. from models import ApiSession newSession = ApiSession() # I known this hack is not great, should require a little refactor of code. newSession._manager = cls newSession.token = conf['token'] newSession.renew = renew newSession.save() conf['token'] = newSession.id conf['expiration'] = newSession.expiration conf['renew'] = newSession.renew json.dump(conf, open(config, 'w'), indent=4) cls._con = Connector(conf['host'], conf['path'], conf['token'])