當前位置: 首頁>>代碼示例>>Python>>正文


Python Comment.find方法代碼示例

本文整理匯總了Python中models.Comment.find方法的典型用法代碼示例。如果您正苦於以下問題:Python Comment.find方法的具體用法?Python Comment.find怎麽用?Python Comment.find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Comment的用法示例。


在下文中一共展示了Comment.find方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: cookie2user

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def cookie2user(cookie_str):
	'''Parse cookie and load user if cookie is valid'''
	if not cookie_str:
		return None
	try:
		L = cookie_str.split('-')
		if len(L) != 3:
			return None
		uid,expires,sha1 = L
		if int(expires) < time.time():
			return None
		user = await User.find(uid)
		if user is None:
			return None
		s = '%s-%s-%s-%s' % (uid,user.passwd,expires,_COOKIE_KEY)
		if sha1 != hashlib.sha1(s.encode('utf-8')).hexdigest():
			logging.info('invalid sha1')
			return None
		user.passwd = '******'
		return user
	except Exception as e:
		logging.exception(e)
		return None 
開發者ID:syusonn,項目名稱:awesome-python3-webapp,代碼行數:25,代碼來源:handlers.py

示例2: api_edit_blog

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def api_edit_blog(request, *, id, name, summary, content):
    check_admin(request)
    if not name or not name.strip():
        raise APIValueError('name', 'name can not be empty')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary can not be empty')
    if not content or not content.strip():
        raise APIValueError('content', 'content can not be empty')
    #blog = Blog(user_id = request.__user__.id, user_name= request.__user__.name, user_image = request.__user__.image, name = name.strip(), summary = summary.strip(), content = content.strip())
    blog = yield from Blog.find(id)
    if not blog:
        raise APIValueError('id', 'request path error, id : {}'.format(id))
    blog.name = name
    blog.summary = summary
    blog.content = content
    yield from blog.update()
    return blog 
開發者ID:tianzhenyun,項目名稱:python-awesome-web,代碼行數:19,代碼來源:handlers.py

示例3: get_blog

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def get_blog(id, request):
    blog = yield from Blog.find(id)  # ??id???????????
    # ????????blog??????????????????????
    comments = yield from Comment.findAll('blog_id=?', [id], orderBy='created_at desc')
    # ?????????html??
    for c in comments:
        c.html_content = text2html(c.content)
    # blog??markdown????????html??
    blog.html_content = markdown2.markdown(blog.content)
    return {
        '__template__': 'blog.html',
        'blog': blog,
          '__user__':request.__user__,
        'comments': comments
    }


# day10???
# ??????? 
開發者ID:ReedSun,項目名稱:Preeminent,代碼行數:21,代碼來源:handlers.py

示例4: api_create_comment

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def api_create_comment(id, request, *, content):
    user = request.__user__
    # ????
    if user is None:
        raise APIPermissionError('Please signin first.')
    # ??????????
    if not content or not content.strip():
        raise APIValueError('content')
    # ????????
    blog = yield from Blog.find(id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    # ??????
    comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip())
    yield from comment.save()  # ?????????
    return comment  # ????

# day14??
# API????? 
開發者ID:ReedSun,項目名稱:Preeminent,代碼行數:21,代碼來源:handlers.py

示例5: cookie2user

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def cookie2user(cookie_str):
    '''
    Parse cookie and load user if cookie is valid.
    '''
    if not cookie_str:
        return None
    try:
        L = cookie_str.split('-')
        if len(L) != 3:
            return None
        uid, expires, sha1 = L
        if int(expires) < time.time():
            return None
        user = yield from User.find(uid)
        if user is None:
            return None
        s = '%s-%s-%s-%s' % (uid, user.passwd, expires, _COOKIE_KEY)
        if sha1 != hashlib.sha1(s.encode('utf-8')).hexdigest():
            logging.info('invalid sha1')
            return None
        user.passwd = '******'
        return user
    except Exception as e:
        logging.exception(e)
        return None 
開發者ID:xsingHu,項目名稱:xs-python-architecture,代碼行數:27,代碼來源:handlers.py

示例6: cookie2user

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def cookie2user(cookie_str):
    '''
    Parse cookie and load user if cookie is valid.
    '''
    if not cookie_str:
        return None
    try:
        L = cookie_str.split('-')
        if len(L) != 3:
            return None
        uid, expires, sha1 = L
        if int(expires) < time.time():
            return None
        user = await User.find(uid)
        if user is None:
            return None
        s = '%s-%s-%s-%s' % (uid, user.passwd, expires, _COOKIE_KEY)
        if sha1 != hashlib.sha1(s.encode('utf-8')).hexdigest():
            logging.info('invalid sha1')
            return None
        user.passwd = '******'
        return user
    except Exception as e:
        logging.exception(e)
        return None 
