def detail(request, id): ''' Responds with the point and related object information ''' try: point = Point.objects.get( id=id ) except: return HttpResponseRedirect(reverse('points_list')) map = MapDisplay( fields = [ point.point, ], map_options = { 'map_style':{'width':'100%', 'height':'550px',}, } ) ct = ContentType.objects.get(\ app_label = point.content_type.app_label, model = point.content_type.model) obj = ct.get_object_for_this_type(id = point.object_id) context = {'point':point, 'object':obj, 'content_type': ct, 'map':map, } return render_to_response('points/detail.html', context,\ context_instance=RequestContext(request))
def latest_for_queryset_map(queryset): ''' Show the latest point for each instance in a qs In head:: {% latest_for_queryset_media queryset %} In body:: {% latest_for_queryset_map queryset %} ''' ct = ContentType.objects.get_for_model(queryset[0]) points = [] for m in queryset: if Point.objects.filter( content_type=ct, object_id=m.id ): p = Point.objects.filter( content_type=ct, object_id=m.id )[0] points.append(p) else: continue map = MapDisplay( fields=[ p.point for p in points ], map_options = { 'map_style':{'width':'240px', 'height':'160px',}, 'layers': ['osm.mapnik','google.hybrid'], } ) return locals()
def themecampuuid(request, theme_camp_id): camp = ThemeCamp.objects.get(id=theme_camp_id) year = camp.year events = PlayaEvent.objects.filter(hosted_by_camp=camp, moderation='A') if camp.location_point: map = MapDisplay( map_options={ 'default_lat': camp.location_point.y, 'default_lon': camp.location_point.x, 'default_zoom': 17, 'layers': ['osm.bme'], 'map_style': { 'width': '400px', 'height': '400px' } }) else: map = '' return render_to_response('brc/themecamp.html', { 'year': year, 'theme_camp': camp, 'events': events, 'map': map }, context_instance=RequestContext(request))
def art_installation_uuid(request, art_installation_id): xArtInstallation = ArtInstallation.objects.get(id=art_installation_id) xyear = xArtInstallation.year events = PlayaEvent.objects.filter(located_at_art=xArtInstallation, moderation='A') if xArtInstallation.location_point: map = MapDisplay( map_options={ 'default_lat': xArtInstallation.location_point.y, 'default_lon': xArtInstallation.location_point.x, 'default_zoom': 17, 'layers': ['osm.bme'], 'map_style': { 'width': '400px', 'height': '400px' } }) else: map = '' return render_to_response('brc/art_installation.html', { 'year': xyear, 'art_installation': xArtInstallation, 'events': events, 'map': map }, context_instance=RequestContext(request))
def get_map_for_geometry(geometry, width, height): """ Returns basic MapDisplay instance for any GEOS geometry. """ return MapDisplay( fields=[geometry], options={ 'default_zoom': 11, 'map_div_style': {'width': width, 'height': height} } )
def show_latest_point_ol(model_instance): ''' Takes model instance and displays the latest point ''' ct = ContentType.objects.get_for_model(model_instance) obj_id = model_instance.id if Point.objects.filter(content_type=ct, object_id=obj_id): point = Point.objects.filter(content_type=ct, object_id=obj_id)[0] else: point = None if point: map = MapDisplay(fields=[ point.point, ], map_options={ 'map_style': { 'width': '360px', 'height': '240px', }, 'layers': ['osm.mapnik'], 'zoom': point.zoom, }) else: map = MapDisplay( map_options={ 'map_style': { 'width': '360px', 'height': '240px', }, 'layers': ['osm.mapnik'], 'zoom': 14, }) return locals()
def show_ol_map(model_instance): ''' Takes a model instance and returns display of all points html {% show_ol_map model_instance %} ''' ct = ContentType.objects.get_for_model(model_instance) obj_id = model_instance.id points = Point.objects.filter(content_type = ct, object_id=obj_id) map = MapDisplay( fields=[p.point for p in points], map_options = { 'map_style':{'width':'240px', 'height':'160px',}, 'layers': ['osm.mapnik','google.hybrid'], } ) return locals()
def list(request, app_label=None, model_name=None, id=None, ): ''' List all points (ALL, all for model instance, or all for table) I wanted to overload a view for fun so as to be more dry but all of this logic might be wetter still FIXME? ''' # FIXME, I think this could be DRYed out a bit; experimental overloading of the # view might not be the coolest thing. if not id and not model_name and not app_label: points = Point.objects.all() map = MapDisplay( fields=[p.point for p in points], map_options = { 'map_style':{'width':'100%', 'height':'550px',}, } ) context = { 'map':map,'points':points, } return render_to_response('points/all.html', context,\ context_instance=RequestContext(request)) elif id and model_name and app_label: try: ct = ContentType.objects.get(\ app_label = app_label, model = model_name) obj = ct.get_object_for_this_type( id=id ) except: return HttpResponseRedirect(reverse('points_list')) points = Point.objects.filter( content_type=ct, object_id=id ) map = MapDisplay( fields=[p.point for p in points], map_options = { 'map_style':{'width':'100%', 'height':'550px',}, } ) context = {'points':points, 'object':obj, 'content_type':ct, 'map':map, } return render_to_response('points/all.html', context,\ context_instance=RequestContext(request)) elif app_label and model_name and not id: try: ct = ContentType.objects.get(\ app_label = app_label, model = model_name) except: return HttpResponseRedirect(reverse('points_list')) points = Point.objects.filter(content_type = ct) map = MapDisplay( fields=[p.point for p in points], map_options = { 'map_style':{'width':'100%', 'height':'550px',}, } ) context = {'points':points, 'content_type':ct, 'map':map,} return render_to_response('points/all.html', context,\ context_instance=RequestContext(request)) else: return HttpResponseNotFound()