23:ccb4fca3d43a
Anton Shestakov <engored@ya.ru>, Fri, 11 Jan 2013 15:19:57 +0900
Added tag 0.2.1 for changeset 3a0403ab7952

next change 24:fe92472b29b7
previous change 21:8378bc5cf2c2

app.py

Permissions: -rwxr-xr-x

Other formats: Feeds:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os
from flask import Flask, g, render_template
from flask.ext.restful import Api
from CodernityDB.database_thread_safe import ThreadSafeDatabase
from fruitbar.indexes import ProjectIndex, TaskIndex
from fruitbar.crud import ResourceList, CRUDResource
DEBUG = True
DATABASE = 'db'
app = Flask(__name__)
app.config.from_object(__name__)
cdb = None
def init_db():
global cdb
db_path = os.path.join(os.path.dirname(__file__), app.config['DATABASE'])
cdb = ThreadSafeDatabase(db_path)
if cdb.exists():
cdb.open()
cdb.reindex()
else:
cdb.create()
cdb.add_index(ProjectIndex(cdb.path, 'project'))
cdb.add_index(TaskIndex(cdb.path, 'task'))
@app.before_request
def before_request():
g.db = cdb
@app.route('/')
def index():
return render_template('index.html')
class ProjectList(ResourceList):
doc_stub = {'_t': 'project'}
db_index = 'project'
class Project(CRUDResource):
safe_fields = ('name', 'color')
def delete(self, workspace, resource_id):
g.db.run('task', 'delete_for_project', workspace, resource_id)
return super(Project, self).delete(workspace, resource_id)
class TaskList(ResourceList):
doc_stub = {'_t': 'task'}
db_index = 'task'
class Task(CRUDResource):
safe_fields = ('name', 'note', 'done')
api = Api(app)
api.add_resource(ProjectList, '/<workspace>/projects/')
api.add_resource(Project, '/<workspace>/projects/<resource_id>/')
api.add_resource(TaskList, '/<workspace>/tasks/')
api.add_resource(Task, '/<workspace>/tasks/<resource_id>/')
if __name__ == '__main__':
init_db()
app.run()