示例#1
0
def map(request):
    """View for request."""
    if request.user.is_authenticated():
        user = get_object_or_404(User, username=request.user)
        request.user = get_profile(user)

    if request.method == 'POST':
        search_query = request.POST.get('q')
        option = request.POST.get('option')
        if option == 'place':
            map_url = reverse('map')
            return HttpResponseRedirect(
                map_url + '?place=%s' % search_query)
        elif option == 'what3words':
            locality_values = Value.objects.filter(
                specification__attribute__key='what3words').filter(
                data=search_query)
            if locality_values:
                locality_value = locality_values[0]
            else:
                return render_to_response(
                    'map.html',
                    context_instance=RequestContext(request)
                )
            locality_uuid = locality_value.locality.uuid
            map_url = reverse('map')
            return HttpResponseRedirect(
                map_url + '#!/locality/%s' % locality_uuid)
        elif option == 'healthsite':
            localities = Locality.objects.filter(
                name=search_query)
            if len(localities) > 0:
                locality = localities[0]
                locality_uuid = locality.uuid
                map_url = reverse('map')
                return HttpResponseRedirect(
                    map_url + '#!/locality/%s' % locality_uuid)
            else:
                return render_to_response(
                    'map.html',
                    context_instance=RequestContext(request)
                )
    else:
        tag = request.GET.get('tag')
        country = request.GET.get('country')
        place = request.GET.get('place')
        attribute = request.GET.get('attribute')
        result = {}

        if tag:
            result = search_locality_by_tag(tag)
            result['tag'] = tag
        elif country:
            result = get_country_statistic(country)
            result['country'] = country
            result['polygon'] = (
                Country.objects.get(name__iexact=country).polygon_geometry.geojson
            )
            result['shapefile_size'] = 0
            filename = os.path.join(directory_media, country + '_shapefile.zip')
            if (os.path.isfile(filename)):
                result['shapefile_size'] = size(os.path.getsize(filename)) + 'B'
        elif place:
            result = search_place(request, place)
        elif attribute:
            uuid = request.GET.get('uuid')
            result = search_locality_by_spec_data('attribute', attribute, uuid)
            result['attribute'] = {
                'attribute': attribute, 'uuid': uuid, 'name': result['locality_name'],
                'location': result['location']
            }
        elif len(request.GET) == 0:
            result = search_place(request, place)
            # get facilities shapefile size
            result['shapefile_size'] = 0
            filename = os.path.join(directory_media, 'facilities_shapefile.zip')
            if (os.path.isfile(filename)):
                result['shapefile_size'] = size(os.path.getsize(filename)) + 'B'
        else:
            uuid = request.GET.get('uuid')
            for item in request.GET:
                if item != 'uuid':
                    spec = item
                    data = request.GET.get(item)
                    result = search_locality_by_spec_data(spec, data, uuid)
                    result['spec'] = {
                        'spec': spec, 'data': data, 'uuid': uuid,
                        'name': result['locality_name'], 'location': result['location']
                    }

        if 'new_geom' in request.session:
            result['new_geom'] = request.session['new_geom']
            del request.session['new_geom']
        return render_to_response(
            'map.html',
            result,
            context_instance=RequestContext(request)
        )
示例#2
0
def map(request):
    """View for request."""
    if request.user.is_authenticated():
        user = get_object_or_404(User, username=request.user)
        request.user = get_profile(user, request)

    if request.method == 'POST':
        search_query = request.POST.get('q')
        option = request.POST.get('option')
        if option == 'place':
            map_url = reverse('map')
            return HttpResponseRedirect(
                map_url + '?place=%s' % search_query)
        elif option == 'what3words':
            locality_values = Value.objects.filter(
                specification__attribute__key='what3words').filter(
                data=search_query)
            if locality_values:
                locality_value = locality_values[0]
            else:
                return render_to_response(
                    'map.html',
                    context_instance=RequestContext(request)
                )
            locality_uuid = locality_value.locality.uuid
            map_url = reverse('map')
            return HttpResponseRedirect(
                map_url + '#!/locality/%s' % locality_uuid)
        elif option == 'healthsite':
            localities = Locality.objects.filter(
                name=search_query)
            if len(localities) > 0:
                locality = localities[0]
                locality_uuid = locality.uuid
                map_url = reverse('map')
                return HttpResponseRedirect(
                    map_url + '#!/locality/%s' % locality_uuid)
            else:
                return render_to_response(
                    'map.html',
                    context_instance=RequestContext(request)
                )
    else:
        tag = request.GET.get('tag')
        country = request.GET.get('country')
        attribute = request.GET.get('attribute')
        uuid = request.GET.get('uuid')
        result = {}

        if tag:
            result = search_locality_by_tag(tag)
            result['tag'] = tag
        elif country:
            pass
        elif attribute:
            uuid = request.GET.get('uuid')
            result = search_locality_by_spec_data('attribute', attribute, uuid)
            result['attribute'] = {
                'attribute': attribute, 'uuid': uuid, 'name': result['locality_name'],
                'location': result['location']
            }
        elif uuid:
            for item in request.GET:
                if item != 'uuid':
                    spec = item
                    data = request.GET.get(item)
                    result = search_locality_by_spec_data(spec, data, uuid)
                    result['spec'] = {
                        'spec': spec, 'data': data, 'uuid': uuid,
                        'name': result['locality_name'], 'location': result['location']
                    }
        else:
            result = search_place(request, None)
            # get facilities shapefile size
            result['shapefile_size'] = 0
            filename = os.path.join(directory_media, 'facilities_shapefile.zip')
            if (os.path.isfile(filename)):
                result['shapefile_size'] = size(os.path.getsize(filename)) + 'B'

        if 'new_geom' in request.session:
            result['new_geom'] = request.session['new_geom']
            del request.session['new_geom']

        result['osm_API'] = settings.OSM_API_URL
        result['map_max_zoom'] = settings.MAX_ZOOM
        result['schema'] = json.dumps(Schema().get_schema())
        return render_to_response(
            'map.html',
            result,
            context_instance=RequestContext(request)
        )
