Exemple #1
0
def genera_boletines(directory, odt = False, dry_run = False, pdc = False, niveles = [], curso = []):
    """
        Genera todos los boletines para los niveles pasados como argumento
    """
    filter = {'curso__ciclo__nivel__cursoEscolar': settings.CURSO_ESCOLAR_ACTUAL}
    
    #no_promocionan_de_primaria = [1291, 1749, 1277, 1283, 1284, 1339, 1289, 1455, 1346, 1337, 1125]
    #no_promocionan_de_secundaria = [6, 17, 18, 22, 29, 31, 40, 46, 47, 55, 78, 87, 111, 116, 119, 124, 125, 130, 133, 135, 137, 141, 
    #   142, 143, 152, 153, 171, 174, 178, 179, 185, 186, 187, 188, 191, 201, 202, 203, 204, 220, 244, 252, 254, 270, 301, 308, 340, 668, 
    #   678, 684, 687, 689, 690, 693, 697, 699, 700, 708, 712, 714, 715, 717, 719, 720, 725, 782, 808, 841, 849, 851, 854, 864, 867, 871, 
    #   874, 875, 876, 878, 881, 883, 886, 887, 893, 894, 898, 902, 914, 1020, 1036, 1037, 1038, 1041, 1045, 1047, 1053, 1061, 1062, 1069, 1073, 
    #   1074, 1078, 1088, 1090, 1095, 1110, 1114, 1381, 1382, 1560, 1567, 1647, 1654, 1747, 1753, 1760, 1852, 1857, 1871, 1952, 1958, 1961, 
    #   1962, 1966, 1969, 1970, 1973, 1974, 1975]
    #no_promocionan = no_promocionan_de_primaria + no_promocionan_de_secundaria
    #alumnos_no_promocionan = TraductorAlumno.objects.filter(registro__in=no_promocionan).values_list('akademic', flat=True)
   
    exclude_sections = ['Pendientes']
    if not pdc:
        exclude_sections.append('PDC')
    exclude = {'seccion__in': exclude_sections}
    if niveles:
        filter['curso__ciclo__nivel__nombre__in'] = niveles.split(',')
    if curso:
        filter['curso__nombre__in'] = curso.split(',')
    for g in GrupoAula.objects.filter(**filter).exclude(**exclude):
        if not dry_run:
            boletin = DjangoWriter()
            boletin.loadFile(os.path.join (settings.OOTEMPLATES, 'boletin.odt'))
            boletin.copyAll()
        alumnos = 0
        for a in g.getAlumnos():
            if not dry_run:
                boletin.pasteEnd()
                a.generaBoletin(boletin)
                boletin.appendPageBreak()
            alumnos += 1
        logger.info("Boletin del grupo %s generado para %d alumnos.", g.__unicode__(), alumnos)

        name = "%s." % g.display_boletin()
        name += 'odt' if odt else 'pdf'
        full_name = os.path.join(directory, name) 
        if not dry_run:
            logger.info("Guardando el fichero en %s" % full_name)
            boletin.saveODT(full_name) if odt else boletin.savePDF(full_name)
            boletin.close()