1 2 3 4 5 6 7 8 9 | #\controllers\toprental.py import config, re, json from bottle import template, route, request, redirect from models import registerdb @route ( '/toprental' ) def getTopRental(): config.kargs[ 'toprentals' ] = json.dumps(registerdb.getTopRental()) return template( 'toprental' , data = config.kargs) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | def getTopRental(): conn = sqlite3.connect( 'sqlite.db' ) cursor = conn.cursor() sql = "SELECT CUSTOMER, COUNT(*) FROM REGISTER GROUP BY CUSTOMER ORDER BY COUNT(*) DESC LIMIT 10" cursor.execute(sql) customers = cursor.fetchall() sql = "SELECT BRAND, COUNT(*) FROM REGISTER GROUP BY BRAND ORDER BY COUNT(*) DESC LIMIT 10" cursor.execute(sql) brands = cursor.fetchall() conn.commit() conn.close() return (customers, brands) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <! - - \views\toprental.tpl - - > % include( "./partials/header.tpl" ) <div class = "main" id = "main" > <div class = "content" id = "content" > <div class = "top-widget" > <span>TOP RENTAL< / span> < / div> <div id = "table-customer" >< / div> <div id = "table-bicycle" >< / div> <script src = "/static/scripts/jQuery.js" >< / script> <script src = "/static/scripts/main.js" >< / script> <script> $(document).ready(function() { bicycle.showTopRental({{!data[ 'toprentals' ]}}); }); < / script> < / div><! - - content - - > < / div><! - - main - - > % include( "./partials/footer" ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | showTopRental(toptentals){ var customers = toptentals[ 0 ]; var brands = toptentals[ 1 ]; var html = ''; if (customers.length > 0 ){ html + = "<table>" ; html + = "<tr>" ; for (var k in {rate: 1 , 'top customers' : 1 }){ html + = "<th>" + k.toUpperCase() + "</th>" ; } html + = "</tr>" ; for (var i = 0 ; i<customers.length; i + + ){ html + = "<tr>" ; html + = "<td style='width:80px;text-align:center;'>" + (i + 1 ) + "</td>" ; html + = "<td>" + customers[i][ 0 ] + "</td>" ; html + = "</tr>" ; } html + = "</table>" ; } document.getElementById( "table-customer" ).innerHTML = html; if (brands.length > 0 ){ html = ''; html + = "<table>" ; html + = "<tr>" ; for (var k in {rate: 1 , 'popular bicycles' : 1 }){ html + = "<th>" + k.toUpperCase() + "</th>" ; } html + = "</tr>" ; for (var i = 0 ; i<brands.length; i + + ){ html + = "<tr>" ; html + = "<td style='width:80px;text-align:center;'>" + (i + 1 ) + "</td>" ; html + = "<td>" + brands[i][ 0 ] + "</td>" ; html + = "</tr>" ; } html + = "</table>" ; } document.getElementById( "table-bicycle" ).innerHTML = html; } |
GitHub: https://github.com/Sokhavuth/Rental-Bicycle-App
Heroku: https://khmerweb-rba.herokuapp.com/