#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/create.py
import uuid, config
from bottle import request, redirect
from models.categorydb import createdb
def call():
name = request.forms.getunicode('name')
link = request.forms.getunicode('link')
datetime = request.forms.getunicode('datetime')
edit = request.forms.getunicode('editid')
if not edit:
id = uuid.uuid4().hex
else:
id = edit
userRole = request.get_cookie('userRole', secret=config.kdict['SECRET_KEY'])
if userRole != 'visitor':
createdb.call(name, link, datetime, id, edit)
return redirect('/admin/category')
#models/categorydb/createdb.py
import setConnection
def call(name, link, datetime, id, edit):
mycol = setConnection.call("categories")
if not edit:
category = {
"id":id,
"title":name,
"thumb":link,
"datetime":datetime
}
mycol.insert_one(category)
else:
pass