本文整理汇总了Python中models.comment.Comment.user_id方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.user_id方法的具体用法?Python Comment.user_id怎么用?Python Comment.user_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.comment.Comment
的用法示例。
在下文中一共展示了Comment.user_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_data
# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import user_id [as 别名]
def create_data():
#create some users
facebook_id = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
rafael = User()
rafael.name = 'Rafael Goncalves'
rafael.facebook_id = facebook_id
rafael.birthday = date.today()
rafael.friends = 299
rafael.gender = 'male'
rafael.nickname = 'rafael'
rafael.email = '[email protected]'
db.session.add(rafael)
token = Token(rafael.id)
db.session.commit()
facebook_id2 = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
bola = User()
bola.name = 'Bola Domingues'
bola.facebook_id = facebook_id2
bola.birthday = date.today()
bola.friends = 532
bola.gender = 'male'
bola.nickname = 'bola'
bola.email = '[email protected]'
db.session.add(bola)
token = Token(bola.id)
db.session.commit()
facebook_id3 = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
bolovo = User()
bolovo.name = 'Doutor Bolovo'
bolovo.facebook_id = facebook_id3
bolovo.birthday = date.today()
bolovo.friends = 23
bolovo.gender = 'male'
bolovo.nickname = 'bolovo'
bolovo.email = '[email protected]'
db.session.add(bolovo)
token = Token(bolovo.id)
db.session.commit()
#create some groups
share_t = Group()
share_t.active = True
share_t.title = "Share Your Thoughts"
share_t.description = "Grupo copiado do facebook chamado share-your-thoughts"
share_t.admins.append(bola)
share_t.subscriptions.append(bola)
share_t.subscriptions.append(bolovo)
share_t.subscriptions.append(rafael)
db.session.add(share_t)
db.session.commit()
shammu = Group()
shammu.active = True
shammu.title = "Salvem as Baleias!"
shammu.description = "Grupo dedicado ao salvamento de baleias e o fechamentos de parques de entretenimento que usam animais em cativeiro para estrelar em suas atracoes"
shammu.admins.append(bola)
shammu.subscriptions.append(bolovo)
shammu.subscriptions.append(bola)
db.session.add(shammu)
db.session.commit()
share_c = Group()
share_c.active = True
share_c.title = "Share Your Career"
share_c.description = "Grupo dedicado ao compartilhamento de informacoes sobre estagios, empregos e carreiras em geral"
share_c.admins.append(bolovo)
share_c.subscriptions.append(bolovo)
share_c.subscriptions.append(rafael)
share_c.subscriptions.append(bola)
db.session.add(share_c)
db.session.commit()
#create some posts to share_t
share_t_post1 = Post('E possivel a contratacao de anoes para animar festar de criancas acima de 11 anos?', 0)
share_t_post1.group_id = bola.id
share_t_post1.user_id = share_t.id
db.session.add(share_t_post1)
db.session.commit()
share_t_post2 = Post('Algo para fazer esse fds??? Geoconda ta com nada me disseram migas!', 0)
share_t_post2.group_id = bolovo.id
share_t_post2.user_id = share_t.id
db.session.add(share_t_post2)
db.session.commit()
#create some posts to share_t
share_c_post1 = Post('[PUC][FACULDADE] Puc ou mackenzie!!!??', 0)
share_c_post1.group_id = bolovo.id
share_c_post1.user_id = share_c.id
db.session.add(share_c_post1)
db.session.commit()
share_c_post2 = Post('[EMPREGO][ENTREVISTA] Como e fazer uma entrevista no JPMorgan gente?', 0)
share_c_post2.group_id = bolovo.id
share_c_post2.user_id = share_c.id
db.session.add(share_c_post2)
db.session.commit()
#.........这里部分代码省略.........
示例2: memorial
# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import user_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)
#.........这里部分代码省略.........