#routes/backend/admin.py
from bottle import Bottle
import bottle
bottle.BaseRequest.MEMFILE_MAX = 1024 * 1024
app = Bottle()
from routes.backend import post
app.mount('/post', post.app)
from routes.backend import category
app.mount('/category', category.app)
#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')
#controllers/backend/categories/get.py
import config
from copy import deepcopy
from bottle import template
from models.categorydb import getdb
def call():
kdict = deepcopy(config.kdict)
kdict['pageTitle'] = 'ទំព័រជំពូក'
kdict['route'] = 'category'
categories, count = getdb.call(kdict['maxItemList'])
kdict['items'] = categories
kdict['count'] = count
return template('backend/admin', data=kdict)
#models/categorydb/getdb.py
import setConnection
def call(amount):
mycol = setConnection.call("categories")
categories = mycol.find().sort([("datetime", -1), ("_id", -1)]).limit(amount)
count = mycol.count_documents({})
return categories, count
<!--views/backend/category-->
<link href='/static/styles/category.css' rel='stylesheet' />
<section class='Category'>
%if 'edit' in data:
<form action='/dashboard/category' method='post'>
<a>ឈ្មោះជំពូកៈ</a><input type='text' value="{{data['item'][0]}}" name="name" required />
<a>តំណរភ្ជាប់រូបៈ</a><input type='text' value="{{data['item'][1]}}" name='link' required />
<a>ពេលបង្កើតៈ</a><input type='datetime-local' value="{{data['item'][2]}}" name='datetime' required />
<a></a><input type='submit' value='បញ្ជូន' />
<a></a><input type='hidden' value="{{data['item'][3]}}" name="editid" />
</form>
%else:
<form action='/dashboard/category' method='post'>
<a>ឈ្មោះជំពូកៈ</a><input type='text' name="name" required />
<a>តំណរភ្ជាប់រូបៈ</a><input type='text' name='link' required />
<a>ពេលបង្កើតៈ</a><input type='datetime-local' name='datetime' required />
<a></a><input type='submit' value='បញ្ជូន' />
</form>
%end
</section>
/*asset/css/category.css*/
.Category{
background: var(--foreground);
}
.Category form{
display: grid;
grid-template-columns: 20% 50%;
grid-gap: 5px;
align-items: center;
margin: 20px auto;
}
.Category form a{
text-align: right;
}
.Category form input{
font: var(--body-font);
padding: 2px 5px;
}