本文整理汇总了Python中models.Place类的典型用法代码示例。如果您正苦于以下问题:Python Place类的具体用法?Python Place怎么用?Python Place使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Place类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_polling_centers
def add_polling_centers(state, filename):
d = {}
with db.transaction():
for ac_code, px_code, pb_code, name in read_csv(filename):
print "adding polling center", state.id, ac_code, px_code
if (ac_code, px_code) not in d:
key = "{0}/{1}/{2}".format(state.key, ac_code, px_code)
if not db.select("places", where="type='PX' AND key=$key", vars=locals()):
pb_key = "{0}/{1}/{2}".format(state.key, ac_code, pb_code)
pb = Place.find(pb_key)
lazy_insert("places", key=key, name=name, type="PX",
code=key.split("/")[-1],
state_id=state.id,
region_id=pb.region_id,
pc_id=pb.pc_id,
ac_id=pb.ac_id,
ward_id=pb.ward_id)
d[ac_code, px_code] = 1
commit_lazy_inserts()
with db.transaction():
for ac_code, px_code, pb_code, name in read_csv(filename):
key = "{0}/{1}/{2}".format(state.key, ac_code, px_code)
px = Place.find(key)
pb_key = "{0}/{1}/{2}".format(state.key, ac_code, pb_code)
db.update("places", px_id=px.id, where="key=$pb_key", vars=locals())
示例2: home
def home():
if 'email' not in session:
return redirect(url_for('login'))
form = AddressForm()
places = []
my_coordinates = (50.45146, 30.52187) #37.4221 -122.0844
if request.method == 'POST':
if form.validate() == False:
return render_template("home.html", form=form)
else:
address = form.address.data
p = Place()
my_coordinates =p.address_to_latlng(address)
places = p.query(address)
return render_template("home.html",
form=form,
my_coordinates=my_coordinates,
places=places)
elif request.method == 'GET':
return render_template("home.html",
form=form,
my_coordinates=my_coordinates,
places=places)
return render_template("home.html")
示例3: home
def home():
if 'email' not in session:
return redirect(url_for('login'))
form = AddressForm()
places = []
my_coordinates = (37.4221, -122.0844)
if request.method == "POST":
if form.validate() == False:
return render_template("home.html", form=form)
else:
# get the address
address = form.address.data
# query for addresses nearby
p = Place()
my_coordinates = p.address_to_latlng(address)
places = p.query(address)
# return those results
return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places)
elif request.method == "GET":
return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
示例4: query
def query(request):
if request.method == 'POST':
latitude_pass = request.POST.get('lat', None)
longitude_pass = request.POST.get('long', None)
else:
latitude_pass = request.GET.get('lat', None)
longitude_pass = request.GET.get('long', None)
if latitude_pass and longitude_pass:
now = datetime.utcnow().replace(tzinfo=tz.tzutc())
# guess[0] = place name, guess[1] = place lat, guess[2] = place longitude
guess = searchPlaces(latitude_pass, longitude_pass)
places = [obj.name for obj in Place.objects.all()]
# use it from db if already exist, otherwise create a new one
if guess[0] not in places:
predict = Place(name=guess[0], latitude=guess[1], longitude=guess[2], time=now)
predict.save()
else:
predict = Place.objects.get(name=guess[0])
Track(
latitude = latitude_pass,
longitude = longitude_pass,
prediction=predict,
time=now
).save()
return HttpResponse('GET successful')
else:
return redirect('/')
示例5: home
def home():
if 'email' not in session:
return redirect(url_for('login'))
form = AddressForm()
places = []
my_coordinates = (5.3109351,-1.9924259)
if request.method == 'POST':
if form.validate() == False:
return render_template('home.html', form=form)
else:
# get the address
address = form.address.data
# query for places around it
p = Place()
my_coordinates = p.address_to_latlng(address)
places = p.query(address)
# return those results
return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places)
elif request.method == 'GET':
return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
示例6: POST
def POST(self, place):
data = json.loads(web.data())['data']
for row in data:
code = place.key + "/" + row['code']
pb = Place.find(code)
if row['ward'] and row['ward'].strip():
# Extract te group code from its name
key = place.key + "/" + row['ward'].split("-")[0].strip()
ward = Place.find(key)
if pb.ward_id != ward.id:
pb.set_ward(ward)
else:
pb.set_ward(None)
if row['px'] and row['px'].strip():
# Extract te group code from its name
key = place.key + "/" + row['px'].split("-")[0].strip()
px = Place.find(key)
if pb.px_id != px.id:
pb.set_px(px)
else:
pb.set_px(None)
web.header("content-type", "application/json")
return '{"result": "ok"}'
示例7: test_good_google_location_and_yelp
def test_good_google_location_and_yelp(self):
place = Place()
place.name = "Whole Foods"
place.location = '1240 Yale St, Santa Monica, CA 90404'
place.save()
self.assertEqual(place.yelp_id, 'hdQJrF3Fw_KrEaDywC3tyg')
self.assertEqual(len(Place.objects.all()), 1)
示例8: createentrycontinue
def createentrycontinue(request):
title = request.POST['title'].replace(" ", "_")
location = request.POST['location']
comments = request.POST['details']
p = Place(name = title, location=location, details=comments)
p.save()
return render_to_response('places/createpagecontinue.html', {"placename": p.name}, context_instance=RequestContext(request))
示例9: setUp
def setUp(self):
self.p1 = Place(name='Demon Dogs', address='944 W. Fullerton')
self.p1.save()
self.p2 = Place(name='Ace Hardware', address='1013 N. Ashland')
self.p2.save()
self.r = Restaurant(place=self.p1, serves_hot_dogs=True, serves_pizza=False)
self.r.save()
示例10: get
def get(self):
place = Place(
name='Google',
location=ndb.GeoPt(lat=1.279,lon=103.85)
)
place.put()
self.redirect('/')
示例11: save_place
def save_place( self, name, geojson ):
owner = self.auth.user.auth_id
place = Place( name=name, owner=owner, geojson=geojson )
place.put()
key = str( place.key() )
self.session['current_place'] = key
return {
'key': str( place.key() )
}
示例12: createNew
def createNew(request):
if request.method == 'POST':
payload = json.loads(request.body)
thisx, thisy = payload.get('location', None).split(',')
pnt = GEOSGeometry('POINT(%s %s)' % (thisx, thisy))
this_place = Place(name = payload.get('name', None), location = pnt)
this_place.save()
return HttpResponse('Success')
else:
return HttpResponseBadRequest('Missing POST data')
示例13: place_page
def place_page(place_id=None):
if request.method == 'POST':
p = Place.get_by_id(place_id)
# for add subscriber form
if 'email' in request.form:
email = request.form.get('email', '')
if email not in [u.email for u in User.all()]:
u = User(
email=email,
suscribed_at=datetime.datetime.now())
u.put()
else:
u = User.gql("WHERE email = '{0}'".format(email)).get()
up = UserPlace.all().filter('user =', u).filter('place =', p).get()
if up:
return "This user already exists in subscribers!"
else:
if u.places_subscribed.count() >= 4:
return "This user has maximum subscribing"
up = UserPlace(
user=u,
place=p
)
up.put()
# for add update form
elif 'update_link' in request.form and 'update_info' in request.form:
update_link = request.form.get('update_link', '')
update_info = request.form.get('update_info', '')
u = Update(
place=p,
link=update_link,
info=update_info
)
u.put()
# for add link form
elif 'link_link' in request.form and 'link_description' in request.form:
link_link = request.form.get('link_link', '')
link_description = request.form.get('link_description', '')
l = PlaceLink(
place=p,
link=link_link,
description=link_description
)
l.put()
p = Place.get_by_id(place_id)
updates = [update for update in p.place_updates.order('-added_at')]
links = [link for link in p.placelink_set.order('-added_at')]
return render_template('place.html', place=p, updates=updates, links=links)
示例14: place_delete
def place_delete(place_id, place_key_str):
try:
pkey = Place.make_key(place_id, place_key_str)
cluster_ratings = ClusterRating.get_list({'place': pkey.urlsafe()})
for cr in cluster_ratings:
ClusterRating.delete(cr.key)
user_ratings = Rating.get_list({'place': pkey.urlsafe()})
for r in user_ratings:
Rating.delete(r.key)
res = Place.delete(pkey)
except TypeError, e:
return None, str(e), 400
示例15: fillConsumingPlaces
def fillConsumingPlaces(response):
places = []
for i in response["results"]:
place = Place()
ID = i["place_id"]
place = getDetailsForID(ID, place)
place.reward = ""
pointsToSpend = random.randint(0, 100)
place.offerPoints = str(pointsToSpend)
place.offerText = "Get our special offer for " + place.offerPoints + " points"
place.placeType = "consuming"
places.append(place)
return places