def get_user_list(req, page, num=10, keys=None): if page: page = int(page) else: page = 1 index = (page - 1) * num if keys: where = ' and (username like "%%' + keys + '%%" or n.shoujihao="' + keys + '") ' sql = '''select a.id, username, a.created, regip, a.status, a.utype from ww_member a, ww_member_normal n where (a.id=n.id) and a.site_id=%s %s order by a.created desc limit %s,%s''' % ( fun.get_site_id(req), where, index, num) # print sql r = unio().fetchAll(sql) if r and len(r) > 0: return r where = ' and (username like "%%' + keys + '%%" or v.lianxifangshi="' + keys + '") ' sql = '''select a.id, username, a.created, regip, a.status, a.utype from ww_member a, ww_member_vip v where (a.id=v.id) and a.site_id=%s %s order by a.created desc limit %s,%s''' % ( fun.get_site_id(req), where, index, num) # print sql return unio().fetchAll(sql) else: where = ' and 1=1 ' sql = '''select a.id, username, a.created, regip, a.status, a.utype from ww_member a where a.site_id=%s %s order by a.created desc limit %s,%s''' % ( fun.get_site_id(req), where, index, num) # print sql return unio().fetchAll(sql)
def get_comment_list(req, page=1, num=10): index = (int(page) - 1) * num sql = '''select id, comment, user_name, submit_date from django_comments where is_removed=0 and site_id=%s order by submit_date desc limit %s,%s''' % ( fun.get_site_id(req), index, num) return unio().fetchAll(sql)
def get_post_list(req, page=1, num=10): index = (int(page)-1)*num sql = '''select post.id, post.title, post.short_url, post.status, post.content, post.views, post.cate2, post.status, post.created, cate.title as cate from blog_blogpost post, blog_blogpost_categories blog_cate, blog_blogcategory cate where post.site_id=%s and post.id=blog_cate.blogpost_id and blog_cate.blogcategory_id=cate.id order by post.created desc limit %s,%s''' % (fun.get_site_id(req), index, num) # print sql return unio().fetchAll(sql)
def get_post_list(req, page=1, num=10): index = (int(page) - 1) * num sql = '''select post.id, post.title, post.short_url, post.status, post.content, post.views, post.cate2, post.status, post.created, cate.title as cate from blog_blogpost post, blog_blogpost_categories blog_cate, blog_blogcategory cate where post.site_id=%s and post.id=blog_cate.blogpost_id and blog_cate.blogcategory_id=cate.id order by post.created desc limit %s,%s''' % (fun.get_site_id(req), index, num) # print sql return unio().fetchAll(sql)
def get_gbook_list(req, page, num=10): if page: page = int(page) else: page = 1 index = (page - 1) * num sql = '''select id, name, tel, created from ww_gbook where site_id=%s limit %s,%s''' % ( fun.get_site_id(req), index, num) # print sql return unio().fetchAll(sql)
def save_post(req, data, uid, uname): print data id = data.get('id', 0) views = data.get('views', 0) if not views: views = 0 featured_image = data.get('featured_image', '') if not featured_image.strip(): featured_image = '/static/zhiyuw/cy_images/images/infor.jpg' desc = data.get('description', '') if not desc: result, number = re.subn(r'<.*?>|</.*?>', '', data.get('editorValue')) desc = len(result) > 20 and result[:20] or result if id: ##update sql = '''update blog_blogpost set title='%s', content='%s', cate2='%s', featured_image='%s', description='%s',created='%s', views='%s', cate3='%s' where id=%s''' % (data.get('title'), data.get('editorValue'), data.get('cate2'), featured_image, desc, fun.now(), views, data.get('cate3', ''), id) # print sql r = unio().execute(sql) if r: sql = '''update blog_blogpost_categories set blogcategory_id=%s where blogpost_id=%s''' % (data.get('cate'), id) unio().execute(sql) return r else: short_url = '/zhiyuw/%s/show-%s.html' % ('xxx', 0) sql = '''insert into blog_blogpost (comments_count, site_id, title, slug, created, status, publish_date, short_url, content, user_id, user_name, allow_comments, views, cate2, cate3, featured_image, description) values (%s, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')''' % \ (0, fun.get_site_id(req), data.get('title', 'no title'), data.get('title','no title'), fun.now(), 1, fun.now(), short_url, data.get('editorValue'), uid, uname, 1, views, data.get('cate2'),data.get('cate3', ''), featured_image, desc) # print sql lastid = unio().executeInsert(sql) if lastid: sql = '''insert blog_blogpost_categories (blogcategory_id, blogpost_id) values ('%s', '%s')''' % (data.get('cate'), lastid) print sql r = unio().executeInsert(sql) if r: sql = '''update ww_member set credits=credits+10 where id=%s''' % uid unio().execute(sql) sql = '''select slug from blog_blogcategory where id=%s''' % data.get( 'cate') r = unio().fetchOne(sql) slug = r.get('slug') short_url = '/zhiyuw/%s/show-%s.html' % (slug, lastid) mobile_url = '/mobile/%s/show-%s.html' % (slug, lastid) sql = '''update blog_blogpost set short_url='%s', mobile_url='%s' where id=%s''' % ( short_url, mobile_url, lastid) return unio().execute(sql)
def get_user_pages(req, num=10): sql = '''select count(id) as pages from ww_member where site_id=%s''' % fun.get_site_id(req) print sql pages = unio().fetchOne(sql) if pages: count = pages['pages'] if count % num==0: return count/num else: return count/num+1 else: return 1
def get_user_list(req, page, num=10, keys=None): if page: page = int(page) else: page = 1 index = (page-1)*num where = ' and 1=1 ' if keys: where = ' and username like "%%' + keys + '%%" ' sql = '''select id, username, created, regip, status,utype from ww_member where site_id=%s %s order by created desc limit %s,%s''' % ( fun.get_site_id(req), where, index, num) print sql return unio().fetchAll(sql)
def get_user_pages(req, num=10): sql = '''select count(id) as pages from ww_member where site_id=%s''' % fun.get_site_id( req) print sql pages = unio().fetchOne(sql) if pages: count = pages['pages'] if count % num == 0: return count / num else: return count / num + 1 else: return 1
def get_post_list(req, uid, cate=None, page=1, num=10): if page<1: return [] if cate: condition = ' post.cate2="%s" and ' % cate else: condition = '' index = (int(page)-1)*num sql = '''select post.id, post.title, post.status, short_url, mobile_url, post.content, post.views, post.cate2, description, featured_image, post.created, cate.title as cate from blog_blogpost post, blog_blogpost_categories blog_cate, blog_blogcategory cate where %s post.user_id=%s and post.site_id=%s and post.id=blog_cate.blogpost_id and blog_cate.blogcategory_id=cate.id order by post.created desc limit %s,%s''' % (condition, uid, fun.get_site_id(req), index, num) # print sql return unio().fetchAll(sql)
def get_post_total(req, uid, cate=None): if cate: condition = ' post.cate2="%s" and ' % cate else: condition = '' sql = '''select count(post.title) as total from blog_blogpost post, blog_blogpost_categories cate, blog_blogcategory blog_category where %s post.status>0 and post.site_id=%s and post.user_id=%s and cate.blogcategory_id=blog_category.id and cate.blogpost_id=post.id''' % (condition, fun.get_site_id(req), uid) # print sql rt = unio().fetchOne(sql) if rt: return rt['total'] else: return 1
def get_cate3_list(req, uid, cate, page=1, num=10): if page < 1: return [] if cate: condition = ' post.cate3="%s" and ' % cate else: condition = '' index = (int(page) - 1) * num sql = '''select post.id, post.title, post.status, short_url, mobile_url, post.content, post.views, post.cate2, description, featured_image, post.created, cate.title as cate from blog_blogpost post, blog_blogpost_categories blog_cate, blog_blogcategory cate where %s post.user_id=%s and post.site_id=%s and post.id=blog_cate.blogpost_id and blog_cate.blogcategory_id=cate.id order by post.created desc limit %s,%s''' % ( condition, uid, fun.get_site_id(req), index, num) # print sql return unio().fetchAll(sql)
def save_post(req, data, uid, uname): id = data.get('id', 0) views = data.get('views') if not views: views = 0 featured_image = data.get('featured_image', '') if not featured_image.strip(): featured_image = '/static/zhiyuw/cy_images/images/infor.jpg' if id: ##update sql = '''update blog_blogpost set title='%s', content='%s', cate2='%s', featured_image='%s', description='%s',created='%s', views='%s' where id=%s''' % (data.get('title'), data.get('editorValue'), data.get('cate2'), featured_image, data.get('description', ''), fun.now(), views, id) # print sql r = unio().execute(sql) if r: sql = '''update blog_blogpost_categories set blogcategory_id=%s where blogpost_id=%s''' % (data.get('cate'), id) unio().execute(sql) return r else: short_url = '/zhiyuw/%s/show-%s.html' % ('xxx',0) sql = '''insert into blog_blogpost (comments_count, site_id, title, slug, created, status, publish_date, short_url, content, user_id, user_name, allow_comments, views, cate2, featured_image, description) values (%s, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')''' % \ (0, fun.get_site_id(req), data.get('title', 'no title'), data.get('title','no title'), fun.now(), 1, fun.now(), short_url, data.get('editorValue'), uid, uname, 1, views, data.get('cate2'), featured_image, data.get('description')) # print sql lastid = unio().executeInsert(sql) if lastid: sql = '''insert blog_blogpost_categories (blogcategory_id, blogpost_id) values ('%s', '%s')''' % (data.get('cate'), lastid) # print sql r =unio().executeInsert(sql) if r: sql = '''update ww_member set credits=credits+10 where id=%s''' % uid unio().execute(sql) sql = '''select slug from blog_blogcategory where id=%s''' % data.get('cate') r = unio().fetchOne(sql) slug = r.get('slug') short_url = '/zhiyuw/%s/show-%s.html' % (slug, lastid) mobile_url = '/mobile/%s/show-%s.html' % (slug, lastid) sql = '''update blog_blogpost set short_url='%s', mobile_url='%s' where id=%s''' %(short_url, mobile_url, lastid) return unio().execute(sql)
def get_post_total(req, uid, cate): if cate: condition = ' post.cate2="%s" and ' % cate else: condition = '' sql = '''select count(post.id) as c from blog_blogpost post, blog_blogpost_categories blog_cate, blog_blogcategory cate where %s post.user_id=%s and post.site_id=%s and post.id=blog_cate.blogpost_id and blog_cate.blogcategory_id=cate.id''' % ( condition, uid, fun.get_site_id(req)) # print sql r = unio().fetchOne(sql) if r: total = r['c'] return total else: return 0
def get_gbook_list(req, page, num=10): if page: page = int(page) else: page = 1 index = (page-1)*num sql = '''select id, name, tel, created from ww_gbook where site_id=%s limit %s,%s''' % (fun.get_site_id(req), index, num) # print sql return unio().fetchAll(sql)
def get_comment_list(req, page=1, num=10): index = (int(page)-1)*num sql = '''select id, comment, user_name, submit_date from django_comments where is_removed=0 and site_id=%s order by submit_date desc limit %s,%s''' % (fun.get_site_id(req), index, num) return unio().fetchAll(sql)