예제 #1
0
def theme_delete(item_id):
    """Remove an item"""

    if request.method == "POST":
        item = db.session.query(Theme).filter_by(id=item_id).one()
        if item is not None:
            item_id = item.id
            item_theme_author = item.theme_author_id
            item_license_type = item.license_type_id

            # Update category relations and counts
            Category.remove_category_relation(item_id)

            # Update tag relations and counts
            Tag.remove_tag_relation(item_id)

            # Remove Item
            db.session.delete(item)
            db.session.commit()

            # Update theme author items count
            Theme.update_theme_author_count(item_theme_author)

            # Update license types count
            Theme.update_license_type_count(item_license_type)

            return redirect(url_for("home"))

    return render_template("theme/theme-single.html",
                           term_id=term_id,
                           item_id=item_id,
                           item=item)