def get_page(self): tag_name = self.request.GET.get("tag_name") cursor = self.request.GET.get("cursor") or None restos = Resto.find_by_tag(name=tag_name, cursor=cursor, limit=20) data = {"tag_name": tag_name, "restos": restos} data = self.update_data(data) return render_to_response(self.get_page_template(), data, RequestContext(self.request))
def get_page(self): cursor = self.request.GET.get("cursor") or None data = { "categories": Resto.CATEGORIES, "restos": Resto.find(cursor=cursor, limit=20), } data = self.update_data(data) return render_to_response(self.get_page_template(), data, RequestContext(self.request))
def create(self, submitter): if self._instance is not None: message = "Failed to create resto: this form is bound to an existing resto." raise ProgrammingError(message) if not self.is_valid(): raise InvalidFormError(self.errors) instance = Resto.create(submitter=submitter, **self.cleaned_data) instance.save() return instance
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_page(self): category_display = None for category, display in Resto.CATEGORIES: if category == self.category: category_display = display break category_display = category_display or self.category cursor = self.request.GET.get("cursor") or None restos = Resto.find_by_category(category=self.category, cursor=cursor, limit=20) data = { "categories": Resto.CATEGORIES, "category_display": category_display, "restos": restos, } data = self.update_data(data) return render_to_response(self.get_page_template(), data, RequestContext(self.request))
def create_instance(self, csv_row): name = csv_row[0].strip() category = csv_row[7].strip() if category not in self.categories: return None city = csv_row[3].strip() if city != u"巴黎": return None city = u"Paris" address = csv_row[1].strip() route = csv_row[2].strip() tel_1 = csv_row[4].strip() or None resto = Resto.create( name=name, category=category, address=address, route=route, city=city, tel_1=tel_1, submitter=self.submitter ) return resto
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