def home(request, **kwargs): ''' Renders the main google map. One thing that seems to be working well so far, json encoding kwargs and using as js options for the map, that way other views can call home and pass whatever map options are needed ''' date = int(time()) # process show id loc_id = request.GET.get('show', None) # process search string search_query = request.GET.get('s', None) geo_placename = None geo_region = None geo_latlng = None if loc_id is None: location = kwargs.get('location', None) if location is not None: loc_id = location.id del kwargs['location'] latlng = getattr(location, 'googlemap_point') geo_placename, geo_region = get_geo_data(latlng[0], latlng[1]) geo_latlng = latlng else: try: location = MapObj.objects.get(pk=loc_id) except MapObj.DoesNotExist: pass else: latlng = location.json().get('googlemap_point') geo_placename, geo_region = get_geo_data(latlng[0], latlng[1]) geo_latlng = latlng # Filter home page locations to building, locations, and groups show = map(lambda c: ContentType.objects.get_for_model(c), (Building, Location, Group, ParkingLot, DiningLocation)) mobs = MapObj.objects.filter(content_type__in=map(lambda c: c.id, show)) points = {} for o in mobs: o = o.json() points[o['id']] = { 'name': o['name'], 'gpoint': o['googlemap_point'], 'ipoint': o['illustrated_point'], 'type': o['object_type'], } """ Google Maps API caches the KML data. In order to purge that cache, the latest MapObj (poly's) modified time is taken and appended to the end of the KML link making it unique. """ map_objs = MapObj.objects.order_by('-modified') v = str(time()) if map_objs.count(): latest_mapobj = map_objs[0] v = str(mktime(latest_mapobj.modified.timetuple())) if settings.GOOGLE_CAN_SEE_ME: buildings_kml = "%s.kml?v=%s" % (request.build_absolute_uri( reverse('locations')[:-1]), v) sidewalks_kml = "%s.kml?v=%s" % (request.build_absolute_uri( reverse('sidewalks')[:-1]), v) parking_kml = "%s.kml?v=%s" % (request.build_absolute_uri( reverse('parking')[:-1]), v) else: buildings_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('locations')[:-1], v) sidewalks_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('sidewalks')[:-1], v) parking_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('parking')[:-1], v) loc = "%s.json" % (request.build_absolute_uri(reverse('locations')[:-1])) kwargs['map'] = 'gmap' error = kwargs.get('error', None) if error: kwargs.pop('error') shuttle_info = '' try: shuttle_info = SimpleSetting.objects.get(name='shuttle_information') shuttle_info = shuttle_info.value except SimpleSetting.DoesNotExist: pass aeds_available = EmergencyAED.objects.all().count() > 0 context = { 'infobox_location_id': json.dumps(loc_id), 'geo_placename': geo_placename, 'geo_region': geo_region, 'geo_latlng': geo_latlng, 'options': json.dumps(kwargs), 'points': json.dumps(points), 'date': date, 'buildings_kml': buildings_kml, 'sidewalks_kml': sidewalks_kml, 'parking_kml': parking_kml, 'parking_json': reverse('parking') + '.json', 'dining_json': reverse('dining') + '.json', 'loc_url': loc, 'base_url': request.build_absolute_uri(reverse('home'))[:-1], 'error': error, 'shuttle_info': shuttle_info, 'aeds_available': aeds_available, 'cloud_typography': settings.CLOUD_TYPOGRAPHY_URL, 'search_query_get': search_query, # These points are not displayed on the base tempalte but they # still need to be here to be available for searching infoboxes, etc. 'base_ignore_types': json.dumps(['DiningLocation']) } return render_to_response('campus/base.djt', context, context_instance=RequestContext(request))
def location(request, loc, return_obj=False): ''' Will one day be a wrapper for all data models, searching over all locations and organizations, maybe even people too ''' location_orgs = [] try: location = MapObj.objects.get(pk=loc) location_orgs = location._orgs()['results'] except MapObj.DoesNotExist: raise Http404("Location ID <code>%s</code> could not be found" % (loc)) base_url = request.build_absolute_uri(reverse('home'))[:-1] html = location_html(location, request) location_image = location.image location = location.json(base_url=base_url) location['info'] = html if location_image != '': location['image'] = {'url': location_image.url} else: location['image'] = None # API views if request.is_json(): if settings.DEBUG: import time time.sleep(.5) response = HttpResponse(json.dumps(location)) response['Content-type'] = 'application/json' return response org = None if request.GET.get('org', None): from apps.views import get_org org = get_org(request.GET['org']) if return_obj: return location # show location profile tags = set() if location.get('id', False): tags.add('map%s' % location['id'].lower()) if location.get('abbreviation', False): tags.add('map%s' % location['abbreviation'].lower()) if location.get('number', False): tags.add('map%s' % location['number'].lower()) # find organizations related to this location via the group it belongs to location_ctype = ContentType.objects.get( app_label="campus", model=location['object_type'].lower()) location_pk = location['id'] # Find all groups this location is a member of grouped_locations = GroupedLocation.objects.filter( object_pk=location_pk, content_type=location_ctype) groups = [gl.group_set.all() for gl in grouped_locations] groups = reduce(lambda a, b: a + b, groups) # Find the union of all organizations between this group and its members def group_orgs(g): group_orgs = g._orgs()['results'] orgs = [ gl.content_object._orgs()['results'] for gl in g.locations.all() ] orgs = reduce(lambda a, b: a + b, orgs) + group_orgs return orgs # Attach org info to each group for this location groups_orgs = list() for g in groups: groups_orgs.append((g, group_orgs(g))) latlng = location.get('googlemap_point') if latlng: geo_placename, geo_region = get_geo_data(latlng[0], latlng[1]) else: geo_placename = None geo_region = None context = { 'location': location, 'loc_url': "%s.json" % reverse('location', kwargs={ 'loc': 'foo' }).replace('foo', '%s'), 'orgs': location_orgs, 'groups_orgs': groups_orgs, 'org': org, 'geo_placename': geo_placename, 'geo_region': geo_region, } return render_to_response('campus/location.djt', context, context_instance=RequestContext(request))
def home(request, **kwargs): ''' Renders the main google map. One thing that seems to be working well so far, json encoding kwargs and using as js options for the map, that way other views can call home and pass whatever map options are needed ''' date = int(time()) # process query string loc_id = request.GET.get('show', None) geo_placename = None geo_region = None geo_latlng = None if loc_id is None: location = kwargs.get('location', None) if location is not None: loc_id = location.id del kwargs['location'] latlng = getattr(location, 'googlemap_point') geo_placename, geo_region = get_geo_data(latlng[0], latlng[1]) geo_latlng = latlng else: try: location = MapObj.objects.get(pk=loc_id) except MapObj.DoesNotExist: pass else: latlng = location.json().get('googlemap_point') geo_placename, geo_region = get_geo_data(latlng[0], latlng[1]) geo_latlng = latlng if request.is_json(): campus = { "name" : "UCF Campus Map", "weather" : weather(json_request=True) } response = HttpResponse(json.dumps(campus)) response['Content-type'] = 'application/json' return response if request.is_txt(): text = u"UCF Campus Map - %s\n%s\n\n# Campus Address\n%s\n\n# Weather\n%s" % ( request.build_absolute_uri(reverse('home')), "-"*78, "4000 Central Florida Blvd. Orlando, Florida, 32816", weather(text_request=True)) response = HttpResponse(text) response['Content-type'] = 'text/plain; charset=utf-8' return response # Filter home page locations to building, locations, and groups show = map(lambda c: ContentType.objects.get_for_model(c), (Building, Location, Group, ParkingLot, DiningLocation)) mobs = MapObj.objects.filter(content_type__in=map(lambda c: c.id, show)) points = {} for o in mobs: o = o.json() points[o['id']] = { 'name' : o['name'], 'gpoint' : o['googlemap_point'], 'ipoint' : o['illustrated_point'], 'type' : o['object_type'], } """ Google Maps API caches the KML data. In order to purge that cache, the latest MapObj (poly's) modified time is taken and appended to the end of the KML link making it unique. """ map_objs = MapObj.objects.order_by('-modified') v = str(time()) if map_objs.count(): latest_mapobj = map_objs[0] v = str(mktime(latest_mapobj.modified.timetuple())) if settings.GOOGLE_CAN_SEE_ME: buildings_kml = "%s.kml?v=%s" % (request.build_absolute_uri(reverse('locations')[:-1]), v) sidewalks_kml = "%s.kml?v=%s" % (request.build_absolute_uri(reverse('sidewalks')[:-1]), v) parking_kml = "%s.kml?v=%s" % (request.build_absolute_uri(reverse('parking')[:-1]), v) else: buildings_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('locations')[:-1], v) sidewalks_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('sidewalks')[:-1], v) parking_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('parking')[:-1], v) loc = "%s.json" % reverse('location', kwargs={'loc':'foo'}) loc = loc.replace('foo', '%s') kwargs['map'] = 'gmap'; error = kwargs.get('error', None) if error: kwargs.pop('error') shuttle_info = '' try: shuttle_info = SimpleSetting.objects.get(name='shuttle_information') shuttle_info = shuttle_info.value except SimpleSetting.DoesNotExist: pass ucf_shuttle_api = ShuttleRouteAPI(settings.SHUTTLE_WSDL, settings.SHUTTLE_APP_CODE, settings.SHUTTLE_COST_CENTER_ID) shuttle_stops = ucf_shuttle_api.get_all_shuttle_stops_dict() shuttle_stops = sorted(shuttle_stops, key=lambda k: k['name']) context = { 'infobox_location_id': json.dumps(loc_id), 'geo_placename' : geo_placename, 'geo_region' : geo_region, 'geo_latlng' : geo_latlng, 'options' : json.dumps(kwargs), 'points' : json.dumps(points), 'date' : date, 'buildings_kml' : buildings_kml, 'sidewalks_kml' : sidewalks_kml, 'parking_kml' : parking_kml, 'parking_json' : reverse('parking') + '.json', 'dining_json' : reverse('dining') + '.json', 'loc_url' : loc, 'base_url' : request.build_absolute_uri(reverse('home'))[:-1], 'error' : error, 'shuttle_routes' : json.dumps(get_shuttle_routes_dict(ucf_shuttle_api)), 'shuttle_stops' : json.dumps(shuttle_stops), 'shuttle_info' : shuttle_info, # These points are not displayed on the base tempalte but they # still need to be here to be available for searching infoboxes, etc. 'base_ignore_types' : json.dumps(['DiningLocation']) } return render_to_response('campus/base.djt', context, context_instance=RequestContext(request))
def location(request, loc, return_obj=False): ''' Will one day be a wrapper for all data models, searching over all locations and organizations, maybe even people too ''' location_orgs = [] try: location = MapObj.objects.get(pk=loc) location_orgs = location._orgs()['results'] except MapObj.DoesNotExist: raise Http404("Location ID <code>%s</code> could not be found" % (loc)) base_url = request.build_absolute_uri(reverse('home'))[:-1] html = location_html(location, request) location_image = location.image location = location.json(base_url=base_url) location['info'] = html if location_image != '': location['image'] = { 'url':location_image.url } else: location['image'] = None # API views if request.is_json(): if settings.DEBUG: import time time.sleep(.5) response = HttpResponse(json.dumps(location)) response['Content-type'] = 'application/json' return response org = None if request.GET.get('org', None): from apps.views import get_org org = get_org(request.GET['org']) if return_obj: return location # show location profile tags = set() if location.get('id', False): tags.add( 'map%s' % location['id'].lower() ) if location.get('abbreviation', False): tags.add( 'map%s' % location['abbreviation'].lower() ) if location.get('number', False): tags.add( 'map%s' % location['number'].lower() ) # find organizations related to this location via the group it belongs to location_ctype = ContentType.objects.get( app_label="campus", model=location['object_type'].lower() ) location_pk = location['id'] # Find all groups this location is a member of grouped_locations = GroupedLocation.objects.filter( object_pk=location_pk, content_type=location_ctype ) groups = [gl.group_set.all() for gl in grouped_locations] groups = reduce(lambda a, b: a + b, groups) # Find the union of all organizations between this group and its members def group_orgs(g): group_orgs = g._orgs()['results'] orgs = [gl.content_object._orgs()['results'] for gl in g.locations.all()] orgs = reduce(lambda a, b: a + b, orgs) + group_orgs return orgs # Attach org info to each group for this location groups_orgs = list() for g in groups: groups_orgs.append((g, group_orgs(g))) latlng = location.get('googlemap_point') if latlng: geo_placename, geo_region = get_geo_data(latlng[0], latlng[1]) else: geo_placename = None geo_region = None context = { 'location' : location, 'loc_url' : "%s.json" % reverse('location', kwargs={'loc':'foo'}).replace('foo', '%s'), 'orgs' : location_orgs, 'groups_orgs' : groups_orgs, 'org' : org, 'geo_placename' : geo_placename, 'geo_region' : geo_region, } return render_to_response('campus/location.djt', context, context_instance=RequestContext(request))
def home(request, **kwargs): ''' Renders the main google map. One thing that seems to be working well so far, json encoding kwargs and using as js options for the map, that way other views can call home and pass whatever map options are needed ''' date = int(time()) # process show id loc_id = request.GET.get('show', None) # process search string search_query = request.GET.get('s', None) geo_placename = None geo_region = None geo_latlng = None if loc_id is None: location = kwargs.get('location', None) if location is not None: loc_id = location.id del kwargs['location'] latlng = getattr(location, 'googlemap_point') geo_placename, geo_region = get_geo_data(latlng[0], latlng[1]) geo_latlng = latlng else: try: location = MapObj.objects.get(pk=loc_id) except MapObj.DoesNotExist: pass else: latlng = location.json().get('googlemap_point') geo_placename, geo_region = get_geo_data(latlng[0], latlng[1]) geo_latlng = latlng # Filter home page locations to building, locations, and groups show = map(lambda c: ContentType.objects.get_for_model(c), (Building, Location, Group, ParkingLot, DiningLocation)) mobs = MapObj.objects.filter(content_type__in=map(lambda c: c.id, show)) points = {} for o in mobs: o = o.json() points[o['id']] = { 'name' : o['name'], 'gpoint' : o['googlemap_point'], 'ipoint' : o['illustrated_point'], 'type' : o['object_type'], } """ Google Maps API caches the KML data. In order to purge that cache, the latest MapObj (poly's) modified time is taken and appended to the end of the KML link making it unique. """ map_objs = MapObj.objects.order_by('-modified') v = str(time()) if map_objs.count(): latest_mapobj = map_objs[0] v = str(mktime(latest_mapobj.modified.timetuple())) if settings.GOOGLE_CAN_SEE_ME: buildings_kml = "%s.kml?v=%s" % (request.build_absolute_uri(reverse('locations')[:-1]), v) sidewalks_kml = "%s.kml?v=%s" % (request.build_absolute_uri(reverse('sidewalks')[:-1]), v) parking_kml = "%s.kml?v=%s" % (request.build_absolute_uri(reverse('parking')[:-1]), v) else: buildings_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('locations')[:-1], v) sidewalks_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('sidewalks')[:-1], v) parking_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('parking')[:-1], v) loc = "%s.json" % (request.build_absolute_uri(reverse('locations')[:-1])) kwargs['map'] = 'gmap' error = kwargs.get('error', None) if error: kwargs.pop('error') shuttle_info = '' try: shuttle_info = SimpleSetting.objects.get(name='shuttle_information') shuttle_info = shuttle_info.value except SimpleSetting.DoesNotExist: pass aeds_available = EmergencyAED.objects.all().count() > 0 context = { 'infobox_location_id': json.dumps(loc_id), 'geo_placename' : geo_placename, 'geo_region' : geo_region, 'geo_latlng' : geo_latlng, 'options' : json.dumps(kwargs), 'points' : json.dumps(points), 'date' : date, 'buildings_kml' : buildings_kml, 'sidewalks_kml' : sidewalks_kml, 'parking_kml' : parking_kml, 'parking_json' : reverse('parking') + '.json', 'dining_json' : reverse('dining') + '.json', 'loc_url' : loc, 'base_url' : request.build_absolute_uri(reverse('home'))[:-1], 'error' : error, 'shuttle_info' : shuttle_info, 'aeds_available' : aeds_available, 'cloud_typography' : settings.CLOUD_TYPOGRAPHY_URL, 'search_query_get' : search_query, # These points are not displayed on the base tempalte but they # still need to be here to be available for searching infoboxes, etc. 'base_ignore_types' : json.dumps(['DiningLocation']) } return render_to_response('campus/base.djt', context, context_instance=RequestContext(request))
def home(request, **kwargs): ''' Renders the main google map. One thing that seems to be working well so far, json encoding kwargs and using as js options for the map, that way other views can call home and pass whatever map options are needed ''' date = int(time()) # process query string loc_id = request.GET.get('show', None) geo_placename = None geo_region = None geo_latlng = None if loc_id is None: location = kwargs.get('location', None) if location is not None: loc_id = location.id del kwargs['location'] latlng = getattr(location, 'googlemap_point') geo_placename, geo_region = get_geo_data(latlng[0], latlng[1]) geo_latlng = latlng else: try: location = MapObj.objects.get(pk=loc_id) except MapObj.DoesNotExist: pass else: latlng = location.json().get('googlemap_point') geo_placename, geo_region = get_geo_data(latlng[0], latlng[1]) geo_latlng = latlng if request.is_json(): campus = { "name": "UCF Campus Map", "weather": weather(json_request=True) } response = HttpResponse(json.dumps(campus)) response['Content-type'] = 'application/json' return response if request.is_txt(): text = u"UCF Campus Map - %s\n%s\n\n# Campus Address\n%s\n\n# Weather\n%s" % ( request.build_absolute_uri(reverse('home')), "-" * 78, "4000 Central Florida Blvd. Orlando, Florida, 32816", weather(text_request=True)) response = HttpResponse(text) response['Content-type'] = 'text/plain; charset=utf-8' return response # Filter home page locations to building, locations, and groups show = map(lambda c: ContentType.objects.get_for_model(c), (Building, Location, Group, ParkingLot, DiningLocation)) mobs = MapObj.objects.filter(content_type__in=map(lambda c: c.id, show)) points = {} for o in mobs: o = o.json() points[o['id']] = { 'name': o['name'], 'gpoint': o['googlemap_point'], 'ipoint': o['illustrated_point'], 'type': o['object_type'], } """ Google Maps API caches the KML data. In order to purge that cache, the latest MapObj (poly's) modified time is taken and appended to the end of the KML link making it unique. """ map_objs = MapObj.objects.order_by('-modified') v = str(time()) if map_objs.count(): latest_mapobj = map_objs[0] v = str(mktime(latest_mapobj.modified.timetuple())) if settings.GOOGLE_CAN_SEE_ME: buildings_kml = "%s.kml?v=%s" % (request.build_absolute_uri( reverse('locations')[:-1]), v) sidewalks_kml = "%s.kml?v=%s" % (request.build_absolute_uri( reverse('sidewalks')[:-1]), v) parking_kml = "%s.kml?v=%s" % (request.build_absolute_uri( reverse('parking')[:-1]), v) else: buildings_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('locations')[:-1], v) sidewalks_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('sidewalks')[:-1], v) parking_kml = "%s%s.kml?v=%s" % (settings.GOOGLE_LOOK_HERE, reverse('parking')[:-1], v) loc = "%s.json" % reverse('location', kwargs={'loc': 'foo'}) loc = loc.replace('foo', '%s') kwargs['map'] = 'gmap' error = kwargs.get('error', None) if error: kwargs.pop('error') shuttle_info = '' try: shuttle_info = SimpleSetting.objects.get(name='shuttle_information') shuttle_info = shuttle_info.value except SimpleSetting.DoesNotExist: pass ucf_shuttle_api = ShuttleRouteAPI(settings.SHUTTLE_WSDL, settings.SHUTTLE_APP_CODE, settings.SHUTTLE_COST_CENTER_ID) shuttle_stops = ucf_shuttle_api.get_all_shuttle_stops_dict() shuttle_stops = sorted(shuttle_stops, key=lambda k: k['name']) context = { 'infobox_location_id': json.dumps(loc_id), 'geo_placename': geo_placename, 'geo_region': geo_region, 'geo_latlng': geo_latlng, 'options': json.dumps(kwargs), 'points': json.dumps(points), 'date': date, 'buildings_kml': buildings_kml, 'sidewalks_kml': sidewalks_kml, 'parking_kml': parking_kml, 'parking_json': reverse('parking') + '.json', 'dining_json': reverse('dining') + '.json', 'loc_url': loc, 'base_url': request.build_absolute_uri(reverse('home'))[:-1], 'error': error, 'shuttle_routes': json.dumps(get_shuttle_routes_dict(ucf_shuttle_api)), 'shuttle_stops': json.dumps(shuttle_stops), 'shuttle_info': shuttle_info, # These points are not displayed on the base tempalte but they # still need to be here to be available for searching infoboxes, etc. 'base_ignore_types': json.dumps(['DiningLocation']) } return render_to_response('campus/base.djt', context, context_instance=RequestContext(request))