Example #1
0
    def post(self):
        args = self.reqparse.parse_args()
        email = args.get("email")
        passwd = args.get("password")
        tipo = args.get("tipo")

        user = None
        if tipo == 'ALUMNO':
            if (email.find('@') != -1):
                user = Alumno.objects(email=email).first()
            else:
                user = Alumno.objects(nombre_usuario=email).first()

        elif tipo == 'ADMINISTRADOR':
            if (email.find('@') != -1):
                user = Administrador.objects(email=email).first()
            else:
                user = Administrador.objects(nombre_usuario=email).first()

        elif tipo == 'PROFESOR':
            if (email.find('@') != -1):
                user = Profesor.objects(email=email).first()
            else:
                user = Profesor.objects(nombre_usuario=email).first()

        if user != None and user.activo and user.check_password(passwd):
            res = []
            if tipo == "ALUMNO":
                res_bd = Curso.objects(alumnos__in=[user],
                                       clon_padre=None,
                                       activo=True,
                                       publicado=True).all()
            else:
                res_bd = Curso.objects(profesor=user,
                                       clon_padre=None,
                                       activo=True).all()
            for resource in res_bd:
                res.append({
                    "id":
                    str(resource.id),
                    "nombre":
                    resource.nombre,
                    "fecha_creacion":
                    resource.fecha_creacion.isoformat(),
                    "activo":
                    resource.activo,
                    "version":
                    resource.version,
                    "id_base":
                    str(resource.curso_base.id),
                })
            return {
                'respuesta': user.to_dict(),
                'tipo': tipo,
                'token': str(user.get_token()),
                'recursos': res
            }
        return abort(403)
Example #2
0
 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)
     grado = Grado()
     grado.nivel = data['nivel']
     grado.identificador = data['identificador']
     grado.institucion = institucion.id
     profesor = Profesor.objects(id=data['profesor']).first()
     grado.profesor = profesor.id
     grado.save()
     return {'Response': 'exito'}
Example #3
0
def test_put_recursos(client):
    curso = Curso.objects().first()
    institucion = Institucion.objects().first()
    asignatura = Asignatura.objects().first()
    profesor = Profesor.objects().first()
    alumno = Alumno.objects().first()
    grado = Grado.objects().first()
    curso_base = CursoBase.objects().first()

    if((institucion == None) or (asignatura == None) or \
       (profesor == None) or (alumno == None) or \
       (grado == None) or (curso_base == None) or (curso == None)):
        assert False
    data = {
        'nombre': 'nombre',
        'fecha_creacion': '01/01/2000',
        'preguntas': [],
        'asignatura': str(asignatura.id),
        'institucion': str(institucion.id),
        'profesor': str(profesor.id),
        'alumnos': str(alumno.id),
        'grado': str(grado.id),
        'activo': True,
        'version': 1,
        'curso_base': str(curso_base.id),
        'descripcion': 'descripcion del curso'
    }

    data_put = {'id': str(curso.id), 'data': data}
    data_put = json.dumps(data_put)
    data_put = data_put.encode()
    rv = client.put('/recursos', data=data_put)
    if rv._status_code == 200:
        return True
    assert False
Example #4
0
    def put(self):
        #Cargar datos dinamicos
        data = request.data.decode()
        data = json.loads(data)
        idCurso = data['id']
        data = data['data']

        cursoBase = CursoBase.objects(id=data['curso_base']).first()
        asignatura = Asignatura.objects(id=data['asignatura']).first()
        institucion = Institucion.objects(id=data['institucion']).first()
        profesor = Profesor.objects(id=data['profesor']).first()
        alumnos = Alumno.objects(id=data['alumnos']).first()
        pregunta = Pregunta()

        curso = Curso.objects(id=idCurso).first()
        curso.nombre = data['nombre']
        curso.fecha_creacion = '10/06/2012'
        curso.preguntas = [pregunta]
        curso.asignatura = asignatura.id
        curso.institucion = institucion.id
        curso.profesor = profesor.id
        curso.alumnos = [alumnos.id]
        curso.activo = True
        curso.version = data['version']
        curso.curso_base = cursoBase.id
        curso.save()

        return {'test': 'test'}
