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

app = Bottle()

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

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

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

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

 

#controllers/admin/categories/delete.py
import config
from bottle import redirect, request
from models.categories import delete

def call(id):
    userRole = request.get_cookie('userRole', secret=config.kdict['SECRET_KEY'])

    if(userRole == 'Admin'):
        delete.call(id)

    redirect('/admin/category')

 

#models/categories/delete.py
import config

def call(id):
    config.mydb.collection(u'categories').document(id).delete()
    counter_ref = config.mydb.collection('counters').document('category')
    counter_ref.update({'total': config.firestore.Increment(-1)})

 

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

GitHub: https://github.com/Sokhavuth/vlog