#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')
#controllers/admin/categories/update.py
import config
from copy import deepcopy
from bottle import template
from models.categories import read,update
def call(id):
kdict = deepcopy(config.kdict)
kdict['pageTitle'] = 'ទំព័រកែប្រែជំពូក'
kdict['route'] = '/admin/category'
kdict['type'] = 'category'
kdict['item'] = update.call(id)
kdict['items'] = read.call(kdict['maxPosts'])
return template('base',data=kdict)
#models/categories/update.py
import config
def call(id):
category_ref = config.mydb.collection("categories").document(id)
doc_category = category_ref.get()
if doc_category.exists:
return doc_category.to_dict()
<!--views/admin/category.tpl-->
<link rel="stylesheet" href="/static/styles/admin/category.css" />
<form action="/admin/category" method="post">
%if 'item' in data:
<input type="text" value="{{data['item']['title']}}" name="title"
required placeholder="ឈ្មោះជំពូក" />
<input type="text" value="{{data['item']['thumb']}}" name="thumb"
required placeholder="តំណរភ្ជាប់រូបសញ្ញា" />
<input type="datetime-local" value="{{data['item']['date']}}" name="datetime" required />
<input type="submit" value="បញ្ជូន" />
%else:
<input type="text" name="title" required placeholder="ឈ្មោះជំពូក" />
<input type="text" name="thumb" required placeholder="តំណរភ្ជាប់រូបសញ្ញា" />
<input type="datetime-local" name="datetime" required />
<input type="submit" value="បញ្ជូន" />
%end
</form>
Vercel: https://khmerweb-vlog.vercel.app