本文整理汇总了Python中models.comment.Comment.memorial_id方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.memorial_id方法的具体用法?Python Comment.memorial_id怎么用?Python Comment.memorial_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.comment.Comment
的用法示例。
在下文中一共展示了Comment.memorial_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: memorial
# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import memorial_id [as 别名]
def memorial(memorial_url=None, action=None):
if memorial_url:
from models.memorial import Memorial
memorial = Memorial.get_memorial(url=memorial_url)
if memorial:
tracker.viewed_memorial(memorial)
comment = None
commented = False
updated_comment = False
if sessions.comment('has'):
commented = sessions.comment('get')
sessions.comment('del')
if memorial.user_id == g.user.id and memorial.status == 2: # i.e., just created
memorial.status = 3
db.session.commit()
memorial.is_new = True
if action is None:
pass
elif action == 'comment':
if g.user.is_anonymous():
return redirect( jinjer.url_for( 'login', _next=True, _args=True, _show=True ) )
else:
from models.comment import Comment
text = request.form.get('comment') or request.args.get('comment') or ''
edit = request.form.get('e', type=int) or request.args.get('e', type=int) or 0
parent = request.form.get('p', type=int) or request.args.get('p', type=int) or 0
if edit:
updated_comment = Comment.update(edit, memorial.id, g.user.id, text)
else:
comment = Comment(text, parent)
if comment.validate():
comment.memorial_id = memorial.id
comment.user_id = g.user.id
comment.save_new_comment()
sessions.comment( 'set', 1 if not parent else 2 )
return redirect( jinjer.memorial_url(memorial) )
elif action == 'share' and request.method == 'POST' and request.is_xhr:
sharer = g.user.name or g.user.username or g.user.email or ''
email = request.form.get('email') or ''
message = request.form.get('message') or ''
s = 'error'
m = gettext('Invalid email address.')
if email:
emails = email.split(',')
for e in emails:
mailer.share_memorial(e, sharer, memorial, message)
s = 'ok'
m = gettext('Memorial was successfully shared.')
return render(ajax=True, status=s, message=m)
elif action == 'remember':
if g.user.is_anonymous():
s = 'login'
m = jinjer.url_for( 'login', _next=True, _args=True, _show=True )
else:
tracker.remembered_memorial(memorial)
s = 'ok'
m = jinjer.format_num(memorial.remembers)
if request.is_xhr:
return render(ajax=True, status=s, message=m)
else:
return redirect( jinjer.memorial_url(memorial) )
elif action == 'like':
if g.user.is_anonymous():
s = 'login'
m = jinjer.url_for( 'login', _next=True, _args=True, _show=True )
else:
from models.comment import Comment
comment_id = request.form.get('c', type=int) or request.args.get('c', type=int) or 0
action = request.form.get('a', type=int) or request.args.get('a', type=int) or 1
comment = Comment.query.filter_by(id=comment_id).first()
if comment:
tracker.liked_comment(comment, action)
if request.is_xhr:
return render(ajax=True, status='ok', message=[ jinjer.format_num(comment.likes), jinjer.format_num(comment.dislikes) ])
else:
s = 'error'
m = ''
if request.is_xhr:
return render(ajax=True, status=s, message=m)
else:
return redirect( jinjer.memorial_url(memorial) )
elif action == 'edit' and not g.user.is_anonymous() and g.user.id == memorial.user_id:
memorial = Memorial.get_memorial(url=memorial_url, init=True) # for now we're just reselecting and initing, till we can figure out a better/more efficient way of doing this
if request.method == 'POST':
memorial = Memorial.update_memorial(request, memorial)
#.........这里部分代码省略.........