#controllers/frontend/login/get.py
import config
from copy import deepcopy
from bottle import template
from models.postdb import getdb

def call():
    kdict = deepcopy(config.kdict)
    kdict['pageTitle'] = 'ទំព័រ​ការផ្សាយ'
    kdict['route'] = 'post'
    posts, count = getdb.call(kdict['maxItemList'])
    kdict['items'] = posts
    kdict['count'] = count

    return template('backend/admin', data=kdict)

 

#models/postdb/getdb.py
import setConnection

def call(amount):
    mycol = setConnection.call("posts")

    posts = mycol.find().sort([("datetime", -1), ("_id", -1)]).limit(amount)
    count = mycol.count_documents({})

    return posts, count

 

<!--views/dashboard/admin.tpl-->
% rebase('base.tpl')

<link href="/static/styles/partials/header.css" rel="stylesheet"></link>
<script src="/static/scripts/paginate.js"></script>
<section class='Head'>
    <header class='region'>
        <div class='site-logo'>{{ data['pageTitle'] }}</div>

        <form action='/backend/search' method='post'>
            <select name="select">
                <option>ការផ្សាយ</option>
                <option>ជំពូក</option>
                <option>សៀវភៅ</option>
                <option>អ្នក​ប្រើប្រាស់</option>
            </select>
            <input type='text' name="q" placeholder="Search" required />
            <input type="submit" value='បញ្ជូន'​ />
        </form>

        <div class='logout'><a href='/'>ទំព័រ​មុខ</a> | <a href='/login/logout'>ចេញ​ក្រៅ</a></div>
    </header>
</section>

<link href="/static/styles/partials/body.css" rel="stylesheet"></link>
<section class='Body region'>
    
    %include('backend/menu.tpl')

    <%
    if 'post' in data['route']:
        include('backend/post.tpl')
    elif 'category' in data['route']:
        include('dashboard/category.tpl')
    elif 'book' in data['route']:
        include('dashboard/book.tpl')
    elif 'upload' in data['route']:
        include('dashboard/upload.tpl')
    elif 'user' in data['route']:
        include('dashboard/user.tpl')
    end
    %>

</section>

<link href="/static/styles/partials/listing.css" rel="stylesheet"></link>
<section class='Listing region'>
    %if 'count' in data:
        <div class='info'>សរុប​ទាំងអស់​​មាន​ចំនួនៈ {{data['count']}}</div>
    %else:
        <div class='info'>សរុប​ទាំងអស់​​មាន​ចំនួនៈ</div>
    %end

    <div class='items'>
        %if 'items' in data:
        %for item in data['items']:
            <div class='item'>
                %if data['route'] == 'user':
                <style>
                .Listing .items .item{
                    grid-template-columns: 13% auto 20%;
                }
                .Listing .items .item .thumb{
                    border-radius: 50%;
                }
                </style>
                %end
                <a href="/{{data['route']}}/{{item['id']}}">
                    <img class='thumb' src="{{item['thumb']}}" />
                    %if item['entries']:
                    <img class='play-icon' src="/static/images/play.png" />
                </a>
               

                <div class='wrapper'>
                    <a href="/{{data['route']}}/{{item['id']}}">{{item['title']}}</a>
                    <p class='date'></p>
                    <script>
                        $('.items .item .date').html(new Date("{{item['datetime']}}").toLocaleDateString()) 
                    </script>
                </div>
                
                <div class='icon'>
                    <a href='/admin/{{data["route"]}}/edit/{{item["id"]}}'><img src='/static/images/edit.png' /></a>
                    <a href='/admin/{{data["route"]}}/delete/{{item["id"]}}'><img src='/static/images/delete.png' /></a>
                </div>
            </div>
        %end
        %end
    </div>

    <script>
        var route = "{{data['route']}}"
    </script>

    <div class='load-more'><img onclick='paginate(route)' src="/static/images/load-more.png" /></div>
</section>

 

/*asset/css/partials/listing*/
.Listing{
    margin-top: 10px;
}

.Listing .info{
    background: var(--foreground);
    padding: 5px;
    text-align: center;
    margin-bottom: 10px;
}

.Listing .items{
    display: grid;
    grid-template-columns: calc(50% - 5px) calc(50% - 5px);
    grid-gap: 10px;
}

.Listing .items .item{
    display: grid;
    grid-template-columns: 20% auto 20%;
    grid-gap: 10px;
    align-items: center;
    background: var(--foreground);
}

.Listing .items .item a{
    position: relative;
}

.Listing .items .item .play-icon{
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 30%;
}

.Listing .items .item .thumb{
    width: 100%;
    float: left;
}

.Listing .items .item .wrapper{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.Listing .items .item .icon{
    text-align: right;
    padding-right: 10px;
    visibility: hidden;
}

.Listing .items .item:hover .icon{
    visibility: visible;
}

.Listing .items .item .icon img{
    width: 35px;
}

.Listing .load-more{
    background: var(--foreground);
    margin: 10px 0;
    text-align: center;
    padding: 5px 0 0;
}

.Listing .load-more img:hover{
    opacity: .5;
    cursor: pointer;
}

 

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

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