def initial_context(self, request, key):
        
        context = super(PublicTransportView, self).initial_context(request)
        
        location = context['location']
        selected_routes = request.GET.getlist('route')
        
        if key not in getattr(self.conf, 'nearby', {}):
            raise Http404()
        
        # If service status provider is set, then include those too:
        if hasattr(self.conf, '%s_status_provider' % key):
            provider = getattr(self.conf, '%s_status_provider' % key)
            context['line_status'] = provider.get_status()
        
        type_slug, count = self.conf.nearby[key]
        et = EntityType.objects.get(slug=type_slug)
        
        favourites = filter(
            lambda e: e is not None and et in e.all_types_completion.all(),
            [f.metadata.get('entity') for f in get_favourites(request)])
        
        if selected_routes:
            
            if location:
                es = et.entities_completion.filter(
                    location__isnull=False, route__service_id__in=selected_routes)
                es = es.distinct().distance(location).order_by('distance')[:count]
            else:
                es = []
        
        else:
            
            if location:
                es = et.entities_completion.filter(location__isnull=False)
                es = es.distance(location).order_by('distance')[:count]
            else:
                es = []
        
        for e in (e for e in es if hasattr(e, 'distance')):
            distance, e.bearing = e.get_distance_and_bearing_from(location)
        
        self.augment_metadata(es, routes=selected_routes)
        
        for e in (e for e in favourites if hasattr(e, 'distance')):
            distance, e.bearing = e.get_distance_and_bearing_from(location)
        self.augment_metadata(favourites)
        
        context.update({
            'pageslug': key,
            'type': et,
            'entities': es,
            'favourites': favourites
        })
        
        # Only show routes which serve this type of thing
        routes = Route.objects.filter(stoponroute__entity__all_types_completion=et).distinct()
        route_ids = routes.values_list('service_id').distinct()
        
        context['route_ids'] = sorted(map(itemgetter(0), route_ids), key=bus_route_sorter)
        context['selected_routes'] = selected_routes
        
        return context
dataset/ETHPy150Open mollyproject/mollyproject/molly/apps/transport/views.py/PublicTransportView.initial_context/original