コード例 #1
0
ファイル: views.py プロジェクト: bloomonkey/mollyproject
    def initial_context(self, request, ptypes, entity=None):
        point = get_point(request, entity)

        entity_types = tuple(get_object_or_404(EntityType, slug=t) for t in ptypes.split(';'))

        if point:
            entities = Entity.objects.filter(location__isnull = False, is_sublocation = False)
            if ptypes:
                for et in entity_types:
                    entities = entities.filter(all_types_completion=et)
            else:
                entity_types = []
            entities = entities.distance(point).order_by('distance')[:99]
        else:
            entities = []

        context = super(NearbyDetailView, self).initial_context(request, ptypes, entities)
        context.update({
            'entity_types': entity_types,
            'point': point,
            'entities': entities,
            'entity': entity,
            'exposes_user_data': entity is None, # entity is None => point is the user's location
        })
        return context
コード例 #2
0
    def initial_context(self, request, ptypes, entity=None):
        point = get_point(request, entity)

        entity_types = tuple(
            get_object_or_404(EntityType, slug=t) for t in ptypes.split(';'))

        if point:
            entities = Entity.objects.filter(location__isnull=False)
            for et in entity_types:
                entities = entities.filter(all_types_completion=et)

            entities = entities.distance(point).order_by('distance')[:99]
        else:
            entities = []

        context = super(NearbyDetailView,
                        self).initial_context(request, ptypes, entities)
        context.update({
            'entity_types': entity_types,
            'point': point,
            'entities': entities,
            'entity': entity,
            # entity is None => point is the user's location
            'exposes_user_data': entity is None,
        })
        return context
コード例 #3
0
    def handle_GET(self, request, context, entity=None):
        point = get_point(request, entity)

        if point is None:
            return self.render(request, {'entity': entity},
                               'places/entity_without_location')

        if entity:
            return_url = reverse(
                'places:entity-nearby-list',
                args=[entity.identifier_scheme, entity.identifier_value])
        else:
            return_url = reverse('places:nearby-list')

        # Get entity types to show on nearby page
        entity_types = EntityType.objects.filter(show_in_nearby_list=True)

        for et in entity_types:
            # For each et, get the entities that belong to it
            et.max_distance = humanise_distance(0)
            et.entities_found = 0
            es = et.entities_completion.filter(
                location__isnull=False, location__distance_lt=(point, D(
                    km=5))).distance(point).order_by('distance')
            for e in es:
                # Selection criteria for whether or not to count this entity
                if (e.distance.m**0.75) * (et.entities_found + 1) > 500:
                    break
                et.max_distance = humanise_distance(e.distance.m)
                et.entities_found += 1

        categorised_entity_types = defaultdict(list)
        for et in filter(lambda et: et.entities_found > 0, entity_types):
            categorised_entity_types[_(et.category.name)].append(et)
        categorised_entity_types = dict(
            (k, sorted(v, key=lambda x: x.verbose_name.lower()))
            for k, v in categorised_entity_types.items())

        context.update({
            'entity_types': categorised_entity_types,
            'entity': entity,
            'return_url': return_url,
            # entity is None => we've searched around the user's location
            'exposes_user_data': entity is None,
        })
        if entity and not entity.location:
            return self.render(request, context,
                               'places/entity_without_location')
        return self.render(request, context, 'places/nearby_list')
コード例 #4
0
ファイル: search.py プロジェクト: writefaruq/mollyproject
 def bus_service_search(self, request, query, is_single_app_search):
     routes = Route.objects.filter(service_id__iexact=query)
     stops = Entity.objects.filter(stoponroute__route__in=routes)
     location = get_point(request, None)
     if location:
         stops = stops.distance(location).order_by('distance')
     
     for stop in stops:
         result = {
             'url': stop.get_absolute_url(),
             'application': self.conf.local_name,
             'redirect_if_sole_result': True,
         }
         result.update(EntityDetailView(self.conf).get_metadata(request, stop.identifier_scheme, stop.identifier_value))
         yield result
