示例#1
0
SQL_T_TAG = """CREATE TABLE IF NOT EXISTS tag (
    id          INTEGER PRIMARY KEY,
    name        VARCHAR(20)
)"""

SQL_T_BOOK = """CREATE TABLE IF NOT EXISTS book (
    id          INTEGER PRIMARY KEY,
    tag_id     INTEGER REFERENCES tag (id),
    title       VARCHAR(50),
    description VARCHAR(200),
    rating      INT
)"""

# Installs MacaronPlugin for working in the Bottle.
install(macaron.MacaronPlugin("books.db"))


# --- Model definitions
class Tag(macaron.Model):
    pass


class Book(macaron.Model):
    # Defines Many-To-One relationship to Tag
    tag = macaron.ManyToOne(Tag, related_name="books")
    # Rating must be set between 0 and 5.
    rating = macaron.IntegerField(min=0, max=5)


def initialize():
示例#2
0
import os

import bottle
from bottle.ext import sqlite
from bottle import HTTPError, response, request, view, static_file
from json import dumps
import macaron

BASE_DIR = "/Users/codeschool/Desktop/CodeSchool/static/"

app = bottle.Bottle()
plugin = sqlite.Plugin(dbfile='database.db')
app.install(plugin)

app.install(macaron.MacaronPlugin("database.db"))


class Skills(macaron.Model):
    title = macaron.CharField()
    description = macaron.CharField()
    url = macaron.CharField()
    image_path = macaron.CharField()


class Challenges(macaron.Model):
    title = macaron.CharField()
    description = macaron.CharField()
    image_url = macaron.CharField()
    skill = macaron.ManyToOne(Skills, related_name="skill")

示例#3
0
__author__ = 'yuyichuan'

from bottle import *

import macaron

# install MacaronPlugin instance
DB_FILE = './team.db'
install(macaron.MacaronPlugin(DB_FILE))


# Class Team definition
class TeamCla(macaron.Model):
    _table_name = "team"

    def __str__(self):
        return "[Team '%s']" % self.name


# class member definition
class MemberCla(macaron.Model):
    _table_name = "member"
    team = macaron.ManyToOne(TeamCla,
                             related_name="members",
                             ref_key="id",
                             fkey="team_id")
    age = macaron.IntegerField(min=15, max=18)

    def __str__(self):
        return "[Member '%s %s : %s']" % (self.first_name, self.last_name,
                                          self.part)
示例#4
0
from bottle import *
from users import User
import sqlite3
import hashlib
import macaron

install(macaron.MacaronPlugin("users.db"))

@route('/static/<filename:path>')
def server_static(filename):
    return static_file(filename, root='/home/clemalex/Documents/Project/bottle_login/static')

@route('/login')
def login():
	return template('templates/login_form_template')
	
@route('/register')
def login():
	return template('templates/register_form_template')
   
@route('/register', method='POST') 
def do_login():
	un = request.forms.get('username')
	pw = request.forms.get('password')
	h_pw = computeMD5hash(pw)
	User.create(username=un, password=h_pw)
	macaron.bake()
	redirect("/login")
 
@route('/login', method='POST') 
def do_login():