def delete_metadata_updates(self, heb_pk):
     """
     Deletes all the records in the link_hebergement_metadata_update for
     the given hebergement pk
     """
     session = Session()
     query = session.query(mappers.LinkHebergementMetadataUpdate).join(
         'link_metadata')
     query = query.filter(mappers.LinkHebergementMetadata.heb_fk == heb_pk)
     for metadata in query.all():
         session.delete(metadata)
def updateGroupementColumn():
    session = DBSession()
    hebs = session.query(Hebergement).join('type')
    hebs = hebs.order_by(Hebergement.heb_pro_fk,
                         TypeHebergement.type_heb_type,
                         Hebergement.heb_cgt_cap_min.desc())

    groupementPk = 1
    proprioGroupedHebsPk = []
    actualProprio = None

    for heb in hebs:
        #Change proprio
        if actualProprio != heb.heb_pro_fk:
            proprioGroupedHebsPk = []
        actualProprio = heb.heb_pro_fk

        if heb.heb_pk not in proprioGroupedHebsPk:
            hebType = heb.type.type_heb_type
            groupedHebs = getGroupedHebs(heb, proprioGroupedHebsPk, hebType,
                                         session)
            if groupedHebs:
                #add this one to the list to update
                groupedHebs.append(heb)
                setGroupementPk(groupedHebs, groupementPk)
                proprioGroupedHebsPk.extend([obj.heb_pk for obj in groupedHebs])
                groupementPk += 1
            else:
                emptyGroupementPk(heb)
    session.commit()
    session.flush()
def updateHebsSortOrder():
    session = DBSession()

    query = session.query(Hebergement).join("app")
    query = query.order_by(func.random())

    position = 1
    for heb in query.all():
        heb.app.heb_app_sort_order = position
        session.add(heb)
        position += 1

    session.commit()
    session.flush()

    memcache = memcachedClient()
    memcache.invalidateAll()
def updateMaison():
    session = DBSession()

    query = session.query(MaisonTourisme)
    query = query.filter(and_(MaisonTourisme.mais_gps_lat != None,
                              MaisonTourisme.mais_gps_long != None))
    maisonTours = query.all()

    for maisonTour in maisonTours:
        point = 'POINT(%s %s)' % (maisonTour.mais_gps_long, maisonTour.mais_gps_lat)
        point = geoalchemy.base.WKTSpatialElement(point, srid=3447)
        if maisonTour.mais_location is None or \
           tuple(maisonTour.mais_location.coords(session)) != \
           tuple([maisonTour.mais_gps_long, maisonTour.mais_gps_lat]):
            maisonTour.mais_location = point

    session.commit()
    session.flush()
def updateInfoPrat():
    session = DBSession()

    query = session.query(InfoPratique)
    query = query.filter(and_(InfoPratique.infoprat_gps_lat != None,
                              InfoPratique.infoprat_gps_long != None))
    infoPrats = query.all()

    for infoPrat in infoPrats:
        point = 'POINT(%s %s)' % (infoPrat.infoprat_gps_long, infoPrat.infoprat_gps_lat)
        point = geoalchemy.base.WKTSpatialElement(point, srid=3447)
        if infoPrat.infoprat_location is None or \
           tuple(infoPrat.infoprat_location.coords(session)) != \
           tuple([infoPrat.infoprat_gps_long, infoPrat.infoprat_gps_lat]):
            infoPrat.infoprat_location = point

    session.commit()
    session.flush()
def updateExtData():
    session = DBSession()

    query = session.query(MapExternalData)
    query = query.filter(and_(MapExternalData.ext_data_latitude != None,
                              MapExternalData.ext_data_longitude != None))
    extDatas = query.all()

    for extData in extDatas:
        point = 'POINT(%s %s)' % (extData.ext_data_longitude, extData.ext_data_latitude)
        point = geoalchemy.base.WKTSpatialElement(point, srid=3447)
        if extData.ext_data_location is None or \
           tuple(extData.ext_data_location.coords(session)) != \
           tuple([extData.ext_data_longitude, extData.ext_data_latitude]):
            extData.ext_data_location = point

    session.commit()
    session.flush()
def updateHebergement():
    session = DBSession()

    query = session.query(Hebergement)
    query = query.filter(and_(Hebergement.heb_gps_lat != None,
                              Hebergement.heb_gps_long != None))
    query = query.filter(and_(Hebergement.heb_gps_lat != 0,
                              Hebergement.heb_gps_long != 0))
    hebs = query.all()

    for heb in hebs:
        point = 'POINT(%s %s)' % (heb.heb_gps_long, heb.heb_gps_lat)
        point = geoalchemy.base.WKTSpatialElement(point, srid=3447)
        if heb.heb_location is None or \
           tuple(heb.heb_location.coords(session)) != \
           tuple([heb.heb_gps_long, heb.heb_gps_lat]):
            heb.heb_location = point
    session.flush()
    session.commit()