本文整理汇总了Python中server.models.ssuser.SSUser.load方法的典型用法代码示例。如果您正苦于以下问题:Python SSUser.load方法的具体用法?Python SSUser.load怎么用?Python SSUser.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server.models.ssuser.SSUser
的用法示例。
在下文中一共展示了SSUser.load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import load [as 别名]
def create(cls, userId, shiftId, text, subscribe=False):
from server.models.ssuser import SSUser
from server.models.shift import Shift
from server.models.message import Message
# first try the public feed
theShift = Shift.load(core.connect("shiftspace/shared"), shiftId)
shiftAuthor = SSUser.load(core.connect(), theShift.createdBy)
theUser = SSUser.load(core.connect(), userId)
server = core.server()
# create the comment db if necessary
dbexists = True
if not theShift.hasThread():
server.create(Comment.db(shiftId))
dbexists = False
# get the db
db = core.connect(Comment.db(shiftId))
# if db just created, sync the views and subscribe shift author
if not dbexists:
Comment.by_created.sync(db)
Comment.all_subscribed.sync(db)
shiftAuthor.subscribe(theShift)
# subscribe the user making the comment
if not theUser.isSubscribed(theShift) and subscribe:
theUser.subscribe(theShift)
# create comment and comment stub
json = {
"createdBy": userId,
"shiftId": shiftId,
"shiftAuthor": theShift.createdBy,
"text": text,
}
newComment = Comment(**utils.clean(json))
newComment.store(db)
subscribers = theShift.subscribers()
# make a private copy
# TODO: need to think about the implications of a private copy here - David
newComment.copyTo(SSUser.privateDb(theUser.id))
# send each subscriber a message
if len(subscribers) > 0:
# TODO: needs to be optimized with a fast join - David
for subscriber in subscribers:
if subscriber != userId:
astr = ((subscriber == theShift.createdBy) and "your") or ("%s's" % shiftAuthor.userName)
json = {
"fromId": userId,
"toId": subscriber,
"title": "%s just commented on %s shift!" % (theUser.userName, astr),
"text": "%s just commented on %s shift!" % (theUser.userName, astr),
"meta": "comment"
}
Message.create(**utils.clean(json))
# TODO: don't replicate if peer - David 11/21/09
core.replicate(Comment.db(shiftId), "shiftspace/shared")
return newComment