コード例 #5
0
ファイル: views.py プロジェクト: SamFoster/mollyproject
    def handle_GET(self, request, context, entity=None):
        point = get_point(request, entity)

        if point is None:
            return self.render(request, {"entity": entity}, "places/entity_without_location")

        if entity:
            return_url = reverse("places:entity-nearby-list", args=[entity.identifier_scheme, entity.identifier_value])
        else:
            return_url = reverse("places:nearby-list")

        # Get entity types to show on nearby page
        entity_types = EntityType.objects.filter(show_in_nearby_list=True)

        for et in entity_types:
            # For each et, get the entities that belong to it
            et.max_distance = 0
            et.entities_found = 0
            es = (
                et.entities_completion.filter(location__isnull=False, location__distance_lt=(point, D(km=5)))
                .distance(point)
                .order_by("distance")
            )
            for e in es:
                # Selection criteria for whether or not to count this entity
                if (e.distance.m ** 0.75) * (et.entities_found + 1) > 500:
                    break
                et.max_distance = e.distance.m
                et.entities_found += 1

        categorised_entity_types = defaultdict(list)
        for et in filter(lambda et: et.entities_found > 0, entity_types):
            categorised_entity_types[et.category.name].append(et)
        # Need to do this other Django evalutes .items as ['items']
        categorised_entity_types = dict(categorised_entity_types.items())

        context.update(
            {
                "entity_types": categorised_entity_types,
                "entity": entity,
                "return_url": return_url,
                # entity is None => we've searched around the user's location
                "exposes_user_data": entity is None,
            }
        )
        if entity and not entity.location:
            return self.render(request, context, "places/entity_without_location")
        return self.render(request, context, "places/nearby_list")
コード例 #6
0
ファイル: views.py プロジェクト: MechanisM/mollyproject
    def handle_GET(self, request, context, entity=None):
        point = get_point(request, entity)
        
        if point is None:
            return self.render(request, { 'entity': entity },
                               'places/entity_without_location')
        
        if entity:
            return_url = reverse('places:entity-nearby-list',
                      args=[entity.identifier_scheme, entity.identifier_value])
        else:
            return_url = reverse('places:nearby-list')

        # Get entity types to show on nearby page
        entity_types = EntityType.objects.filter(show_in_nearby_list=True)
        
        for et in entity_types:
            # For each et, get the entities that belong to it
            et.max_distance = humanise_distance(0)
            et.entities_found = 0
            es = et.entities_completion.filter(location__isnull=False,
                                               location__distance_lt=(point, D(km=5))).distance(point).order_by('distance')
            for e in es:
                # Selection criteria for whether or not to count this entity
                if (e.distance.m ** 0.75) * (et.entities_found + 1) > 500:
                    break
                et.max_distance = humanise_distance(e.distance.m)
                et.entities_found += 1

        categorised_entity_types = defaultdict(list)
        for et in filter(lambda et: et.entities_found > 0, entity_types):
            categorised_entity_types[_(et.category.name)].append(et)
        categorised_entity_types = dict(
            (k, sorted(v, key=lambda x: x.verbose_name.lower()))
            for k, v in categorised_entity_types.items())

        context.update({
            'entity_types': categorised_entity_types,
            'entity': entity,
            'return_url': return_url,
            # entity is None => we've searched around the user's location
            'exposes_user_data': entity is None, 
        })
        if entity and not entity.location:
            return self.render(request, context, 'places/entity_without_location')
        return self.render(request, context, 'places/nearby_list')
コード例 #7
0
ファイル: views.py プロジェクト: bloomonkey/mollyproject
    def handle_GET(self, request, context, entity=None):
        point = get_point(request, entity)

        if entity:
            return_url = reverse('places:entity-nearby-list', args=[entity.identifier_scheme, entity.identifier_value])
        else:
            return_url = reverse('places:nearby-list')

        entity_types_map = dict((e.slug, e) for e in EntityType.objects.all())
        entity_types = tuple((name, tuple(entity_types_map[t] for t in types)) for (name, types) in self.conf.nearby_entity_types)
        flat_entity_types = set(chain(*[types for name, types in entity_types]))

        entities = Entity.objects.filter(location__isnull = False, all_types_completion__in = flat_entity_types)
        entities = entities.distance(point).order_by('distance')

        for et in flat_entity_types:
            et.max_distance = 0
            et.entities_found = 0

        for e in entities:
            for et in e.all_types_slugs:
                et = entity_types_map[et]
                if not et in flat_entity_types:
                    continue
                if (e.distance.m ** 0.75) * (et.entities_found + 1) > 500:
                    flat_entity_types.remove(et)
                    continue
                et.max_distance = e.distance
                et.entities_found += 1

            if len(flat_entity_types) == 0 or e.distance.m > 5000:
                break

        entity_types = tuple((name, tuple(t for t in types if t.entities_found>0)) for name, types in entity_types)

        context.update({
            'entity_types': entity_types,
            'entity': entity,
            'return_url': return_url,
            'exposes_user_data': entity is None, # entity is None => we've searched around the user's location
        })
        if entity and not entity.location:
            return self.render(request, context, 'places/entity_without_location')
        return self.render(request, context, 'places/nearby_list')