def check_name_email(self, user_name='', email=''): sql = "SELECT * FROM `cms_user` WHERE `user_name` = %s and `email` = %s and status=1 and deleted=0 LIMIT 1" sdb._ensure_connected() user = sdb.get(sql, user_name, email) if user: return True else: return False
def get(self, category_id): if category_id is None: raise tornado.web.HTTPError(404) sdb._ensure_connected() post = sdb.get('SELECT * FROM `cms_category` WHERE `category_id` = %s' % category_id) if post is None: raise tornado.web.HTTPError(404) return post
def get(self, category_id): if category_id is None: raise tornado.web.HTTPError(404) sdb._ensure_connected() post = sdb.get( 'SELECT * FROM `cms_category` WHERE `category_id` = %s' % category_id) if post is None: raise tornado.web.HTTPError(404) return post
def get(self, comment_id): sdb._ensure_connected() return sdb.get('SELECT * FROM `cms_comments` WHERE `comment_id` = %s' % str(comment_id))
def get_by_name_or_email(self, name, email=None): if not email: email = name sql = "SELECT * FROM `cms_user` WHERE `user_name` = \'%s\' or `email` = \'%s\' LIMIT 1" sdb._ensure_connected() return sdb.get(sql % (name, email))
def check_has_user(self): sdb._ensure_connected() return sdb.get('SELECT `user_id` FROM `cms_user` LIMIT 1')
def get(self, user_id): sdb._ensure_connected() return sdb.get( 'SELECT * FROM `cms_user` WHERE `user_id` = %s LIMIT 1' % user_id)
def get_by_name(self, archive_name=''): sdb._ensure_connected() return sdb.get( 'SELECT * FROM `cms_archive` WHERE `archive_name` = \'%s\'' % archive_name)
def get(self, link_id): sdb._ensure_connected() return sdb.get('SELECT * FROM `cms_links` WHERE `link_id` = %s' % str(link_id))
def get_post_simple(self, post_id): sql = 'SELECT `post_id`,`user_name`,`category_name`,`title`,`comment_num`,`closecomment`,`password` FROM `cms_posts` p ' \ 'inner join `cms_category` c on p.category_id=c.category_id and p.`post_id` = %s ' \ 'inner join `cms_user` u on p.user_id=u.user_id' sdb._ensure_connected() return sdb.get(sql, post_id)
def get(self, post_id): sdb._ensure_connected() return sdb.get( 'SELECT p.*,c.category_name FROM `cms_posts` as p inner join `cms_category` as c on p.category_id=c.category_id and `post_id` = %s' % str( post_id))
def get_by_category_name(self, category_name=''): sdb._ensure_connected() return sdb.get( 'SELECT * FROM `cms_category` WHERE `category_name` like \'%s\'' % category_name)
def get_tag_by_name(self, tag_name=''): sdb._ensure_connected() return sdb.get('SELECT * FROM `cms_tags` WHERE `tag_name` = \'%s\'' % tag_name)
def get(self, type_key): sdb._ensure_connected() return sdb.get('SELECT * FROM `cms_show_types` WHERE `type_key` = %s' % str(type_key))
def get_post_num_by_archive_name(self, archive_name=''): sql = 'SELECT count(*) FROM `cms_posts` p ' \ 'inner join `cms_archive_post` ap on p.`post_id` = ap.post_id ' \ 'inner join `cms_archive` a on ap.`archive_id` = a.archive_id and a.archive_name = \'%s\'' sdb._ensure_connected() return sdb.get(sql, archive_name)
def get_post_detail(self, post_id): sql = 'SELECT p.*,`user_name`,`category_name` FROM `cms_posts` p ' \ 'inner join `cms_category` c on p.category_id=c.category_id and p.`post_id` = %s ' \ 'inner join `cms_user` u on p.user_id=u.user_id' sdb._ensure_connected() return post_detail_formate(sdb.get(sql, str(post_id)))
def get(self, user_id): sdb._ensure_connected() return sdb.get('SELECT * FROM `cms_user` WHERE `user_id` = %s LIMIT 1' % user_id)
def post_detail_formate(obj): if obj: slug = slugfy(obj.title) obj.slug = slug obj.absolute_url = '%s/topic/%d/%s' % (BASE_URL, obj.id, slug) obj.shorten_url = '%s/t/%s' % (BASE_URL, obj.id) if '[/code]' in obj.content: obj.highlight = True else: obj.highlight = False obj.content = tran_content(obj.content, obj.highlight) obj.taglist = ', '.join( ["""<a href="%s/tag/%s/" rel="tag">%s</a>""" % (BASE_URL, tag, tag) for tag in obj.tags.split(',')]) obj.add_time_fn = time_from_now(int(obj.add_time)) obj.last_modified = timestamp_to_datetime(obj.edit_time) obj.keywords = obj.tags obj.description = HTML_REG.sub('', obj.content[:DESCRIPTION_CUT_WORDS]) #get prev and next obj obj.prev_obj = sdb.get('SELECT `id`,`title` FROM `cms_posts` WHERE `id` > %s LIMIT 1' % str(obj.id)) if obj.prev_obj: obj.prev_obj.slug = slugfy(obj.prev_obj.title) obj.next_obj = sdb.get( 'SELECT `id`,`title` FROM `cms_posts` WHERE `id` < %s ORDER BY `id` DESC LIMIT 1' % str(obj.id)) if obj.next_obj: obj.next_obj.slug = slugfy(obj.next_obj.title) #get relative obj base tags obj.relative = [] if obj.tags: idlist = [] getit = False for tag in obj.tags.split(','): from model.tags import Tags tagobj = Tags.get_tag_by_name(tag) if tagobj and tagobj.content: pids = tagobj.content.split(',') for pid in pids: if pid != str(obj.id) and pid not in idlist: idlist.append(pid) if len(idlist) >= RELATIVE_POST_NUM: getit = True break if getit: break # if idlist: obj.relative = sdb.query('SELECT `id`,`title` FROM `cms_posts` WHERE `id` in(%s) LIMIT %s' % ( ','.join(idlist), str(len(idlist)))) if obj.relative: for robj in obj.relative: robj.slug = slugfy(robj.title) #get comment obj.coms = [] if obj.comment_num > 0: if obj.comment_num >= EACH_PAGE_COMMENT_NUM: first_limit = EACH_PAGE_COMMENT_NUM else: first_limit = obj.comment_num from model.comments import Comments obj.coms = Comments.get_post_page_comments_by_id(obj.id, 0, first_limit) return obj
def get_by_category_name(self, category_name=''): sdb._ensure_connected() return sdb.get('SELECT * FROM `cms_category` WHERE `category_name` like \'%s\'' % category_name)
def get(self, archive_id=''): sdb._ensure_connected() return sdb.get('SELECT * FROM `cms_archive` WHERE `archive_id` = %s' % str(archive_id))