開發者ID:chenpengcong,項目名稱:python3-webapp,代碼行數:27,代碼來源:handlers.py

示例7: get_blog

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def get_blog(id,request):
	blog = await Blog.find(id)
	comments = await Comment.findAll('blog_id=?',[id],orderBy='created_at desc')
	for c in comments:
		c.html_content = text2html(c.content)
	blog.html_content = markdown2.markdown(blog.content)
	return	{
		'__template__' : 'blog.html',
		'blog' : blog,
		'comments' : comments,
		'__user__' : request.__user__
	}

# ???? 
開發者ID:syusonn,項目名稱:awesome-python3-webapp,代碼行數:16,代碼來源:handlers.py

示例8: api_create_comments

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def api_create_comments(id,request,*,content):
	user = request.__user__
	if user is None:
		raise APIPermissionError('Please signin first')
	if not content or not content.strip():
		raise APIValueError('content')
	blog = await Blog.find(id)
	if blog is None:
		raise APIResourceNotFoundError('Blog')
	comment = Comment(blog_id=blog.id,user_id=user.id,user_name=user.name,user_image=user.image,content=content.strip())
	await comment.save()
	return comment 
開發者ID:syusonn,項目名稱:awesome-python3-webapp,代碼行數:14,代碼來源:handlers.py

示例9: api_delete_comments

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def api_delete_comments(id,request):
	check_admin(request)
	c = await Comment.find(id)
	if c is None:
		raise APIResourceNotFoundError('Comment')
	await c.remove()
	return dict(id=id) 
開發者ID:syusonn,項目名稱:awesome-python3-webapp,代碼行數:9,代碼來源:handlers.py

示例10: api_get_blog

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def api_get_blog(*,id):
	blog = await Blog.find(id)
	return blog 
開發者ID:syusonn,項目名稱:awesome-python3-webapp,代碼行數:5,代碼來源:handlers.py

示例11: api_delete_blog

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def api_delete_blog(request,*,id):
	check_admin(request)
	blog = await Blog.find(id)
	await blog.remove()
	return dict(id=id) 
開發者ID:syusonn,項目名稱:awesome-python3-webapp,代碼行數:7,代碼來源:handlers.py

示例12: cookie2user

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def cookie2user(cookie_str):
    '''
    Parse cookie and load user if cookie is valid
    :param cookie_str:
    :return:
    '''

    if not cookie_str:
        return None
    try:
        L = cookie_str.split('-')
        if len(L) != 3:
            return None
        uid, expires, sha1 = L
        if int(expires) < time.time():
            return None
        user = yield from User.find(uid)
        if user is None:
            return None

        s = '{}-{}-{}-{}'.format(uid, user.password, expires, _COOKIE_KEY)
        if sha1 != hashlib.sha1(s.encode('utf-8')).hexdigest():
            logging.info('cookie:{} is invalid, invalid sha1')
            return None
        user.password = '*' * 8
        return user
    except Exception as e:
        logging.exception(e)
        return None 
開發者ID:tianzhenyun,項目名稱:python-awesome-web,代碼行數:31,代碼來源:handlers.py

示例13: get_blog

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def get_blog(id):
    blog = yield from Blog.find(id)
    if not blog:
        raise APIValueError('id', 'can not find blog id is :{}'.format(id))
    comments = yield from Comment.find_all('blog_id=?', [id], order_by='created_at desc')
    for c in comments:
        c.html_content = text2html(c.content)
    blog.html_content = markdown2.markdown(blog.content)
    return {
        '__template__': 'blog.html',
        'blog': blog,
        'comments': comments
    } 
開發者ID:tianzhenyun,項目名稱:python-awesome-web,代碼行數:15,代碼來源:handlers.py

示例14: api_get_blog

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def api_get_blog(*, id):
    blog = yield from Blog.find(id)
    return blog 
開發者ID:tianzhenyun,項目名稱:python-awesome-web,代碼行數:5,代碼來源:handlers.py

示例15: api_delete_blog

# 需要導入模塊: from models import Comment [as 別名]
# 或者: from models.Comment import find [as 別名]
def api_delete_blog(request, *, id):
    logging.info('delete blog id: {}'.format(id))
    check_admin(request)
    blog = yield from Blog.find(id)
    if blog:
        yield from blog.remove()
        return blog
    raise APIValueError('id', 'id can not find...') 
開發者ID:tianzhenyun,項目名稱:python-awesome-web,代碼行數:10,代碼來源:handlers.py


注:本文中的models.Comment.find方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。