<commit_before>from __future__ import division

from itertools import chain
import simplejson, copy

from django.contrib.gis.geos import Point
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect
from django.shortcuts import get_object_or_404
from django.core.urlresolvers import reverse
from django.template.defaultfilters import capfirst

from molly.utils.views import BaseView, ZoomableView
from molly.utils.breadcrumbs import *
from molly.geolocation.views import LocationRequiredView

from molly.osm.utils import fit_to_map
from molly.osm.models import OSMUpdate

from models import Entity, EntityType
from utils import get_entity, get_point
from forms import BusstopSearchForm, UpdateOSMForm


class IndexView(BaseView):
    def get_metadata(cls, request):
        return {
            'title': 'places',
            'additional': 'Find University buildings and units, along with bus stops and local amenities',
        }

    @BreadcrumbFactory
    def breadcrumb(cls, request, context):
        return Breadcrumb(
            'places',
            None,
            'Places',
            lazy_reverse('places:index')
        )

    def initial_context(cls, request):
        return {
            'return_url': request.get_full_path(),
        }

    def handle_GET(cls, request, context):
        return cls.render(request, context, 'places/index')

class NearbyListView(LocationRequiredView):
    def get_metadata(cls, request, entity=None):
        return {
            'title': 'Find things nearby',
            'additional': 'Search for things based on your current location',
        }

    @BreadcrumbFactory
    def breadcrumb(cls, request, context, entity=None):
        return Breadcrumb(
            'places',
            lazy_parent(IndexView),
            'Things nearby',
            url = lazy_reverse('places:nearby_list'),
        )


    def handle_GET(cls, 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 if t in entity_types_map)) for (name, types) in cls.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:<commit_msg>The fix in 940a3c2 didn't work -- reverting.<commit_after>from __future__ import division

from itertools import chain
import simplejson, copy

from django.contrib.gis.geos import Point
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect
from django.shortcuts import get_object_or_404
from django.core.urlresolvers import reverse
from django.template.defaultfilters import capfirst

from molly.utils.views import BaseView, ZoomableView
from molly.utils.breadcrumbs import *
from molly.geolocation.views import LocationRequiredView

from molly.osm.utils import fit_to_map
from molly.osm.models import OSMUpdate

from models import Entity, EntityType
from utils import get_entity, get_point
from forms import BusstopSearchForm, UpdateOSMForm


class IndexView(BaseView):
    def get_metadata(cls, request):
        return {
            'title': 'places',
            'additional': 'Find University buildings and units, along with bus stops and local amenities',
        }

    @BreadcrumbFactory
    def breadcrumb(cls, request, context):
        return Breadcrumb(
            'places',
            None,
            'Places',
            lazy_reverse('places:index')
        )

    def initial_context(cls, request):
        return {
            'return_url': request.get_full_path(),
        }

    def handle_GET(cls, request, context):
        return cls.render(request, context, 'places/index')

class NearbyListView(LocationRequiredView):
    def get_metadata(cls, request, entity=None):
        return {
            'title': 'Find things nearby',
            'additional': 'Search for things based on your current location',
        }

    @BreadcrumbFactory
    def breadcrumb(cls, request, context, entity=None):
        return Breadcrumb(
            'places',
            lazy_parent(IndexView),
            'Things nearby',
            url = lazy_reverse('places:nearby_list'),
        )


    def handle_GET(cls, 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 cls.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:
{'fraction_non_alphanumeric': 0.08241206030150754, 'fraction_numerical': 0.0035175879396984926, 'mean_word_length': 2.936058009228741, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6865819', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1646, 'n_words': 453}