예제 #1
0
    def _log_download_sketch_stats(self, filename, town):
        sketch_download = SketchDownload()
        sketch_download.login = self.request.user.username
        sketch_download.application = self.request.host
        sketch_download.filename = filename
        sketch_download.directory = town

        PortailSession.add(sketch_download)
        PortailSession.commit()
예제 #2
0
    def _log_download_sketch_stats(self, filename, town):
        sketch_download = SketchDownload()
        sketch_download.login = self.request.user.username
        sketch_download.application = self.request.host
        sketch_download.filename = filename
        sketch_download.directory = town

        PortailSession.add(sketch_download)
        PortailSession.commit()
예제 #3
0
    def _log_download_measurement_stats(self, filename, town, parcel):
        mesurage_download = MesurageDownload()
        if self.request.user is None:
            mesurage_download.login = '******'
        else:
            mesurage_download.login = self.request.user.username

        mesurage_download.application = self.request.host
        mesurage_download.filename = filename
        mesurage_download.commune = town
        mesurage_download.parcelle = parcel

        PortailSession.add(mesurage_download)
        PortailSession.commit()
예제 #4
0
 def __log_download_stats(self, objectids, download_link):
     pag_download = PagDownload()
     pag_download.objectids = objectids
     pag_download.download_link = download_link
     try:
         PortailSession.add(pag_download)
         PortailSession.commit()
     except Exception as e:
         log.exception(e)
         PortailSession.rollback()
예제 #5
0
def ldap_user_validator(request, username, password):
    connector = get_ldap_connector(request)
    data = connector.authenticate(username, password)
    connection = Connections()
    connection.login = username
    connection.application = request.host

    if data is not None:
        connection.action = "CONNECT"
        PortailSession.add(connection)
        PortailSession.commit()
        return data[0]
    else:
        connection.action = "CONNECT ERROR"
        PortailSession.add(connection)
        PortailSession.commit()

    return None
def ldap_user_validator(request, username, password):
    connector = get_ldap_connector(request)
    data = connector.authenticate(username, password)
    connection = Connections()
    connection.login = username
    connection.application = request.host

    if data is not None:
        connection.action = "CONNECT"
        PortailSession.add(connection)
        PortailSession.commit()
        return data[0]
    else:
        connection.action = "CONNECT ERROR"
        PortailSession.add(connection)
        PortailSession.commit()

    return None
예제 #7
0
 def __log_download_stats(self, objectids, download_link):
     pag_download = PagDownload()
     pag_download.objectids = objectids
     pag_download.download_link = download_link
     PortailSession.add(pag_download)
     PortailSession.commit()
예제 #8
0
    def get_route(self):
        coords = self.request.params.get('waypoints', '').split(',')
        lang = self.request.params.get('lang', 'fr')
        transport_mode = int(self.request.params.get('transportMode', 0))
        criteria = int(self.request.params.get('criteria', 0))
        avoid = self.request.params.get('avoid', '').split(',')
        prefer_bike_road =\
            int(self.request.params.get('preferBikeRoad', False))
        bike_avoid_hills =\
            int(self.request.params.get('bikeAvoidHills', False))
        if coords == ['']:
            coords = []

        # At least two waypoints (4 coordinates) are required
        if len(coords) < 4:
            routing_success = False
            return HTTPBadRequest("Not enough waypoints (At least 2 required)")
        else:
            # Use Graphhopper for bicycle routing, Mapquest for all other modes
            if len(coords) <= 10 and transport_mode in [2]:
                r = GraphhopperRouter(self.config['routing']['graphhopper'])

                self.__setup_router(coords, lang, transport_mode, criteria,
                                    avoid, prefer_bike_road, bike_avoid_hills,
                                    r)
                try:
                    r.execute()
                except HTTPError as e:
                    if e.code == 429:
                        r = MapquestRouter(self.config['routing']['mapquest'])
                        self.__setup_router(coords, lang, transport_mode,
                                            criteria, avoid, prefer_bike_road,
                                            bike_avoid_hills, r)
                        r.execute()
                    else:
                        raise e

            else:
                r = MapquestRouter(self.config['routing']['mapquest'])
                self.__setup_router(coords, lang, transport_mode, criteria,
                                    avoid, prefer_bike_road, bike_avoid_hills,
                                    r)
                r.execute()

            if r.geom and len(r.geom) > 0:
                routing_success = True
            else:
                routing_success = False
                r.errorMessages.append('An error occured')
        try:
            routing_stats = RoutingStats()
            routing_stats.transport_mode = transport_mode
            routing_stats.transport_criteria = criteria
            PortailSession.add(routing_stats)
            PortailSession.commit()
        except Exception as e:
            log.exception(e)
            PortailSession.rollback()

        if routing_success:
            json = {
                "type":
                "FeatureCollection",
                "features": [{
                    'type': "Feature",
                    'properties': {
                        'success': routing_success,
                        'desc': r.desc,
                        'dist': int(r.dist),
                        'time': r.time,
                        'errorMessages': r.errorMessages,
                        'attribution': r.attribution
                    },
                    'geometry': r.geom
                }]
            }
        else:
            json = {
                'success': routing_success,
                'geometry': None,
                'desc': [],
                'dist': 0,
                'time': 0,
                'errorMessages': r.errorMessages,
                'attribution': r.attribution
            }

        return json
