#\controllers\register.py import config, re, json, datetime from bottle import template, route, request, redirect from models import customerdb, bicycledb, registerdb @route('/register') def displayRegister(): config.kargs['registers'] = json.dumps(registerdb.select()) return template('register', data=config.kargs) @route('/registerForm') def getRegisterForm(): config.kargs['bicycles'] = json.dumps(bicycledb.select()) config.kargs['customers'] = json.dumps(customerdb.select()) return template('registerform', data=config.kargs) @route('/register', method="POST") def insertToRegister(): brand = json.loads(request.forms.get("fbikelist")) customer = json.loads(request.forms.get("fcustomerlist")) bicycledb.amountMinus(brand[0]) registerdb.insert(brand[0], customer[1], brand[1], (datetime.date.today()).strftime('%Y-%m-%d'), '1990-07-30') redirect('/register') @route('/register/returndate// ') def editReturnDate(id, bikeid): registerdb.setReturnDate((datetime.date.today()).strftime('%Y-%m-%d'), id) bicycledb.amountPlus(bikeid) redirect('/register')
#\models\registerdb.py import sqlite3 def insert(*register): conn = sqlite3.connect('sqlite.db') cursor = conn.cursor() sql ='''CREATE TABLE IF NOT EXISTS REGISTER( ID INT, CUSTOMER TEXT, BRAND TEXT, RENTDATE DATE, RETURNDATE DATE ) ''' cursor.execute(sql) cursor.execute("INSERT INTO REGISTER VALUES (?, ?, ?, ?, ?)", register) conn.commit() conn.close() def select(): conn = sqlite3.connect('sqlite.db') cursor = conn.cursor() sql ='''CREATE TABLE IF NOT EXISTS REGISTER( ID INT, CUSTOMER TEXT, BRAND TEXT, RENTDATE DATE, RETURNDATE DATE ) ''' cursor.execute(sql) cursor.execute("SELECT ROWID, * from REGISTER") registers = cursor.fetchall() conn.commit() conn.close() return registers
<!--\views\register.tpl--> %include("./partials/header.tpl") <div class="main" id="main"> <div class="content" id="content"> <div class="top-widget"> <span>REGISTERS</span><input onclick="location.href='/registerForm'" type="button" value="Add Register" /> </div> <div id="table"></div> <script> $( document ).ready(function() { bicycle.showRegister({{!data['registers']}}); }); </script> </div><!--content--> </div><!--main--> %include("./partials/footer")
showRegister(registers,){ var html = ''; if(registers.length > 0){ html += "<table>"; html += "<tr>"; for(var k in {id:1, customer:1, bicycle:1, 'Rental Date':1, 'Return Date':1}){ html += "<th>" + k.toUpperCase() + "</th>"; } html += "<th>OPTION</th>"; html += "</tr>"; for(var i=0; i<registers.length; i++){ html += "<tr>"; html += "<td>" + (i+1) + "</td>"; for(var j in registers[i]){ if(j > 1){ if(j == 5){ if(registers[i][j] == "1990-07-30") html += `<td class='return-date'><a href='/register/returndate/${registers[i][0]}/${registers[i][1]}'><img src='/static/images/return.png' /></a></td>`; else html += "<td class='return-date'>" + registers[i][j] + "</td>"; }else{ html += "<td>" + registers[i][j] + "</td>"; } } } html += `<td class="option"><a href="/register/delete/${registers[i][0]}" class="delete" >Delete</a></td>`; html += "</tr>"; } html += "</table>"; } document.getElementById("table").innerHTML = html; }
GitHub: https://github.com/Sokhavuth/Rental-Bicycle-App
Heroku: https://khmerweb-rba.herokuapp.com/