Exemple #1
0
def deleteNotaMateria(id):
    try:
        notamateria = NotaMateria.buscarNotaMateriaByNotamateriaID(id)
    except Exception as identifier:
        raise InternalServerError(
            'Error relacionado con base de datos.',
            CodeInternalError.ERROR_INTERNAL_11_CONEXION_BD)
    if notamateria is not None:
        try:
            notamateria.delete()
            return ('Recurso eliminado.', status.HTTP_200_OK)
        except Exception as identifier:
            raise InternalServerError(
                'Error relacionado con base de datos.',
                CodeInternalError.ERROR_INTERNAL_11_CONEXION_BD)
    else:
        raise BadResquest(
            'Recurso no encontrado en la base de datos.',
            CodeInternalError.ERROR_INTERNAL_12_REQUEST_NOT_FOUND)
Exemple #2
0
def updateNotaMateria(request):
    try:
        notamateriaID = request.json['notamateria_id']
        nombremateria = request.json['nombremateria']
        notafinal = request.json['notafinal']
        alumnoID = request.json['alumno_id']
    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 (int(notafinal) >= 11 or int(notafinal) < 0):
        raise BadResquest('Nota invalida',
                          CodeInternalError.ERROR_INTERNAL_10_JSON_BAD_FORMED)
    #Se valida si la notamateriaID recibida corresponde al alumno en cuestión. Valida si el user no existe.
    notamateria = NotaMateria.buscarNotaMateriaByNotamateriaID(notamateriaID)
    if notamateria is None:
        raise BadResquest(
            'Los datos recibidos no coinciden.',
            CodeInternalError.ERROR_INTERNAL_13_REQUEST_DATA_NOT_MATCHED)
    if (int(alumnoID) == int(notamateria.alumno_fk)):
        try:
            notamateria.nombremateria = nombremateria
            notamateria.notafinal = notafinal
            '''print(notamateria.nombremateria)
            print(notamateria.notafinal)
            print(notamateria.alumno_fk)
            print(notamateria.notamateria_id)'''
            notamateria.save()
            return ('Recurso actualizado.')
        except Exception as identifier:
            raise InternalServerError(
                'Error relacionado con base de datos.',
                CodeInternalError.ERROR_INTERNAL_11_CONEXION_BD)
    else:
        raise BadResquest(
            'Los datos recibidos no coinciden.',
            CodeInternalError.ERROR_INTERNAL_13_REQUEST_DATA_NOT_MATCHED)