def accept_link(modeladmin, request, queryset): for suggestion in queryset: if check_link_against_blacklist(suggestion.link): pl = suggestion.place pl.gift_card_url = suggestion.link pl.save() queryset.delete()
def save(self, *args, **kwargs): from places.helper import check_link_against_blacklist if self.gift_card_url and not check_link_against_blacklist( self.gift_card_url): raise Exception("Bad Link Saved") if (self.lat and self.lng): self.geom = Point([float(x) for x in (self.lng, self.lat)], srid=4326) super(self.__class__, self).save(*args, **kwargs)
def save(self, *args, **kwargs): from places.helper import check_link_against_blacklist from places.google_places_helper import fetch_details_for_place_id if self.gift_card_url and not check_link_against_blacklist( self.gift_card_url): raise Exception("Bad Link Saved") # if self.lat and self.lng: # self.geom = Point([float(x) for x in (self.lng, self.lat)], srid=4326) r, _, _ = fetch_details_for_place_id(self.place_id) if not r: raise Exception("Failed to fetch details from google api") self.lat = r['geometry']['location']['lat'] self.lng = r['geometry']['location']['lng'] self.geom = Point(float(self.lng), float(self.lat), srid=4326) super(self.__class__, self).save(*args, **kwargs)
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()
def save(self, *args, **kwargs): from places.google_places_helper import fetch_details_for_place_id r, photo_url, photo_attrib = fetch_details_for_place_id(self.place_id) self.name = r['name'] self.address = r['formatted_address'] if r['rating']: self.user_rating = r['rating'] self.num_ratings = r['user_ratings_total'] self.place_types = ','.join(r.get('types', [])) self.place_url = r.get('website') lat, lng = r['geometry']['location']['lat'], r['geometry']['location']['lng'] self.lat = lat self.lng = lng self.image_url = photo_url self.image_attribution = photo_attrib from places.helper import check_link_against_blacklist if self.gift_card_url and not check_link_against_blacklist(self.gift_card_url): raise Exception("Bad Link Saved") if (self.lat and self.lng): self.geom = Point([float(x) for x in (self.lng, self.lat)], srid=4326) super(self.__class__, self).save(*args, **kwargs)