def delete_comment(cid): try: cid = int(cid) sql = "delete from comment where id = %s" db.execute(sql, (cid)) return {'err': 0} except Exception, e: print e return {'err': -1, 'err_msg': 'server error'}
def new_article(title, summary, content, html): if title is None or summary is None or content is None or html is None: return {'err': -1, 'err_msg': '标题、概要、内容都不能为空'} try: time = datetime.datetime.now() sql = "insert into article(title, publish_time, summary, content, html) values(%s, %s, %s, %s, %s)" db.execute(sql, title, time, summary, content, html) return {'err': 0} except Exception, e: print e return {'err': -1, 'err_msg': 'sever error'}
def add_comment(article_id=None, user_name=None, user_email=None, website=None, comment=None, to_cid=None, to_cname=None): sql = 'insert into comment(article_id, user_name, user_email, website, create_at, content, to_comment_id, to_comment_username)' \ 'values(%s, %s, %s, %s, %s, %s, %s, %s)' create_at = datetime.datetime.now() try: article_id = int(article_id) if article_id < 1: return {'err': -1, 'err_msg': '不存在的文章'} if to_cid: print to_cid to_cid = int(to_cid) if to_cid < 1: return {'err': -1, 'err_msg': '不存在的评论'} if to_cid=='': to_cid = None user_name = parsehtml(user_name) comment = parsehtml(comment) db.execute(sql, article_id, user_name, user_email, website, create_at, comment, to_cid, to_cname) except Exception, e: print e return {'err': -1, 'err_msg': '系统错误,请稍后再试'}