Exemplo n.º 1
0
 def get_context_data(self, **kwargs):
     """
     Add route polys to context.
     """
     context = super(ShuttleRoutePolyView, self).get_context_data(**kwargs)
     route_id = self.kwargs.get('route_id')
     if route_id is None:
         raise Http404()
     ucf_shuttle_api = ShuttleRouteAPI(settings.SHUTTLE_WSDL,
                                   settings.SHUTTLE_APP_CODE,
                                   settings.SHUTTLE_COST_CENTER_ID)
     route_lines = ucf_shuttle_api.get_route_poly(route_id)
     route_info = ucf_shuttle_api.get_route_info(route_id)
     context['route_lines'] = route_lines
     context['route_info'] = route_info
     return context
Exemplo n.º 2
0
 def get_context_data(self, **kwargs):
     """
     Add route polys to context.
     """
     context = super(ShuttleRoutePolyView, self).get_context_data(**kwargs)
     route_id = self.kwargs.get('route_id')
     if route_id is None:
         raise Http404()
     ucf_shuttle_api = ShuttleRouteAPI(settings.SHUTTLE_WSDL,
                                       settings.SHUTTLE_APP_CODE,
                                       settings.SHUTTLE_COST_CENTER_ID)
     route_lines = ucf_shuttle_api.get_route_poly(route_id)
     route_info = ucf_shuttle_api.get_route_info(route_id)
     context['route_lines'] = route_lines
     context['route_info'] = route_info
     return context
Exemplo n.º 3
0
def shuttle_gps(request, route_id):
    """
    Retrieve a list of shuttle gps locations and return them in json.
    """
    if not request.is_json() or route_id is None:
        raise Http404()

    json_object = {}
    ucf_shuttle_api = ShuttleRouteAPI(settings.SHUTTLE_WSDL,
                                  settings.SHUTTLE_APP_CODE,
                                  settings.SHUTTLE_COST_CENTER_ID)
    route_gps_list = ucf_shuttle_api.get_route_gps(route_id)
    json_gps_list = []
    for gps in route_gps_list:
        json_gps_list.append(gps.json())
    json_object['locations'] = json_gps_list
    return HttpResponse(json.dumps(json_object), content_type='application/json')
Exemplo n.º 4
0
def shuttle_gps(request, route_id):
    """
    Retrieve a list of shuttle gps locations and return them in json.
    """
    if not request.is_json() or route_id is None:
        raise Http404()

    json_object = {}
    ucf_shuttle_api = ShuttleRouteAPI(settings.SHUTTLE_WSDL,
                                      settings.SHUTTLE_APP_CODE,
                                      settings.SHUTTLE_COST_CENTER_ID)
    route_gps_list = ucf_shuttle_api.get_route_gps(route_id)
    json_gps_list = []
    for gps in route_gps_list:
        json_gps_list.append(gps.json())
    json_object['locations'] = json_gps_list
    return HttpResponse(json.dumps(json_object),
                        content_type='application/json')
Exemplo n.º 5
0
def get_shuttle_routes_dict(ucf_shuttle_api=None):
    """
    Get the shuttle routes
    """
    if ucf_shuttle_api is None:
        ucf_shuttle_api = ShuttleRouteAPI(settings.SHUTTLE_WSDL,
                                      settings.SHUTTLE_APP_CODE,
                                      settings.SHUTTLE_COST_CENTER_ID)
    ucf_shuttle_routes = ucf_shuttle_api.get_routes()
    route_list = []
    route_dict = {}
    for route_id, route in ucf_shuttle_routes.iteritems():
        route_list.append(route.json())

    def string_number_cmp(x, y):
        try:
            x = x['shortname']
            xsplit = x.split(' ')
            xsplit_len = len(xsplit)
            route_num = xsplit[xsplit_len - 1]
            if int(route_num) > -1 and len(route_num) == 1:
                xsplit[xsplit_len - 1] = '0'
                xsplit.append(route_num)
                x = ' '.join(xsplit)
        except ValueError:
            pass

        try:
            y = y['shortname']
            ysplit = y.split(' ')
            ysplit_len = len(ysplit)
            route_num = ysplit[ysplit_len - 1]
            if int(route_num) > -1 and len(route_num) == 1:
                ysplit[ysplit_len - 1] = '0'
                ysplit.append(route_num)
                y = ' '.join(ysplit)
        except ValueError:
            pass

        return cmp(x.lower(), y.lower())

    sorted_route_list = sorted(route_list, cmp=string_number_cmp)
    route_dict['routes'] = sorted_route_list
    return route_dict
Exemplo n.º 6
0
def get_shuttle_routes_dict(ucf_shuttle_api=None):
    """
    Get the shuttle routes
    """
    if ucf_shuttle_api is None:
        ucf_shuttle_api = ShuttleRouteAPI(settings.SHUTTLE_WSDL,
                                          settings.SHUTTLE_APP_CODE,
                                          settings.SHUTTLE_COST_CENTER_ID)
    ucf_shuttle_routes = ucf_shuttle_api.get_routes()
    route_list = []
    route_dict = {}
    for route_id, route in ucf_shuttle_routes.iteritems():
        route_list.append(route.json())

    def string_number_cmp(x, y):
        try:
            x = x['shortname']
            xsplit = x.split(' ')
            xsplit_len = len(xsplit)
            route_num = xsplit[xsplit_len - 1]
            if int(route_num) > -1 and len(route_num) == 1:
                xsplit[xsplit_len - 1] = '0'
                xsplit.append(route_num)
                x = ' '.join(xsplit)
        except ValueError:
            pass

        try:
            y = y['shortname']
            ysplit = y.split(' ')
            ysplit_len = len(ysplit)
            route_num = ysplit[ysplit_len - 1]
            if int(route_num) > -1 and len(route_num) == 1:
                ysplit[ysplit_len - 1] = '0'
                ysplit.append(route_num)
                y = ' '.join(ysplit)
        except ValueError:
            pass

        return cmp(x.lower(), y.lower())

    sorted_route_list = sorted(route_list, cmp=string_number_cmp)
    route_dict['routes'] = sorted_route_list
    return route_dict
Exemplo n.º 7
0
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))
Exemplo n.º 8
0
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))