Exemple #1
0
    def get(self):
        q = Recipe.all()

        templatevalues = RequestContext(self.request, {
                'recipes' : [r for r in q if len(r.tags) == 0]
                })

        path = os.path.join(os.path.dirname(__file__), 'no_tags.html')
        self.response.out.write(template.render(path, templatevalues))
Exemple #2
0
 def get(self):
     have = []
     havenot = []
     for r in Recipe.all():
         if r.stickies.count(1) > 0: have.append(r)
         else: havenot.append(r)
     templatevalues = RequestContext(self.request, {
             'have' : have,
             'havenot' : havenot,
             })
     path = os.path.join(os.path.dirname(__file__), 'recipes_by_sticky.html')
     self.response.out.write(template.render(path, templatevalues))
Exemple #3
0
    def get(self):
        q = Recipe.all()
        recipes = [r for r in q]
        buckets,keys = bucketize(recipes, lambda x: x.title)
        templatevalues = RequestContext(self.request, {
            'recipes' : recipes,
            'buckets' : buckets,
            'keys' : keys,
            })

        path = os.path.join(os.path.dirname(__file__), 'recipes_by_title.html')
        self.response.out.write(template.render(path, templatevalues))
Exemple #4
0
    def get(self):
        section = None
        if self.request.get('section'):
            try:
                section = Section.get( self.request.get('section') )
            except BadKeyError:
                # invalid key
                self.redirect('.')
            recipes = Recipe.all().filter('section =', section).order('-inserted').fetch(page_count+1)
        else:
            recipes = Recipe.all().order('-inserted').fetch(page_count+1)

        more = True if len(recipes) > page_count else False

        vals = {
            'title'      : 'Recipe List',
            'sections'   : Section.all(),
            'section'    : section,
            'recipes'    : recipes,
            'page_count' : page_count if more else len(recipes),
            'more'       : more,
        }
        self.template( 'recipe-list.html', vals, 'admin' );
Exemple #5
0
    async def get(self):
        """Возвращает список рецептов"""
        await check_authorized(self.request)
        if not await permits(self.request, "is_active"):
            raise web.HTTPForbidden

        rq = self.request.query
        query = Recipe.all().filter(is_active=True)
        # Фильтрация
        if "hashtag" in rq:
            query = query.filter(hashtags__name=rq["hashtag"])
        if "name" in rq:
            query = query.filter(name__icontains=rq["name"])
        if "dish_type" in rq:
            with suppress(AttributeError):
                query = query.filter(
                    dish_type=getattr(DishType, rq["dish_type"]))
        if "author" in rq:
            query = query.filter(author__login=rq["author"])
        if "has_photo" in rq:
            with suppress(ValueError):
                query = query.filter(
                    final_dish_photo__isnull=not bool(int(rq["has_photo"])))

        # Сортировка
        if "order_by" in rq:
            sorts = [v for k, v in rq.items() if k == "order_by"]
            for sort in sorts:
                if sort.startswith("+"):
                    sort = sort[1:]
                with suppress(FieldError):
                    query = query.order_by(sort)

        # Пагинация
        if "offset" in rq:
            with suppress(ValueError):
                query = query.offset(int(rq["offset"]))

        limit = int(rq.get("limit", "10"))
        query = query.limit(limit)

        return web.json_response(
            [await recipe.to_dict() for recipe in await query])
Exemple #6
0
def recipe_index():
    recipes = Recipe.all()
    flash('Got all recipes')
    return render_template('recipes/index.html', recipes=recipes)