def initial_context(self, request, key):
        
        context = super(RoutesView, self).initial_context(request)
        
        type_slug, count = self.conf.nearby[key]
        et = EntityType.objects.get(slug=type_slug)
        
        if key not in getattr(self.conf, 'nearby', {}):
            raise Http404()
        
        location = context['location']
        
        # Only show routes which serve this type of thing
        routes = Route.objects.filter(stoponroute__entity__all_types_completion=et).distinct()
        
        if location:
            routes = list(routes)
            for route in routes:
                route.nearest = Entity.objects.filter(route=route).distance(location).order_by('distance')[0]
                route.nearest_distance, route.nearest_bearing = route.nearest.get_distance_and_bearing_from(location)
        
        context['routes'] = sorted(routes, key=lambda x: bus_route_sorter(x.service_id))
        
        return context
dataset/ETHPy150Open mollyproject/mollyproject/molly/apps/transport/views.py/RoutesView.initial_context/original