def get_blog(blog_id): d = DBHelper() result = d.find_one("SELECT title, content, create_time from blog where id=%s", blog_id) if result: title, content, create_time = result b = Blog(blog_id, title, content, create_time) return b
def check_user_name(user_name): if not user_name: return False, False x = DBHelper() result = x.find_one("SELECT is_admin FROM user WHERE user_name=%s", user_name) if result: is_user = True is_admin = result else: is_user = False is_admin = False return is_user, is_admin
def publish_blog(title, content): d = DBHelper() return d.insert(TABLE_NAME, ("title", "content", "is_show"), ((title, content, True),))
def get_all_blogs(): d = DBHelper() count, result = d.find("SELECT id, title, content, create_time from blog") blogs = [Blog(ID, title, content, create_time) for ID, title, content, create_time in result] return count, blogs
def create_user(user_name, password, is_admin): db = DBHelper() value = (user_name, md5(password).hexdigest(), is_admin) return db.insert("user", ("user_name", "password", "is_admin"), (value,))
def check_user(user_name, password): if not (user_name and password): return False x = DBHelper() result = x.find_one("SELECT password FROM user WHERE user_name=%s", user_name) return result and result[0] == md5(password).hexdigest()
def add_todo(text): print "todo" db = DBHelper() db.insert("todo", ("text", "status"), ((text, 1),))
def get_todo_list(): db = DBHelper() count, result = db.find("SELECT id, text, status FROM todo") return [dict(Id = Id, text = text, status = status) for Id, text, status in result]