#routes/frontend/index.py
import config
from bottle import Bottle, static_file

app = Bottle()

@app.route('/static/images/<filename>')
def loadImage(filename):
    return static_file(filename, root='./asset/img')

@app.route('/static/styles/<filename>')
def loadStyle(filename):
    return static_file(filename, root='./asset/css')

@app.route('/static/styles/partials/<filename>')
def loadStylePartial(filename):
    return static_file(filename, root='./asset/css/partials')

@app.route('/static/styles/highlight/styles/<filename>')
def loadHighLightStylesScript(filename):
    return static_file(filename, root='./asset/js/highlight/styles')

@app.route('/static/scripts/<filename>')
def loadScript(filename):
    return static_file(filename, root='./asset/js')

@app.route('/static/scripts/ckeditor/<filename>')
def loadCKEditorScript(filename):
    return static_file(filename, root='./asset/js/ckeditor')

@app.route('/static/fonts/<filename>')
def loadFont(filename):
    return static_file(filename, root='./asset/font')

@app.route('/static/uploads/<filename>')
def loadFont(filename):
    return static_file(filename, root='./asset/uploads')

@app.route('/')
def index():
    from controllers.frontend import front
    return front.call()

@app.route('/post/<id>')
def post(id):
    from controllers.frontend import post
    return post.call(id)

@app.route('/search', method='post')
def search():
    from controllers.frontend import search
    return search.call()

 

#controllers/frontend/search.py
import config
from copy import deepcopy
from bottle import template, request
from models.postdb import searchdb

def call():
    kdict = deepcopy(config.kdict)
    kdict['pageTitle'] = 'ទំព័រ​ស្វែង​រក'
    kdict['route'] = 'search'
    q = request.forms.getunicode('q')
    kdict['posts'] = searchdb.call(40,q)

    return template('frontend/index', data=kdict)

 

#models/postdb/searchdb.py
import setConnection

def call(amount,q):
    mycol = setConnection.call("posts")
    querry = { "title": { "$regex": q } }
    posts = mycol.find(querry).sort([("datetime", -1), ("_id", -1)]).limit(amount)
    items = [post for post in posts]

    return items

 

<!--views/frontend/search.tpl-->

<link href="/static/styles/frontend_post.css" rel="stylesheet"></link>
<link href="/static/styles/partials/front_menu.css" rel="stylesheet"></link>

<section class='Random-thumb region'>
    %if 'posts' in data:
    <div class='wrapper'>
    %for v in range(len(data['posts'])):
        <div class='thumb'>
            <a href='/post/{{data["posts"][v]["id"]}}'>
                <img src='{{data["posts"][v]["thumb"]}}' />
            </a> 
        </div>
    %end
    </div>

    <div class="reload">
        <a href='/'><img src="/static/images/left.png" /></a>
        <a href='/'><img src="/static/images/home.png" /></a>
        <a href='/'><img src="/static/images/right.png" /></a>
    </div>
    %end
</section>

 

GitHub: https://github.com/Sokhavuth/khmerweb-multimedia

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

Responsive: https://khmerweb-multimedia.vercel.app/