def get(self, style=None): if style is not None and len(style) > 0: # FIXME: Un-urlize the string style = re.sub(r'%20', ' ', style) style = re.sub(r'%28', '(', style) style = re.sub(r'%29', ')', style) # Find all the styles by creating a set from all beers b/c # app engine won't let us grab just this column from a table beers = __weekly_brews__(Beer.all().filter("style = ", style)).order("name") template_values = {'beers' : beers, 'search' : style} path = os.path.join(os.path.dirname(__file__), 'templates/beers.html') self.response.out.write(template.render(path, template_values)) return # Use a list to preserve ordering styles = [] tmp = __weekly_brews__(Beer.all()) for beer in tmp: styles.append(beer.style) styles = list(set(styles)) styles.sort() template_values = {'styles' : styles} path = os.path.join(os.path.dirname(__file__), 'templates/search.html') self.response.out.write(template.render(path, template_values))
def get(self): beers = __weekly_brews__(Beer.all().filter("type = ", self.type())).order("name") template_values = {'beers' : beers, 'type' : self.type()} # FIXME: This template sucks b/c it has 4 loops that are duplicates path = os.path.join(os.path.dirname(__file__), 'templates/type.html') self.response.out.write(template.render(path, template_values))
def get(self): # Have to filter name afterwards b/c datastore requires the inequality # operators to have a order FIRST if there is going to be any order # clauses at all (see datastore docs) drafts = __weekly_brews__(Beer.all().filter("type = ", "Draft")).order("name") bottles = __weekly_brews__(Beer.all().filter("type = ", "Bottle")).order("name") cans = __weekly_brews__(Beer.all().filter("type = ", "Can")).order("name") casks = __weekly_brews__(Beer.all().filter("type = ", "Cask")).order("name") beers = {} beers['drafts'] = drafts beers['bottles'] = bottles beers['cans'] = cans beers['casks'] = casks template_values = {'beers' : beers} # FIXME: This template sucks b/c it has 4 loops that are duplicates path = os.path.join(os.path.dirname(__file__), 'templates/index.html') self.response.out.write(template.render(path, template_values))
def post(self, name): name = self.request.get('name') if name is None or not len(name): self.redirect("/search") return beers = __weekly_brews__(Beer.all().filter("name = ", name)) template_values = {'beers' : beers} path = os.path.join(os.path.dirname(__file__), 'templates/beers.html') self.response.out.write(template.render(path, template_values))