示例#3
0
def map(request):
    """View for request."""
    if request.user.is_authenticated():
        user = get_object_or_404(User, username=request.user)
        request.user = get_profile(user)

    if request.method == 'POST':
        search_query = request.POST.get('q')
        option = request.POST.get('option')
        if option == 'place':
            map_url = reverse('map')
            return HttpResponseRedirect(map_url + "?place=%s" % search_query)
        elif option == 'what3words':
            locality_values = Value.objects.filter(
                specification__attribute__key='what3words').filter(
                    data=search_query)
            if locality_values:
                locality_value = locality_values[0]
            else:
                return render_to_response(
                    'map.html', context_instance=RequestContext(request))
            locality_uuid = locality_value.locality.uuid
            map_url = reverse('map')
            return HttpResponseRedirect(map_url +
                                        "#!/locality/%s" % locality_uuid)
        elif option == 'healthsite':
            localities = Locality.objects.filter(name=search_query)
            if len(localities) > 0:
                locality = localities[0]
                locality_uuid = locality.uuid
                map_url = reverse('map')
                return HttpResponseRedirect(map_url +
                                            "#!/locality/%s" % locality_uuid)
            else:
                return render_to_response(
                    'map.html', context_instance=RequestContext(request))
    else:
        tag = request.GET.get('tag')
        country = request.GET.get('country')
        place = request.GET.get('place')
        attribute = request.GET.get('attribute')
        result = {}
        if tag:
            result = search_locality_by_tag(tag)
            result['tag'] = tag
        elif country:
            result = get_country_statistic(country)
            result['country'] = country
            result['polygon'] = Country.objects.get(
                name__iexact=country).polygon_geometry.geojson
        elif place:
            result = search_place(request, place)
        elif attribute:
            uuid = request.GET.get('uuid')
            result = search_locality_by_spec_data("attribute", attribute, uuid)
            result['attribute'] = {
                'attribute': attribute,
                'uuid': uuid,
                'name': result['locality_name'],
                'location': result['location']
            }
        elif len(request.GET) == 0:
            result = search_place(request, place)
        else:
            uuid = request.GET.get('uuid')
            for item in request.GET:
                if item != "uuid":
                    spec = item
                    data = request.GET.get(item)
                    result = search_locality_by_spec_data(spec, data, uuid)
                    result['spec'] = {
                        'spec': spec,
                        'data': data,
                        'uuid': uuid,
                        'name': result['locality_name'],
                        'location': result['location']
                    }

        if 'new_geom' in request.session:
            result["new_geom"] = request.session['new_geom']
            del request.session['new_geom']
        return render_to_response('map.html',
                                  result,
                                  context_instance=RequestContext(request))
示例#4
0
def map(request):
    """View for request."""
    if request.user.is_authenticated():
        user = get_object_or_404(User, username=request.user)
        request.user = get_profile(user)

    if request.method == 'POST':
        search_query = request.POST.get('q')
        option = request.POST.get('option')
        if option == 'place':
            map_url = reverse('map')
            return HttpResponseRedirect(map_url + '?place=%s' % search_query)
        elif option == 'healthsite':
            localities = Locality.objects.filter(name=search_query)
            if len(localities) > 0:
                locality = localities[0]
                locality_uuid = locality.uuid
                map_url = reverse('map')
                return HttpResponseRedirect(map_url +
                                            '#!/locality/%s' % locality_uuid)
            else:
                return render_to_response(
                    'map.html', context_instance=RequestContext(request))
    else:
        tag = request.GET.get('tag')
        country = request.GET.get('country')
        place = request.GET.get('place')
        attribute = request.GET.get('attribute')
        result = {}

        if tag:
            result = search_locality_by_tag(tag)
            result['tag'] = tag
        elif country:
            result = get_country_statistic(country)
            result['country'] = country
            result['polygon'] = (Country.objects.get(
                name__iexact=country).polygon_geometry.geojson)
            result['shapefile_size'] = 0
            filename = os.path.join(directory_media,
                                    country + '_shapefile.zip')
            if (os.path.isfile(filename)):
                result['shapefile_size'] = size(
                    os.path.getsize(filename)) + 'B'
        elif place:
            result = search_place(request, place)
        elif attribute:
            uuid = request.GET.get('uuid')
            result = search_locality_by_spec_data('attribute', attribute, uuid)
            result['attribute'] = {
                'attribute': attribute,
                'uuid': uuid,
                'name': result['locality_name'],
                'location': result['location']
            }
        elif len(request.GET) == 0:
            result = search_place(request, place)
            # get facilities shapefile size
            result['shapefile_size'] = 0
            filename = os.path.join(directory_media,
                                    'facilities_shapefile.zip')
            if (os.path.isfile(filename)):
                result['shapefile_size'] = size(
                    os.path.getsize(filename)) + 'B'
        else:
            uuid = request.GET.get('uuid')
            for item in request.GET:
                if item != 'uuid':
                    spec = item
                    data = request.GET.get(item)
                    result = search_locality_by_spec_data(spec, data, uuid)
                    result['spec'] = {
                        'spec': spec,
                        'data': data,
                        'uuid': uuid,
                        'name': result['locality_name'],
                        'location': result['location']
                    }

        if 'new_geom' in request.session:
            result['new_geom'] = request.session['new_geom']
            del request.session['new_geom']
        return render_to_response('map.html',
                                  result,
                                  context_instance=RequestContext(request))