Example #1
0
 def __get_area(self):
     #TODO use within_distance is a best way, the follow is just test
     areas = Area.objects(centroid__near=self.centroid)
     if areas.count():
         return areas[0].slug
     else:
         return None
Example #2
0
def accept_place(modeladmin, request, queryset, accept_link=True):
    from places.google_places_helper import fetch_details_for_place_id
    # we listify the queryset since we're going to edit objects such that they won't appear
    # in the queryset anymore
    any_added = False
    for suggestion in list(queryset):
        place_id = suggestion.place_id
        try:
            p = Place.objects.get(place_id=place_id)
        except Place.DoesNotExist:
            any_added = True
            p = Place(place_id=place_id)

            r, photo_url, photo_attrib = fetch_details_for_place_id(place_id)
            if not r.get(
                    'rating'
            ):  # probably not meaningful place, or Google returned NOT_FOUND
                suggestion.processed = True
                suggestion.save()
                continue
            p.name = r['name']
            p.address = r['formatted_address']
            p.image_url = photo_url
            p.user_rating = r['rating']
            p.num_ratings = r['user_ratings_total']
            p.place_types = ','.join(r.get('types', []))
            p.place_url = r.get('website')
            lat, lng = r['geometry']['location']['lat'], r['geometry'][
                'location']['lng']
            p.lat = lat
            p.lng = lng
            p.image_attribution = photo_attrib
        if accept_link:
            p.gift_card_url = check_link_against_blacklist(
                suggestion.gift_card_url) or p.gift_card_url
        p.donation_url = p.donation_url or suggestion.donation_url
        p.email_contact = suggestion.email or p.email_contact
        p.save()
        suggestion.processed = True
        suggestion.save()
    if any_added:
        # Note: this is a fairly expensive operation, but should be ok to run
        # once at the end of an admin action
        Area.update_area_for_all_places()
Example #3
0
import django
import sys
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'carebackend.settings'
sys.path.append(os.path.dirname(__file__) + '/..')
django.setup()
from django.contrib.gis.measure import D
from places.models import Neighborhood, Place, Area

Area.update_area_for_all_places()
Example #4
0
def update_area(modeladmin, request, queryset):
    Area.update_area_for_places(queryset)
Example #5
0
def add_area(line):
    current_area = Area(name=line[0])
    if len(line) == 2:
        current_area.description = line[1]
    current_area.save()
    return current_area
Example #6
0
def add_area(line):
    current_area = Area(name=line[0])
    if len(line) == 2:
        current_area.description = line[1]
    current_area.save()
    return current_area
import django
import sys
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'carebackend.settings'
sys.path.append(os.path.dirname(__file__) + '/..')
django.setup()
from django.contrib.gis.measure import D
from places.models import Neighborhood, Place, Area

Area.update_area_for_places(Place.objects.all())