Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. # the handler
  2. class AdminNamedLocations(BaseHandler):
  3.     @superadmin
  4.     def get(self):
  5.         #nl = settings.NamedLocationMap.new_namedlocationmap(u'nyc',u'New York, NY')
  6.         #nl.put()
  7.         nls = settings.NamedLocationMap.all()
  8.         nlsplus = []
  9.         for nl in nls:
  10.             restaurantkeys = nl.bounding_models
  11.             if restaurantkeys:
  12.                 nl.restaurants = db.get(nl.bounding_models)
  13.             else:
  14.                 nl.restaurants = []
  15.             nlsplus.append(nl)
  16.         self.render("admin_namedlocs.html",
  17.             nls = nlsplus
  18.         )
  19.  
  20. # the form
  21. class NamedLocationForm(wtforms.Form):
  22.     label = wtforms.fields.TextField(u'Label', description=u'e.g. "Ann Arbor"',
  23.         validators = [wtforms.validators.Required()])
  24.     slug  = wtforms.fields.TextField(u"Slug", description=u'''Short string that
  25.        uniquely identifies this region, e.g. "ann-arbor"''',
  26.         validators = [wtforms.validators.Required()])
  27.     restaurants = wtforms.fields.SelectMultipleField(label=u"Bounding Restaurants",
  28.         description='''Restaurants that should definitely be included as part of this named location.
  29.        Not all restaurants in the region need to be checked, just one that is
  30.        in the center of the region and any that are out on fringes''',
  31.         widget=MultiCheckWidget())
  32.  
  33.     r_models = sorted(restaurant_models.Restaurant.all(), key=lambda r: r.name.lower())
  34.     restaurants.choices = [(unicode(r.key()), r.name) for r in r_models]
  35.  
  36.     def prepare_update_get(self, nl):
  37.         self.label.data = nl.label
  38.         self.slug.data  = nl.slug
  39.         self.restaurants.data = [str(r.key()) for r in nl.restaurants]
  40.         return self
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement