def get_page(self): # Find newly added restos (randomly select 4 out of 10). newly_added_restos = list(Resto.find(order_by="-update_date", limit=10)) random.shuffle(newly_added_restos) newly_added_restos = newly_added_restos[:4] # Find newly commented restos (a list of 2-tuple with resto and comment). new_comments = Comment.find_recent(ref_type=Resto.__name__, limit=4) newly_commented_restos = [] for comment in new_comments: resto = Resto.get_unique(id=int(comment.ref_pk)) if resto: newly_commented_restos.append((resto, comment)) # Render the response. data = { "categories": Resto.CATEGORIES, "newly_added_restos": newly_added_restos, "newly_commented_restos": newly_commented_restos, } data = self.update_data(data) return render_to_response(self.get_page_template(), data, RequestContext(self.request))
def get_resto(self): resto = Resto.get_unique(id=self.resto_id) if not resto: message = "searched by resto id %s." % self.resto_id raise EntityNotFoundError(Resto, message) return resto