Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # the handler
- class AdminNamedLocations(BaseHandler):
- @superadmin
- def get(self):
- #nl = settings.NamedLocationMap.new_namedlocationmap(u'nyc',u'New York, NY')
- #nl.put()
- nls = settings.NamedLocationMap.all()
- nlsplus = []
- for nl in nls:
- restaurantkeys = nl.bounding_models
- if restaurantkeys:
- nl.restaurants = db.get(nl.bounding_models)
- else:
- nl.restaurants = []
- nlsplus.append(nl)
- self.render("admin_namedlocs.html",
- nls = nlsplus
- )
- # the form
- class NamedLocationForm(wtforms.Form):
- label = wtforms.fields.TextField(u'Label', description=u'e.g. "Ann Arbor"',
- validators = [wtforms.validators.Required()])
- slug = wtforms.fields.TextField(u"Slug", description=u'''Short string that
- uniquely identifies this region, e.g. "ann-arbor"''',
- validators = [wtforms.validators.Required()])
- restaurants = wtforms.fields.SelectMultipleField(label=u"Bounding Restaurants",
- description='''Restaurants that should definitely be included as part of this named location.
- Not all restaurants in the region need to be checked, just one that is
- in the center of the region and any that are out on fringes''',
- widget=MultiCheckWidget())
- r_models = sorted(restaurant_models.Restaurant.all(), key=lambda r: r.name.lower())
- restaurants.choices = [(unicode(r.key()), r.name) for r in r_models]
- def prepare_update_get(self, nl):
- self.label.data = nl.label
- self.slug.data = nl.slug
- self.restaurants.data = [str(r.key()) for r in nl.restaurants]
- return self
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement