예제 #1
0
    def browse_view(self):
        params = request.args.items()
        params = dict((k, v) for k, v in params if v)
        print params
        def test_and_remove(key):
            if request.args.get(key):
                if request.args.get(key).lower() == request.args.get("query").lower():
                    erase_from_dict(params, 'query')

        if not request.args.get("location"):
            try:
                reader = geoip2.database.Reader(os.path.realpath('.') + '/static/data/GeoLite2-Country.mmdb')
                ip = get_real_ip()
                if ip == '127.0.0.1' or ip == '0.0.0.0':
                    ip = urlopen('http://ip.42.pl/raw').read()  # On local test environments
                response = reader.country(ip)
                country = response.country.name
            except:
                country = "United States"
        else:
            country = request.args.get("location")

        test_and_remove("location")
        test_and_remove("category")
        erase_from_dict(params, 'location')

        return redirect(url_for('explore.explore_view', location=slugify(country)) + '?' +
                        urllib.urlencode(params))
    def browse_view(self):
        params = request.args.items()
        params = dict((k, v) for k, v in params if v)

        def test_and_remove(key):
            if request.args.get(key):
                if request.args.get(key).lower() == request.args.get("query").lower():
                    erase_from_dict(params, 'query')

        if not request.args.get("location"):
            try:
                reader = geoip2.database.Reader(os.path.realpath('.') + '/static/data/GeoLite2-Country.mmdb')
                ip = get_real_ip()
                if ip == '127.0.0.1' or ip == '0.0.0.0':
                    ip = urlopen('http://ip.42.pl/raw').read()  # On local test environments
                response = reader.country(ip)
                country = response.country.name
            except:
                country = "United States"
        else:
            country = request.args.get("location")

        test_and_remove("location")
        test_and_remove("category")
        erase_from_dict(params, 'location')

        return redirect(url_for('explore.explore_view', location=slugify(country)) + '?' +
                        urllib.urlencode(params))
예제 #3
0
 def test_and_remove(key):
     if request.args.get(key):
         if request.args.get(key).lower() == request.args.get("query").lower():
             erase_from_dict(params, 'query')
 def test_and_remove(key):
     if request.args.get(key):
         if request.args.get(key).lower() == request.args.get("query").lower():
             erase_from_dict(params, 'query')