Esempio n. 1
0
def getNotasMateriasToAlumnoIDbyNotaMateriaID(alumnoid, materiaid):
    if (not (isNumber(alumnoid))):
        raise BadResquest(
            identifier,
            CodeInternalError.ERROR_INTERNAL_13_REQUEST_DATA_NOT_MATCHED)
    elif (not (isNumber(materiaid))):
        raise BadResquest(
            identifier,
            CodeInternalError.ERROR_INTERNAL_13_REQUEST_DATA_NOT_MATCHED)
    try:
        notamateria = NotaMateria.getNotaMateriaNotamateriaIDToAlumnoID(
            materiaid, alumnoid)
    except Exception as identifier:
        raise InternalServerError(
            'Error relacionado en base de datos.',
            CodeInternalError.ERROR_INTERNAL_11_CONEXION_BD)
    if notamateria is not None:
        return jsonify(
            alumno_id=notamateria.alumno_fk,
            notamateria_id=notamateria.notamateria_id,
            nombremateria=notamateria.nombremateria,
            notafinal=notamateria.notafinal,
        )
    else:
        raise NotFound('No se encontraron los datos solicitados.',
                       CodeInternalError.ERROR_INTERNAL_12_REQUEST_NOT_FOUND)
Esempio n. 2
0
def updateNotaMateria(request, alumnoid, notamateriaid):
    try:
        json_recibido = request.json
        nombremateria = json_recibido['nombremateria']
        notafinal = request.json['notafinal']
    except Exception as identifier:
        raise BadResquest('Estructa de Json incorrecta.',
                          CodeInternalError.ERROR_INTERNAL_10_JSON_BAD_FORMED)
    #se valida el nro de la nota
    if (not (isNumber(alumnoid))):
        raise BadResquest(
            'AlumnoID no es un tipo de dato valido.',
            CodeInternalError.ERROR_INTERNAL_13_REQUEST_DATA_NOT_MATCHED)
    elif (not (isNumber(notamateriaid))):
        raise BadResquest(
            'NotamateriaID no es un tipo de dato valido.',
            CodeInternalError.ERROR_INTERNAL_13_REQUEST_DATA_NOT_MATCHED)
    if (not (isNumber(notafinal))):
        raise BadResquest(
            'Nota final no es un tipo de dato valido.',
            CodeInternalError.ERROR_INTERNAL_13_REQUEST_DATA_NOT_MATCHED)
    isValidNotaFinal(notafinal)
    existe = nombremateria in Listamaterias
    if (not (existe)):
        raise BadResquest(
            'No existe el nombre de la materia.',
            CodeInternalError.ERROR_INTERNAL_13_REQUEST_DATA_NOT_MATCHED)
    #Si el objeto recibido es igual que en la base devuelve el mismo. Si no lo es, se valida que no este actualizando
    #la materia_id con un nombre de materia ya existente.
    if (NotaMateria.existsMateriaIDToAlumnoID(alumnoid, notamateriaid)):
        notaMateria_base = NotaMateria.getNotaMateriaNotamateriaIDToAlumnoID(
            notamateriaid, alumnoid)
        if (notaMateria_base.nombremateria == nombremateria
                and notaMateria_base.notafinal == notafinal):
            return jsonify(
                alumnoid=alumnoid,
                notamateriaid=notamateriaid,
                nombremateria=nombremateria,
                notafinal=notafinal,
            )
        else:
            if (NotaMateria.existsNombreMateriaToAlumnoID(
                    alumnoid, nombremateria)):
                notamateria_existente = NotaMateria.getNotaMateriaByNombreMateria(
                    alumnoid, nombremateria)
                if (notamateria_existente.notamateria_id !=
                        notaMateria_base.notamateria_id):
                    raise Conflict(
                        'Existe otra materia con el mismo nombre.',
                        CodeInternalError.
                        ERROR_INTERNAL_14_REQUEST_DATA_DUPLICATED)
                else:
                    notamateria = NotaMateria.getNotaMateriaByNotamateriaID(
                        notamateriaid)
                    notamateria.nombremateria = nombremateria
                    notamateria.notafinal = notafinal
                    notamateria.save()
                    notamateria_updated = NotaMateria.getNotaMateriaByNotamateriaID(
                        notamateriaid)
                    return jsonify(
                        alumnoid=notamateria_updated.alumno_fk,
                        notamateriaid=notamateria_updated.notamateria_id,
                        nombremateria=notamateria_updated.nombremateria,
                        notafinal=notamateria_updated.notafinal,
                    )
            else:
                notamateria = NotaMateria.getNotaMateriaByNotamateriaID(
                    notamateriaid)
                notamateria.nombremateria = nombremateria
                notamateria.notafinal = notafinal
                notamateria.save()
                notamateria_updated = NotaMateria.getNotaMateriaByNotamateriaID(
                    notamateriaid)
                return jsonify(
                    alumnoid=notamateria_updated.alumno_fk,
                    notamateriaid=notamateria_updated.notamateria_id,
                    nombremateria=notamateria_updated.nombremateria,
                    notafinal=notamateria_updated.notafinal,
                )
    else:
        raise BadResquest(
            'Los datos recibidos no coinciden.',
            CodeInternalError.ERROR_INTERNAL_13_REQUEST_DATA_NOT_MATCHED)