Beispiel #1
0
def get_agents():
    '''
    retourne la liste des agents en cours de recrutement
    '''
    today = datetime.date.today()
    _format = request.args.get('format', 'dict')
    add_prev_years = request.args.get('add_prev_years', False)
    if add_prev_years == 'false':
        add_prev_years = False
    try:
        annee = request.args.get('annee', False)
        if not annee:
            annee = today.year
        else:
            annee = int(annee)
    except ValueError:
        return [], 400
    try:
        annee_deb = datetime.date(annee, 1, 1)
        annee_fin = datetime.date(annee, 12, 31)
        if not add_prev_years:
            ag_list = get_agents_annee(annee_deb, annee_fin, _format)
        else:
            ag_list = get_agents_presents(annee_deb, annee_fin, _format)
        if _format == 'csv':
            return csv_response(AgentDetailSerializer.export_csv(
                ag_list, fields=csv_fields),
                                filename='recrutement.csv')
        else:
            return [AgentSerializer(res).dump() for res in ag_list]
    except Exception:
        import traceback
        return [{'msg': traceback.format_exc()}], 400
Beispiel #2
0
def get_entites():
    '''
    retourne la liste des groupes
    '''
    entite_ids = request.args.getlist('params')
    _format = request.args.get('format', None)
    _etype = request.args.get('type', 'correspondant')
    if not len(entite_ids):
        entites = Entite.query.all()
    else:
        entites = get_entites_by_parent(entite_ids)
    if _format in ('csv', 'tsv'):
        serializer = SERIALIZERS_E[_etype]
        entites = filter(lambda x: isinstance(x, TYPES_E[_etype]) ,entites)
        if _format == 'csv':
            csv = serializer.export_csv(entites, fields=FIELDS_E[_etype])
        else:
            csv = serializer.export_csv(entites, fields=FIELDS_E[_etype], sep='\t')
        return csv_response(csv, 'annuaire.csv')
    if _format == 'vcard':
        vcards = '\r\n'.join([
                format_vcard(CorrespondantSerializer(e)) for e in entites
                if isinstance(e, Correspondant)
                ])
        return vcard_response(vcards, 'annuaire.vcf')

    return [SERIALIZERS_E[e.type_entite](e).serialize() for e in entites]
Beispiel #3
0
def get_agents():
    '''
    retourne la liste des agents en cours de recrutement
    '''
    today = datetime.date.today()
    _format = request.args.get('format', 'dict')
    add_prev_years = request.args.get('add_prev_years', False)
    if add_prev_years == 'false':
        add_prev_years = False
    try:
        annee = request.args.get('annee', False)
        if not annee:
            annee = today.year
        else:
            annee = int(annee)
    except ValueError:
        return [], 400
    try:
        annee_deb = datetime.date(annee, 1, 1)
        annee_fin = datetime.date(annee, 12, 31)
        if not add_prev_years:
            ag_list = get_agents_annee(annee_deb, annee_fin, _format)
        else:
            ag_list = get_agents_presents(annee_deb, annee_fin, _format)
        if _format == 'csv':
            return csv_response(AgentDetailSerializer.export_csv(ag_list, fields=csv_fields), filename='recrutement.csv')
        else:
            return [AgentSerializer(res).serialize() for res in ag_list]
    except Exception:
        import traceback
        return [{'msg': traceback.format_exc()}], 400
Beispiel #4
0
def get_interventions():
    """
    retourne la liste des demandes d'intervention
    """

    today = datetime.date.today()
    _format = request.args.get('format', 'dict')
    add_prev_years = request.args.get('add_prev_years', False)
    if add_prev_years == 'false':
        add_prev_years = False
    try:
        annee = request.args.get('annee', False)
        if not annee:
            annee = today.year
        else:
            annee = int(annee)
    except ValueError:
        return [], 400
    try:
        annee_deb = datetime.date(annee, 1, 1)
        annee_fin = datetime.date(annee, 12, 31)
        if not add_prev_years:
            results = get_demande_annee(annee_deb, annee_fin)
        else:
            results = get_demande_encours(annee_deb, annee_fin)

        print(len(results))
        if _format == 'csv':
            return csv_response(DemandeFullSerializer.export_csv(results, fields=csv_fields), filename='interventions.csv')
        else:
            return [DemandeSerializer(res).serialize() for res in results]
    except Exception:
        import traceback
        return [{'msg': traceback.format_exc()}], 400
Beispiel #5
0
def get_all_trav_batiments():
    """
    retourne la liste des demandes de travaux sur batiments
    """
    today = datetime.date.today()
    _format = request.args.get('format', 'dict')
    add_prev_years = request.args.get('add_prev_years', False)
    if add_prev_years == 'false':
        add_prev_years = False
    try:
        annee = request.args.get('annee', False)
        if not annee:
            annee = today.year
        else:
            annee = int(annee)
    except ValueError:
        return [], 400
    try:
        annee_deb = datetime.date(annee, 1, 1)
        annee_fin = datetime.date(annee, 12, 31)
        if not add_prev_years:
            results = get_demande_annee(annee_deb, annee_fin)
        else:
            results = get_demande_encours(annee_deb, annee_fin)

        if _format == 'csv':
            return csv_response(TravauxBatimentFullSerializer.export_csv(
                results, fields=csv_fields),
                                filename='travaux.csv')

        return [TravauxBatimentSerializer(res).serialize() for res in results]
    except Exception:
        import traceback
        return [{'msg': traceback.format_exc()}], 400
Beispiel #6
0
def get_subs():
    _format = request.args.get('format', 'dict')
    _term = request.args.get('add_term', False)
    subs = _db.session.query(DemandeSubvention).all()
    if _format == 'csv':
        return csv_response(SubvFullSerializer.export_csv(subs,
                                                          fields=csv_fields),
                            filename='subventions.csv')
    return [SubvSerializer(sub).dump() for sub in subs]
Beispiel #7
0
def get_entites():
    '''
    retourne la liste des groupes
    '''
    entite_ids = request.args.getlist('params')
    _format = request.args.get('format', None)
    _etype = request.args.get('type', 'correspondant')
    if not len(entite_ids):
        if not request.args.get('all', False):
            return {}
        entites = Entite.query.all()
    else:
        parents = Entite.query.filter(Entite.id.in_(entite_ids)).all()
        filters = [Entite.parents.contains(z) for z in parents]
        entites = Entite.query.filter(_db.and_(*filters)).order_by(
            Entite.type_entite).order_by(Entite.nom).all()
    if _format in ('csv', 'tsv'):
        ent_type, serializer = TYPES_E[_etype]
        entites = filter(lambda x: isinstance(x, ent_type), entites)
        if _format == 'csv':
            csv = serializer.export_csv(entites, fields=FIELDS_E[_etype])
        else:
            csv = serializer.export_csv(entites,
                                        fields=FIELDS_E[_etype],
                                        sep='\t')
        return csv_response(csv, 'annuaire.csv')
    if _format == 'vcard':
        vcards = '\r\n'.join([
            format_vcard(CorrespondantSerializer(e)) for e in entites
            if isinstance(e, Correspondant)
        ])
        return vcard_response(vcards, 'annuaire.vcf')

    return {
        'recherche': [TYPES_E[e.type_entite][1](e).dump() for e in parents],
        'liste': [TYPES_E[e.type_entite][1](e).dump() for e in entites]
    }