예제 #1
0
def getProduct(productID):
    """ 
    Get Product

    This api route takes a product ID from our database
    and returns the related product in json form.
    
    An example of the format can be seen below in a json schema:
    ```
    {
        'id': int,
        'product_id': int,
        'title': str,
        'desc': str,
        'details': List<str>,
        'bullets': str,
        'brand': str,
        'imgs': List<urls>, # 0th image is primary img
        'categories': List<str>,
        'old_price': int,
        'new_price': int,
    }
    ```
    
    """
    item = Item.query.filter_by(id=productID).first_or_404()  # Grab raw object
    imgs = sorted(Image.query.filter_by(item_id=item.id).all(),
                  key=lambda x: x.is_primary
                  )  # Get images for objects and put primary first
    cats = [
        Category.get(x.category_id)
        for x in Category_Item.query.filter_by(item_id=item.id).all()
    ]  # Get Categories
    brand = [
        Brand.query.get(x.brand_id)
        for x in Brand_Item.query.filter_by(item_id=item.id).all()
    ]  # get brand
    details = Details.query.filter_by(item_id=item.id).all()  # get details
    bullets = Bullets.query.filter_by(
        item_id=item.id).all()  # get bullet points

    return json.dumps({
        'id': item.id,
        'product_id': item.product_id,
        'title': item.title,
        'desc': item.desc,
        'details': details,
        'bullets': bullets,
        'brand': brand,
        'imgs': imgs,
        'categories': cats,
        'old_price': item.old_price,
        'new_price': item.new_price,
    })
예제 #2
0
파일: post.py 프로젝트: bmwant/bmwlog
def category_delete(category_id):
    try:
        category = Category.get(Category.category_id == category_id)
        try:
            category.delete_instance()
        except IntegrityError as e:
            app.flash(u'Категорія містить статті. Неможливо видалити', 'error')

        redirect('/category/add')

    except DoesNotExist:
        abort(404)
예제 #3
0
파일: post.py 프로젝트: bmwant/bmwlog
def category_delete(category_id):
    try:
        category = Category.get(Category.category_id == category_id)
        try:
            category.delete_instance()
        except IntegrityError as e:
            app.flash(u'Категорія містить статті. Неможливо видалити', 'error')

        redirect('/category/add')

    except DoesNotExist:
        abort(404)
예제 #4
0
파일: post.py 프로젝트: bmwant/bmwlog
def category_list(category_id):
    """
    List all posts in current category
    """
    try:
        category = Category.get(Category.category_id == category_id)
    except DoesNotExist:
        abort(404)
    all_posts = Post.get_posts()\
        .where(Post.category == category_id).order_by(Post.date_posted.desc())
    template = env.get_template('post/list.html')
    return template.render(posts=all_posts,
                           info='Articles for category "%s"' %
                           category.category_name)
예제 #5
0
파일: post.py 프로젝트: bmwant/bmwlog
def category_list(category_id):
    """
    List all posts in current category
    """
    try:
        category = Category.get(Category.category_id == category_id)
    except DoesNotExist:
        abort(404)
    all_posts = Post.get_posts()\
        .where(Post.category == category_id).order_by(Post.date_posted.desc())
    template = env.get_template('post/list.html')
    return template.render(
        posts=all_posts,
        info=u'Статті у категорії "%s"' % category.category_name
    )