#routes/backend/category.py
from bottle import Bottle, redirect
from controllers.frontend.login import checkLogged

app = Bottle()

@app.route('/')
def get():
    if checkLogged.call():
        from controllers.backend.categories import get
        return get.call()
    else:
        redirect('/login')

@app.route('/', method="post")
def create():
    if checkLogged.call():
        from controllers.backend.categories import create
        return create.call()
    else:
        redirect('/login')

@app.route('/edit/<id>')
def create(id):
    if checkLogged.call():
        from controllers.backend.categories import edit
        return edit.call(id)
    else:
        redirect('/login')

@app.route('/delete/<id>')
def create(id):
    if checkLogged.call():
        from controllers.backend.categories import delete
        return delete.call(id)
    else:
        redirect('/login')

 

#controllers/backend/categories/delete.py
from bottle import redirect
from models.categorydb import deletedb

def call(id):
    deletedb.call(id)

    redirect('/admin/category')

 

#models/categorydb/deletedb.py
import setConnection,  config
from bottle import request

def call(id):
    mycol = setConnection.call("categories")

    userRole = request.get_cookie('userRole', secret=config.kdict['SECRET_KEY'])

    if(userRole == "Admin"):
        myquery = { "id": id }
        mycol.delete_one(myquery)

 

GitHub: https://github.com/Sokhavuth/khmerweb-multimedia

Vercel: https://khmerweb-multimedia.vercel.app/