from config import * from bottle import * from entities import * from pony.orm.integration.bottle_plugin import PonyPlugin install(PonyPlugin()) ''' Server module ============= This module provides all the basic functionalities of the application. The module is a standard Bottle application and runs on port 8080. ''' ####################################################### ### Begin route declaration ####################################################### @route('/') @view('index') def index(): books = book.select() return dict(books=books) @route('/books/new') @view('new_book') def new_book(): genres = Genre.select() return dict(genre=genres)
import os import bottle from bottle import Bottle, template, static_file from pony.orm.integration.bottle_plugin import PonyPlugin from controllers import surat, letters path = os.path.abspath(__file__) dir_path = os.path.dirname(path) templates_dir = os.path.join(dir_path, 'views') if templates_dir not in bottle.TEMPLATE_PATH: bottle.TEMPLATE_PATH.insert(0, templates_dir) app = Bottle() pony_plugin = PonyPlugin() app.install(pony_plugin) def setup_route(application): application.route('/static/<filename:path>', callback=send_static) application.route('/', callback=index) application.route('/favicon.ico', 'GET', callback=favicon) application.route('/letter', 'GET', callback=letters.letter) application.route('/letter/add', ['GET', 'POST'], callback=letters.add_letter) def send_static(filename): return static_file(filename, root=os.path.join(os.path.dirname(__file__), 'static'))