Example #5
0
def test_post_cursos(client):
    institucion = Institucion.objects().first()
    asignatura = Asignatura.objects().first()
    profesor = Profesor.objects().first()
    alumnos = Alumno.objects().all()
    grado = Grado.objects().first()
    curso_base = CursoBase.objects().first()

    if ((institucion == None) or (asignatura == None) or (profesor == None)
            or (alumnos == None) or (grado == None) or (curso_base == None)):
        assert True
    else:
        alumnos_array = []
        for alumno in alumnos:
            alumnos_array.append(alumno.id)
        data = {
            'nombre': 'nombre',
            'fecha_creacion': '01/01/2000',
            'preguntas': [],
            'asignatura': str(asignatura.id),
            'institucion': str(institucion.id),
            'profesor': str(profesor.id),
            'alumnos': alumnos_array,
            'grado': str(grado.id),
            'activo': True,
            'version': '1.0',
            'curso_base': str(curso_base.id),
            'descripcion': 'descripcion del curso'
        }
        token = profesor.get_token()
        rv = client.post('/recursos', data=data, headers={'auth-token': token})
        if rv._status_code == 200:
            assert True
        else:
            assert False
Example #6
0
 def get(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
     profesores = []
     for profesor in Profesor.objects(institucion=institucion.id,
                                      activo=True).all():
         profesores.append(profesor.to_dict())
     return profesores
Example #7
0
    def post(self):
        args = self.reqparse.parse_args()
        email = args.get("email")
        passwd = args.get("password")
        tipo = args.get("tipo")
        recursos = []
        user = None

        if tipo == 'ALUMNO':
            user = Alumno.objects(email=email).first()
            for recurso in Curso.objects(alumnos__in=[user]).all():
                recursos.append(recurso.to_dict())
        elif tipo == 'ADMINISTRADOR':
            user = administrador = Administrador.objects(email=email).first()
        elif tipo == 'PROFESOR':
            user = Profesor.objects(email=email).first()
            for recurso in Curso.objects(profesor=user).all():
                recursos.append(recurso.to_dict())

        if user and user.activo and user.check_password(passwd):
            return {
                'respuesta': {
                    'id': str(user.id)
                },
                'tipo': tipo,
                'token': str(user.get_token()),
                'recursos': recursos
            }
        print('testingggg')
        return {'respuesta': 'no_existe'}, 401
Example #8
0
def test_get_cursos_profesor(client):
    profesor = Profesor.objects().first()
    if profesor == None:
        assert False
    rv = client.get('/cursos/profesor/' + str(profesor.id))
    if rv._status_code == 200:
        return True
    assert False
Example #9
0
def test_get_recursos_desactivados(client):
    profesor = Profesor.objects().first()
    if profesor == None:
        assert False
    rv = client.get('/recursos/desactivados/' + str(profesor.id))
    if rv._status_code == 200:
        return True
    assert False
Example #10
0
def test_delete_profesor_item(client):
    profesor = Profesor.objects().first()
    if profesor == None:
        assert False
    rv = client.delete('/profesores/' + str(profesor.id))
    if rv._status_code == 200:
        return True
    assert False
Example #11
0
def test_get_profesor_finalizar_tutorial(client):
    profesor = Profesor.objects().first()
    if profesor == None:
        assert False
    rv = client.get('/profesor/finalizar/tutorial/' + str(profesor.id))
    if rv._status_code == 200:
        return True
    assert False
Example #12
0
 def get(self, id_profesor,id_institucion):
     institucion = Institucion.objects(id=id_institucion).first()
     profesor = Profesor.objects(id=id_profesor).first()
     response = []
     for curso in Curso.objects(activo=False, institucion=institucion.id,profesor=profesor.id).all():
         categoria = Categoria.objects(id=curso.categoria.id).first()
         curso = curso.to_dict()
         curso['categoria'] = categoria.to_dict()
         response.append(curso)
     return response
Example #13
0
 def post(self):
     data = request.data.decode()
     data = json.loads(data)
     grado = Grado()
     profesor = Profesor.objects(id=data['profesor']).first()
     grado.profesor = profesor.id
     grado.nivel = data['nivel']
     grado.identificador = data['identificador']
     grado.save()
     return {'Response': 'exito'}
Example #14
0
def test_get_recursos_activos(client):
    profesor = Profesor.objects().first()
    if profesor == None:
        assert True
    else:
        rv = client.get('/recursos/activos/' + str(profesor.id))
        if rv._status_code == 200:
            assert True
        else:
            assert False
Example #15
0
 def get(self, id):
     args = self.reqparse.parse_args()
     token = args.get('auth-token')
     alumno = Alumno.load_from_token(token)
     apoderado = Apoderado.load_from_token(token)
     administrador = Administrador.load_from_token(token)
     profesor = Profesor.load_from_token(token)
     if alumno == None and apoderado == None and administrador == None and profesor == None:
         return {'response': 'user_invalid'}, 401
     return Profesor.objects(id=id).first().to_dict()
Example #16
0
def test_get_profesor(client):
    profesor = Profesor.objects().first()
    if profesor == None:
        assert True
    else:
        rv = client.get('/profesores/' + str(profesor.id))
        if rv._status_code == 200:
            assert True
        else:
            assert False
Example #17
0
    def post(self, id):
        data = request.data.decode()
        data = json.loads(data)
        institucion = Institucion.objects(id=id).first()
        administrador = Administrador.objects(
            email=data['email'], institucion=institucion.id).first()
        profesor = Profesor.objects(email=data['email'],
                                    institucion=institucion.id).first()
        alumno = Alumno.objects(email=data['email'],
                                institucion=institucion.id).first()
        if administrador != None:
            if (administrador.check_password(data['password'])
                    or administrador.activo == False):
                token = administrador.get_token()
                return {
                    'respuesta': {
                        'id': str(administrador.id)
                    },
                    'tipo': 'ADMINISTRADOR',
                    'token': str(token)
                }
            else:
                return {'respuesta': 'no_existe'}, 401

        if profesor != None:
            if (profesor.check_password(data['password'])
                    or administrador.activo == False):
                token = profesor.get_token()
                return {
                    'respuesta': {
                        'id': str(profesor.id)
                    },
                    'tipo': 'PROFESOR',
                    'token': str(token)
                }
            else:
                return {'respuesta': 'no_existe'}, 401

        if alumno != None:
            if (alumno.check_password(data['password'])
                    or administrador.activo == False):
                token = alumno.get_token()
                return {
                    'respuesta': {
                        'id': str(alumno.id)
                    },
                    'tipo': 'ALUMNO',
                    'token': str(token)
                }
            else:
                return {'respuesta': 'no_existe'}, 401

        else:
            return {'respuesta': 'no_existe'}, 404
Example #18
0
def test_post_cursos(client):
    profesor = Profesor.objects().first()
    if profesor == None:
        assert False
    data = {'profesor': str(profesor.id), 'nivel': '1', 'identificador': 'A'}
    data = json.dumps(data)
    data = data.encode()
    rv = client.post('/cursos', data=data)
    if rv._status_code == 200:
        return True
    assert False
Example #19
0
 def put(self, id):
     data = request.data.decode()
     data = json.loads(data)
     profesor = Profesor.objects(id=id).first()
     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.save()
     return {'Response': 'exito'}
Example #20
0
 def get(self, id):
     args = self.reqparse.parse_args()
     token = args.get('auth-token')
     administrador = Administrador.load_from_token(token)
     profesor = Profesor.objects(id=id).first()
     if administrador == None and profesor == None:
         return {'response': 'user_invalid'}, 401
     response = []
     for anotacion in ObservacionProfesor.objects(
             profesor=profesor.id).all():
         response.append(anotacion.to_dict())
     return response
Example #21
0
    def post(self):
        args = self.reqparse.parse_args()
        email = args.get("email")
        tipo = args.get("tipo")

        user = None
        if tipo == 'ALUMNO':
            if (email.find('@') != -1):
                user = Alumno.objects(email=email).first()
            else:
                user = Alumno.objects(nombre_usuario=email).first()
        elif tipo == 'ADMINISTRADOR':
            if (email.find('@') != -1):
                user = Administrador.objects(email=email).first()
            else:
                user = Administrador.objects(nombre_usuario=email).first()
        elif tipo == 'PROFESOR':
            if (email.find('@') != -1):
                user = Profesor.objects(email=email).first()
            else:
                user = Profesor.objects(nombre_usuario=email).first()
        if user and user.activo and user.check_password(args.get("password")):
            recursos = []
            if tipo == 'ALUMNO':
                for recurso in Curso.objects(alumnos__in=[user],
                                             clon_padre=None).all():
                    recursos.append(recurso.to_dict())
            elif tipo == 'PROFESOR':
                for recurso in Curso.objects(profesor=user,
                                             clon_padre=None).all():
                    recursos.append(recurso.to_dict())
            return {
                'respuesta': {
                    'id': str(user.id)
                },
                'tipo': tipo,
                'token': str(user.get_token()),
                'recursos': recursos
            }
        return {'respuesta': 'no_existe'}, 401
Example #22
0
 def get(self, id):
     profesor = Profesor.objects(id=id).first()
     imagen = Image.open(
         current_app.config.get("BASE_PATH") +
         "uploads/profesores/default_thumbnail.jpg")
     imagen.thumbnail((800, 800))
     imagen.save(
         os.path.join(
             current_app.config.get("BASE_PATH") + "uploads/profesores",
             str(id) + '_thumbnail.jpg'))
     profesor.imagen = str(profesor.id)
     profesor.save()
     return {'Response': 'exito'}
Example #23
0
 def delete(self, id):
     args = self.reqparse.parse_args()
     token = args.get('auth-token')
     alumno = Alumno.load_from_token(token)
     apoderado = Apoderado.load_from_token(token)
     administrador = Administrador.load_from_token(token)
     profesor = Profesor.load_from_token(token)
     if alumno == None and apoderado == None and administrador == None and profesor == None:
         return {'response': 'user_invalid'}, 401
     profesor = Profesor.objects(id=id).first()
     profesor.activo = False
     profesor.save()
     return {'Response': 'borrado'}
Example #24
0
 def get(self, id):
     cursosRespuesta = []
     cursos = Curso.objects().all()
     for curso in cursos:
         if curso.alumnos != None:
             esta_alumno = False
             for alumno in curso.alumnos:
                 if str(alumno.id) == str(id):
                     esta_alumno = True
             if esta_alumno:
                 asignatura = Asignatura.objects(id=curso.asignatura.id).first()
                 profesor = Profesor.objects(id=curso.profesor.id).first()
                 cursosRespuesta.append(curso.to_dict()) 
     return cursosRespuesta
Example #25
0
 def post(self, id):
     profesor = Image.open(request.files['imagen'].stream).convert("RGB")
     profesor.save(
         os.path.join(
             current_app.config.get("BASE_PATH") + "uploads/profesores",
             str(id) + ".jpg"))
     profesor.thumbnail((800, 800))
     profesor.save(
         os.path.join(
             current_app.config.get("BASE_PATH") + "uploads/profesores",
             str(id) + '_thumbnail.jpg'))
     profesor = Profesor.objects(id=id).first()
     profesor.imagen = id
     profesor.save()
     return {'Response': 'exito'}
Example #26
0
 def get(self):
     args = self.reqparse.parse_args()
     token = args.get('auth-token')
     alumno = Alumno.load_from_token(token)
     apoderado = Apoderado.load_from_token(token)
     administrador = Administrador.load_from_token(token)
     profesor = Profesor.load_from_token(token)
     if alumno == None and apoderado == None and administrador == None and profesor == None:
         return {'response': 'user_invalid'}, 401
     profesores = Profesor.objects().all()
     response = []
     for profesor in profesores:
         if profesor.activo:
             response.append(profesor.to_dict())
     return response
Example #27
0
 def get(self, id_asignatura):
     args = self.reqparse.parse_args()
     token = args.get('auth-token')
     alumno = Alumno.load_from_token(token)
     apoderado = Apoderado.load_from_token(token)
     administrador = Administrador.load_from_token(token)
     profesor = Profesor.load_from_token(token)
     if alumno == None and apoderado == None and administrador == None and profesor == None:
         return {'response': 'user_invalid'}, 401
     profesores = []
     asignatura = Asignatura.objects(id=id_asignatura).first()
     for profesor in Profesor.objects(asignatura=asignatura.id,
                                      activo=True).all():
         if profesor.activo:
             profesores.append(profesor.to_dict())
     return profesores
Example #28
0
    def post(self, id):
        #########
        # Se usa el siguiente os.path.join para los tests
        #########
        directory_root = dirname(dirname(abspath(__file__)))
        upload_directory = os.path.join(str(directory_root),
                                        "flaskr/uploads/profesores")

        imagen = Image.open(request.files['imagen'].stream).convert("RGB")
        imagen.save(os.path.join(upload_directory, str(id) + ".jpg"))
        imagen.thumbnail((200, 100))
        imagen.save(os.path.join(upload_directory, str(id) + '_thumbnail.jpg'))
        profesor = Profesor.objects(id=id).first()
        profesor.imagen = str(id)
        profesor.save()
        return {'Response': 'exito'}
Example #29
0
 def post(self, id):
     directory_root = dirname(dirname(abspath(__file__)))
     imagen = Image.open(request.files['imagen'].stream).convert("RGB")
     imagen.save(
         os.path.join(str(directory_root), "flaskr", "uploads",
                      "profesores",
                      str(id) + ".jpg"))
     imagen.thumbnail((200, 100))
     imagen.save(
         os.path.join(str(directory_root), "flaskr", "uploads",
                      "profesores",
                      str(id) + '_thumbnail.jpg'))
     profesor = Profesor.objects(id=id).first()
     profesor.imagen = str(id)
     profesor.save()
     return {'Response': 'exito'}
Example #30
0
def test_post_profesor_imagen(client):
    with api.app.app_context():
        directory_root = dirname(dirname(abspath(__file__)))
        path_img = os.path.join(str(directory_root), "flaskr", "uploads",
                                "categorias", "default.jpg")
        with open(path_img, 'rb') as img_open:
            img = BytesIO(img_open.read())
            profesor = Profesor.objects().first()
            if profesor == None:
                assert False
            data = {'imagen': (img, 'img.jpg')}
            rv = client.post('/profesor/imagen/' + str(profesor.id),
                             content_type='multipart/form-data',
                             data=data)
            if rv._status_code == 200:
                return True
            assert False