예제 #9
0
    def get_route(self):
        coords = self.request.params.get('waypoints', '').split(',')
        lang = self.request.params.get('lang', 'fr')
        transport_mode = int(self.request.params.get('transportMode', 0))
        criteria = int(self.request.params.get('criteria', 0))
        avoid = self.request.params.get('avoid', '').split(',')
        prefer_bike_road =\
            int(self.request.params.get('preferBikeRoad', False))
        bike_avoid_hills =\
            int(self.request.params.get('bikeAvoidHills', False))
        if coords == ['']:
            coords = []

        # At least two waypoints (4 coordinates) are required
        if len(coords) < 4:
            routing_success = False
            return HTTPBadRequest("Not enough waypoints (At least 2 required)")
        else:
            # Use Graphhopper for bicycle routing, Mapquest for all other modes
            if len(coords) <= 10 and transport_mode in [2]:
                r = GraphhopperRouter(self.config['routing']['graphhopper'])

                self.__setup_router(coords, lang, transport_mode, criteria,
                                    avoid, prefer_bike_road, bike_avoid_hills,
                                    r)
                try:
                    r.execute()
                except HTTPError as e:
                    if e.code == 429:
                        r = MapquestRouter(self.config['routing']['mapquest'])
                        self.__setup_router(
                            coords, lang, transport_mode,
                            criteria, avoid, prefer_bike_road,
                            bike_avoid_hills, r)
                        r.execute()
                    else:
                        raise e

            else:
                r = MapquestRouter(self.config['routing']['mapquest'])
                self.__setup_router(
                    coords, lang, transport_mode, criteria,
                    avoid, prefer_bike_road, bike_avoid_hills, r)
                r.execute()

            if r.geom and len(r.geom) > 0:
                routing_success = True
            else:
                routing_success = False
                r.errorMessages.append('An error occured')
        try:
            routing_stats = RoutingStats()
            routing_stats.transport_mode = transport_mode
            routing_stats.transport_criteria = criteria
            PortailSession.add(routing_stats)
            PortailSession.commit()
        except Exception as e:
            log.exception(e)
            PortailSession.rollback()

        if routing_success:
            json = {
                "type": "FeatureCollection",
                "features": [
                    {'type': "Feature",
                     'properties': {
                        'success': routing_success,
                        'desc': r.desc, 'dist': int(r.dist),
                        'time': r.time,
                        'errorMessages': r.errorMessages,
                        'attribution': r.attribution},
                     'geometry': r.geom}]}
        else:
            json = {'success': routing_success,
                    'geometry': None,
                    'desc': [],
                    'dist': 0,
                    'time': 0,
                    'errorMessages': r.errorMessages,
                    'attribution': r.attribution}

        return json
예제 #10
0
 def __log_download_stats(self, objectids, download_link):
     pag_download = PagDownload()
     pag_download.objectids = objectids
     pag_download.download_link = download_link
     PortailSession.add(pag_download)
     PortailSession.commit()