Ejemplo n.º 1
0
    def init_zupc(self):
        zupc = ZUPC()
        zupc.insee = '75056'
        zupc.nom = 'Paris'
        poly = Polygon([(48,2), (49,2), (49,3), (48,3)])
        zupc.shape = from_shape(MultiPolygon([poly]), srid=4326)
        db.session.add(zupc)
        db.session.commit()
        zupc.parent_id = zupc.id

        zupc2 = ZUPC()
        zupc2.insee = '93048'
        zupc2.nom = 'Montreuil'
        zupc2.parent_id = zupc.id
        db.session.add(zupc2)
        db.session.commit()
Ejemplo n.º 2
0
def dashboard():
    zupc_parent_id = set()
    zupc_parent = []
    logger = current_app.logger
    query = db.session.query(ADS.zupc_id)
    if not current_user.has_role('admin'):
        query.filter_by(added_by = current_user.id)
    for zupc_tuple in query.distinct():
        if not zupc_tuple.zupc_id or zupc_tuple.zupc_id in zupc_parent_id:
            continue
        zupc = ZUPC.get(zupc_tuple.zupc_id)
        if not zupc:
            logger.info('Unable to find ZUPC with id: {}'.format(zupc_tuple.zupc_id))
            continue
        if not zupc.parent:
            logger.info('Unable to find a ZUPC parent with id: {}'.format(zupc.parent_id))
            continue
        if zupc.parent.id in zupc_parent_id:
            continue
        zupc_parent.append({"insee": zupc.parent.insee, "name": zupc.parent.nom})
        zupc_parent_id.add(zupc.parent.id)

    return render_template('dash.html', apikey=current_user.apikey, zupc_list=zupc_parent)