コード例 #1
0
ファイル: utils.py プロジェクト: jorgeecardona/mollyproject
        def h(*args, **kwargs):
            args = getargsfunc(*args, **kwargs)
            app = get_app('molly.geolocation', args.pop('local_name', None))
            try:
                return Geocode.recent.get(local_name=app.local_name, **args).results
            except Geocode.DoesNotExist:
                pass
            results = f(providers=app.providers, **args)

            i = 0
            while i < len(results):
                loc, name = Point(results[i]['location'], srid=4326).transform(settings.SRID, clone=True), results[i]['name']
                if any((r['name'] == name and Point(r['location'], srid=4326).transform(settings.SRID, clone=True).distance(loc) < 100) for r in results[:i]):
                    results[i:i+1] = []
                else:
                    i += 1

            if hasattr(app, 'prefer_results_near'):
                point = Point(app.prefer_results_near[:2], srid=4326).transform(settings.SRID, clone=True)
                distance = app.prefer_results_near[2]
                filtered_results = [
                    result for result in results if
                        Point(result['location'], srid=4326).transform(settings.SRID, clone=True).distance(point) <= distance]
                if filtered_results:
                    results = filtered_results

            geocode, _ = Geocode.objects.get_or_create(local_name = app.local_name,
                                                       **args)
            geocode.results = results
            geocode.save()
            
            return results
コード例 #2
0
        def h(*args, **kwargs):
            args = getargsfunc(*args, **kwargs)
            app = get_app('molly.geolocation', args.pop('local_name', None))
            try:
                geocode = Geocode.recent.get(local_name=app.local_name, **args)
                logger.debug('Found cached geocode')
                return geocode.results
            except Geocode.DoesNotExist:
                logger.debug('Geocode not found in cache')
                pass
            except Geocode.MultipleObjectsReturned:
                Geocode.recent.filter(local_name=app.local_name,
                                      **args).delete()
            results = f(providers=app.providers, **args)

            i = 0
            while i < len(results):
                loc, name = Point(results[i]['location']), results[i]['name']
                if any((r['name'] == name
                        and haversine(Point(r['location']), loc) < 100)
                       for r in results[:i]):
                    results[i:i + 1] = []
                else:
                    i += 1

            if hasattr(app, 'prefer_results_near'):
                point = Point(app.prefer_results_near[:2])
                distance = app.prefer_results_near[2]
                filtered_results = [
                    result for result in results
                    if haversine(Point(result['location']), point) <= distance
                ]
                if filtered_results:
                    results = filtered_results

            try:
                geocode, created = Geocode.objects.get_or_create(
                    local_name=app.local_name, **args)
            except Geocode.MultipleObjectsReturned:
                Geocode.objects.filter(local_name=app.local_name,
                                       **args).delete()
                geocode, created = Geocode.objects.get_or_create(
                    local_name=app.local_name, **args)
            geocode.results = results
            geocode.save()

            return results
コード例 #3
0
ファイル: __init__.py プロジェクト: puntofisso/mollyproject
        def h(*args, **kwargs):
            args = getargsfunc(*args, **kwargs)
            app = get_app('molly.geolocation', args.pop('local_name', None))
            try:
                geocode = Geocode.recent.get(local_name=app.local_name, **args)
                logger.debug('Found cached geocode')
                return geocode.results
            except Geocode.DoesNotExist:
                logger.debug('Geocode not found in cache')
                pass
            except Geocode.MultipleObjectsReturned:
                Geocode.recent.filter(local_name=app.local_name, **args).delete()
            results = f(providers=app.providers, **args)

            i = 0
            while i < len(results):
                loc, name = Point(results[i]['location']), results[i]['name']
                if any((r['name'] == name and haversine(Point(r['location']), loc) < 100) for r in results[:i]):
                    results[i:i+1] = []
                else:
                    i += 1
            
            if hasattr(app, 'prefer_results_near'):
                point = Point(app.prefer_results_near[:2])
                distance = app.prefer_results_near[2]
                filtered_results = [
                    result for result in results if
                        haversine(Point(result['location']), point) <= distance]
                if filtered_results:
                    results = filtered_results

            try:
                geocode, created = Geocode.objects.get_or_create(
                    local_name=app.local_name, **args)
            except Geocode.MultipleObjectsReturned:
                Geocode.objects.filter(local_name=app.local_name, **args).delete()
                geocode, created = Geocode.objects.get_or_create(
                    local_name=app.local_name, **args)
            geocode.results = results
            geocode.save()
            
            return results
コード例 #4
0
ファイル: __init__.py プロジェクト: nicosiseng/mollyproject
        def h(*args, **kwargs):
            args = getargsfunc(*args, **kwargs)
            app = get_app('molly.geolocation', args.pop('local_name', None))
            try:
                return Geocode.recent.get(local_name=app.local_name, **args).results
            except Geocode.DoesNotExist:
                pass
            except Geocode.MultipleObjectsReturned:
                Geocode.recent.filter(local_name=app.local_name, **args).delete()
            results = f(providers=app.providers, **args)

            i = 0
            while i < len(results):
                loc, name = Point(results[i]['location'], srid=4326).transform(settings.SRID, clone=True), results[i]['name']
                if any((r['name'] == name and Point(r['location'], srid=4326).transform(settings.SRID, clone=True).distance(loc) < 100) for r in results[:i]):
                    results[i:i+1] = []
                else:
                    i += 1

            if hasattr(app, 'prefer_results_near'):
                point = Point(app.prefer_results_near[:2], srid=4326).transform(settings.SRID, clone=True)
                distance = app.prefer_results_near[2]
                filtered_results = [
                    result for result in results if
                        Point(result['location'], srid=4326).transform(settings.SRID, clone=True).distance(point) <= distance]
                if filtered_results:
                    results = filtered_results

            try:
                geocode, _ = Geocode.objects.get_or_create(local_name = app.local_name,
                                                            **args)
            except Geocode.MultipleObjectsReturned:
                Geocode.objects.filter(local_name = app.local_name, **args).delete()
                geocode, _ = Geocode.objects.get_or_create(local_name = app.local_name,
                                                            **args)
            geocode.results = results
            geocode.save()
            
            return results