def post(self): args = self.reqparse.parse_args() token = args.get('auth-token') userAdmin = Administrador.load_from_token(token) userAlum = Alumno.load_from_token(token) userProf = Profesor.load_from_token(token) if userAdmin == None and userAlum == None and userProf == None: return {'response': 'user_invalid'}, 401 institucion = None if userAdmin != None: institucion = Institucion.objects( id=userAdmin.institucion.id).first() if userAlum != None: institucion = Institucion.objects( id=userAlum.institucion.id).first() if userProf != None: institucion = Institucion.objects( id=userProf.institucion.id).first() if institucion == None: return {'response': 'colegio_invalid'}, 404 data = request.data.decode() data = json.loads(data) profesor = Profesor() profesor.nombres = data['nombres'] profesor.apellido_paterno = data['apellido_paterno'] profesor.apellido_materno = data['apellido_materno'] profesor.telefono = data['telefono'] profesor.email = data['email'] profesor.nombre_usuario = data['nombre_usuario'] profesor.encrypt_password(data['nombre_usuario']) profesor.institucion = institucion.id profesor.save() return {'Response': 'exito', 'id': str(profesor.id)}
def post(self, id_institucion): data = request.data.decode() data = json.loads(data) profesor = Profesor() profesor.nombres = data['nombres'] profesor.apellido_paterno = data['apellido_paterno'] profesor.apellido_materno = data['apellido_materno'] profesor.telefono = data['telefono'] profesor.email = data['email'] profesor.nombre_usuario = data['nombre_usuario'] profesor.password = data['nombre_usuario'] institucion = Institucion.objects(id=id_institucion).first() profesor.institucion = institucion.id profesor.save() return {'Response': 'exito', 'id': str(profesor.id)}
def post(self, token): data = request.data.decode() data = json.loads(data) token = token if Administrador.load_from_token(token) != None: profesor = Profesor() profesor.nombres = data['nombres'] profesor.apellido_paterno = data['apellido_paterno'] profesor.apellido_materno = data['apellido_materno'] profesor.telefono = data['telefono'] profesor.email = data['email'] profesor.nombre_usuario = data['nombre_usuario'] profesor.encrypt_password(data['nombre_usuario']) profesor.save() return {'Response': 'exito', 'id': str(profesor.id)} else: return {'Response': 'fracaso'}