#routes/admin/category.py
from bottle import Bottle,redirect
from controllers.login import checkLogged
app = Bottle()
@app.route('/')
def getCategory():
if checkLogged.call():
from controllers.admin.categories import read
return read.call()
else:
redirect('/login')
@app.route('/',method='post')
def postCategory():
if checkLogged.call():
from controllers.admin.categories import create
return create.call()
else:
redirect('/login')
#controllers/admin/categories/create.py
import config
from copy import deepcopy
from bottle import redirect,request
from models.categories import create
def call():
userRole = request.get_cookie('userRole', secret=config.kdict['SECRET_KEY'])
if(userRole == 'Admin'):
create.call()
redirect('/admin/category')
#models/categories/create.py
import uuid
from models import setDBconnection
from bottle import request
def call():
id = uuid.uuid4().hex
category = {
'id': id,
'title': request.forms.getunicode('title'),
'thumb': request.forms.getunicode('thumb'),
'date': request.forms.getunicode('datetime')
}
doc_ref = setDBconnection.db.collection('categories').document(id)
doc_ref.set(category)
Vercel: https://khmerweb-vlog.vercel.app