def allItemsJSON():
    categories = session.query(Category).all()
    catsSerialized = []
    for c in categories:
        items = session.query(Item).filter_by(category_id=c.id).all()
        catsSerialized.append(c.serialize(items))
    return jsonify(Categories=catsSerialized)
 def get_categories():
     """
     Returns all categories, with a new variable (count) that shows how
     many items are in the category
     """
     categories = session.query(Category).order_by(Category.name).all()
     for c in categories:
         c.count = session.query(Item).filter_by(category_id=c.id).count()
     return categories
 def wrapper(category_id, category, item_id):
     try:
         item = session.query(Item).filter_by(id=item_id).one()
     except:
         flash('!E!The item ID (%s) does not exist' % item_id)
         return redirect(url_for('viewCategory', category_id=category_id))
     return f(category_id, category, item_id, item)
def getUserID(email):
    """
    Returns the user id based on email address
    """
    try:
        user = session.query(User).filter_by(email=email).one()
        return user.id
    except:
        return None
 def wrapper(category_id, item_id=None):
     try:
         category = session.query(Category).filter_by(id=category_id).one()
     except:
         flash('!E!The category ID (%s) does not exist' % category_id)
         return redirect(url_for('front'))
     if item_id:
         return f(category_id, category, item_id)
     else:
         return f(category_id, category)
def clearCategory(category_id, category):
    if request.method == 'POST':
        items = session.query(Item).filter_by(category=category).all()
        for item in items:
            session.delete(item)
        session.commit()
        flash('All items in category <b>%s</b> has been deleted' %
              category.name)
        return redirect(url_for('editCategories'))
    else:
        return render_template('clearcategory.html', category=category)
def getUserInfo(user_id):
    """
    Returns the user based on user id
    """
    user = session.query(User).filter_by(id=user_id).one()
    return user
Exemple #8
0
def front():
    recent = session.query(Item).order_by(desc(Item.time)).limit(10).all()
    return render_template('front.html', recent=recent)
def editCategories():
    categories = session.query(Category).order_by(Category.name).all()
    return render_template('editcategories.html', categories=categories)
def categoryJSON(category_id, category):
    items = session.query(Item).filter_by(category_id=category_id).all()
    return jsonify(Category=category.serialize(items))