def map_view(request, username, id_string): owner = get_object_or_404(User, username=username) xform = get_object_or_404(XForm, id_string=id_string, user=owner) if not has_permission(xform, owner, request): return HttpResponseForbidden(_(u"Not shared.")) context = RequestContext(request) context.content_user = owner context.xform = xform context.profile, created = UserProfile.objects.get_or_create(user=owner) points = ParsedInstance.objects.values("lat", "lng", "instance").filter( instance__user=owner, instance__xform__id_string=id_string, lat__isnull=False, lng__isnull=False ) center = { "lat": round_down_geopoint(average([p["lat"] for p in points])), "lng": round_down_geopoint(average([p["lng"] for p in points])), } def round_down_point(p): return {"lat": round_down_geopoint(p["lat"]), "lng": round_down_geopoint(p["lng"]), "instance": p["instance"]} context.center = json.dumps(center) context.form_view = True context.jsonform_url = reverse(download_jsonform, kwargs={"username": username, "id_string": id_string}) context.mongo_api_url = reverse(main.views.api, kwargs={"username": username, "id_string": id_string}) context.mapbox_layer = MetaData.mapbox_layer_upload(xform) return render_to_response("map.html", context_instance=context)
def map_view(request, username, id_string): owner = get_object_or_404(User, username=username) xform = get_object_or_404(XForm, id_string=id_string, user=owner) if not has_permission(xform, owner, request): return HttpResponseForbidden('Not shared.') context = RequestContext(request) context.content_user = owner context.xform = xform context.profile, created = UserProfile.objects.get_or_create(user=owner) points = ParsedInstance.objects.values('lat', 'lng', 'instance').filter( instance__user=owner, instance__xform__id_string=id_string, lat__isnull=False, lng__isnull=False) center = { 'lat': round_down_geopoint(average([p['lat'] for p in points])), 'lng': round_down_geopoint(average([p['lng'] for p in points])), } def round_down_point(p): return { 'lat': round_down_geopoint(p['lat']), 'lng': round_down_geopoint(p['lng']), 'instance': p['instance'] } context.center = json.dumps(center) context.form_view = True context.jsonform_url = reverse(download_jsonform, \ kwargs={"username": username, "id_string":id_string}) context.mongo_api_url = reverse(main.views.api, \ kwargs={"username": username, "id_string": id_string}) context.mapbox_layer = MetaData.mapbox_layer_upload(xform) return render_to_response('map.html', context_instance=context)
def map_view(request, username, id_string): xform = XForm.objects.get(user__username=username, id_string=id_string) owner = User.objects.get(username=username) if not has_permission(xform, owner, request): return HttpResponseForbidden('Not shared.') context = RequestContext(request) context.content_user = owner context.xform = xform context.profile, created = UserProfile.objects.get_or_create(user=owner) points = ParsedInstance.objects.values('lat', 'lng', 'instance').filter( instance__user=owner, instance__xform__id_string=id_string, lat__isnull=False, lng__isnull=False) center = { 'lat': round_down_geopoint(average([p['lat'] for p in points])), 'lng': round_down_geopoint(average([p['lng'] for p in points])), } def round_down_point(p): return { 'lat': round_down_geopoint(p['lat']), 'lng': round_down_geopoint(p['lng']), 'instance': p['instance'] } context.points = json.dumps([round_down_point(p) for p in list(points)]) context.center = json.dumps(center) context.form_view = True return render_to_response('map.html', context_instance=context)
def map_view(request, username, id_string, template='map.html'): owner = get_object_or_404(User, username=username) xform = get_object_or_404(XForm, id_string=id_string, user=owner) if not has_permission(xform, owner, request): return HttpResponseForbidden(_(u'Not shared.')) context = RequestContext(request) context.content_user = owner context.xform = xform context.profile, created = UserProfile.objects.get_or_create(user=owner) points = ParsedInstance.objects.values('lat', 'lng', 'instance').filter( instance__user=owner, instance__xform__id_string=id_string, lat__isnull=False, lng__isnull=False) center = { 'lat': round_down_geopoint(average([p['lat'] for p in points])), 'lng': round_down_geopoint(average([p['lng'] for p in points])), } def round_down_point(p): return { 'lat': round_down_geopoint(p['lat']), 'lng': round_down_geopoint(p['lng']), 'instance': p['instance'] } context.center = json.dumps(center) context.form_view = True context.jsonform_url = reverse(download_jsonform, kwargs={"username": username, "id_string": id_string}) context.enketo_edit_url = reverse('edit_data', kwargs={"username": username, "id_string": id_string, "data_id": 0}) context.enketo_add_url = reverse('enter_data', kwargs={"username": username, "id_string": id_string}) context.enketo_add_with_url = reverse('add_submission_with', kwargs={"username": username, "id_string": id_string}) context.mongo_api_url = reverse('mongo_view_api', kwargs={"username": username, "id_string": id_string}) context.delete_data_url = reverse('delete_data', kwargs={"username": username, "id_string": id_string}) context.mapbox_layer = MetaData.mapbox_layer_upload(xform) audit = { "xform": xform.id_string } audit_log(Actions.FORM_MAP_VIEWED, request.user, owner, _("Requested map on '%(id_string)s'.") % {'id_string': xform.id_string}, audit, request) return render_to_response(template, context_instance=context)
def _check_map_view(self): map_url = reverse(odk_viewer.views.map_view, kwargs={ 'username': self.user.username, 'id_string': 'gps' }) response = self.client.get(map_url) # testing the response context to get a concise notification # if the lat/long values have changed. lat = str(round_down_geopoint(40.811052024364471)) lng = str(round_down_geopoint(-73.964480459690094)) expected_ll = '{"lat": "%s", "lng": "%s"}' % (lat, lng) for r in response.context: self.assertEqual(expected_ll, r.center) self.assertContains(response, expected_ll)
def _check_lat_lng(self): expected_values = [ (round_down_geopoint(40.81101715564728), round_down_geopoint(-73.96446704864502)), (round_down_geopoint(40.811086893081665), round_down_geopoint(-73.96449387073517)), ] for pi, lat_lng in zip(ParsedInstance.objects.all(), expected_values): self.assertEquals(round_down_geopoint(pi.lat), lat_lng[0]) self.assertEquals(round_down_geopoint(pi.lng), lat_lng[1])
def round_down_point(p): return {"lat": round_down_geopoint(p["lat"]), "lng": round_down_geopoint(p["lng"]), "instance": p["instance"]}
def round_down_point(p): return { 'lat': round_down_geopoint(p['lat']), 'lng': round_down_geopoint(p['lng']), 'instance': p['instance'] }