def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) context['debug'] = settings.DEBUG context['locality_count'] = get_country_statistic('')['localities'] if request.user.is_authenticated(): if request.user.is_staff: context['uploader'] = True else: permission = DataLoaderPermission.objects.filter(uploader=request.user) if len(permission) <= 0: context['uploader'] = False else: context['uploader'] = True else: context['uploader'] = False return self.render_to_response(context)
def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) context['debug'] = settings.DEBUG context['locality_count'] = get_country_statistic("")['localities'] if request.user.is_authenticated(): if request.user.is_staff: context['uploader'] = True else: permission = DataLoaderPermission.objects.filter( uploader=request.user) if len(permission) <= 0: context['uploader'] = False else: context['uploader'] = True else: context['uploader'] = False return self.render_to_response(context)
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) )
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))
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))