本文整理汇总了Python中server.models.ssuser.SSUser.publicDb方法的典型用法代码示例。如果您正苦于以下问题:Python SSUser.publicDb方法的具体用法?Python SSUser.publicDb怎么用?Python SSUser.publicDb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server.models.ssuser.SSUser
的用法示例。
在下文中一共展示了SSUser.publicDb方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import publicDb [as 别名]
def update(self, fields, updateDbs=True):
from server.models.ssuser import SSUser
if fields.get("content"):
self.content = fields.get("content")
if fields.get("summary"):
self.summary = self.content["summary"] = fields.get("summary")
if fields.get("broken"):
self.broken = fields.get("broken")
if fields.get("dbs"):
self.dbs = list(set(self.dbs.extend(fields.get("dbs"))))
self.modified = datetime.now()
# update the correct user db
if self.publishData.private:
db = SSUser.privateDb(self.createdBy)
else:
db = SSUser.publicDb(self.createdBy)
self.store(core.connect(db))
core.replicate(db, "shiftspace/shared")
# update followers and groups
if updateDbs:
for db in self.publishData.dbs:
dbtype, dbid = db.split("/")
if dbtype == "group":
from server.models.group import Group
Group.read(dbid).updateShift(self)
return Shift.joinData(self, self.createdBy)
示例2: delete
# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import publicDb [as 别名]
def delete(self):
from server.models.ssuser import SSUser
db = core.connect(SSUser.privateDb(self.createdBy))
if db.get(self.id):
del db[self.id]
else:
db = core.connect(SSUser.publicDb(self.createdBy))
if db.get(self.id):
del db[self.id]
core.replicate(db.name, "shiftspace/shared")
示例3: read
# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import publicDb [as 别名]
def read(cls, id, userId=None):
from server.models.ssuser import SSUser
if userId != None:
# then try the user public
db = core.connect(SSUser.publicDb(userId))
theShift = Shift.load(db, id)
if not theShift:
# then user private
db = core.connect(SSUser.privateDb(userId))
theShift = Shift.load(db, id)
else:
theShift = Shift.load(core.connect("shiftspace/shared"), id)
if theShift:
return Shift.joinData(theShift, theShift.createdBy)
示例4: testBasicPublish
# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import publicDb [as 别名]
def testBasicPublish(self):
json = shiftJson()
json["createdBy"] = self.fakemary.id
newShift = Shift.create(json)
newShift.publish({"private":False})
# should exist in user/public db
theShift = Shift.load(core.connect(SSUser.publicDb(self.fakemary.id)), newShift.id)
self.assertEqual(theShift.summary, newShift.summary)
# should exist in master/public db
theShift = Shift.load(core.connect("shiftspace/public"), newShift.id)
self.assertEqual(theShift.summary, newShift.summary)
# should exist in shiftspace/shared db
theShift = Shift.load(core.connect("shiftspace/shared"), newShift.id)
self.assertEqual(theShift.summary, newShift.summary)
# should _not_ exist in user/private db
theShift = Shift.load(core.connect(SSUser.privateDb(self.fakemary.id)), newShift.id)
self.assertEqual(theShift, None)
示例5: read
# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import publicDb [as 别名]
def read(cls, id, userId=None, proxy=False):
from server.models.ssuser import SSUser
theShift = None
# then try the user public
if userId:
db = core.connect(SSUser.publicDb(userId))
theShift = Shift.load(db, id)
if not theShift:
# then user private
db = core.connect(SSUser.privateDb(userId))
theShift = Shift.load(db, id)
else:
db = core.connect("shiftspace/public")
theShift = Shift.load(db, id)
if userId and not theShift:
theUser = SSUser.read(userId)
aShift = Shift.load(core.connect("shiftspace/shared"), id)
if theUser.canRead(aShift):
theShift = aShift
if proxy:
theShift = Shift.load(core.connect("shiftspace/shared"), id)
if theShift:
return Shift.joinData(theShift, theShift.createdBy)
示例6: publish
# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import publicDb [as 别名]
def publish(self, publishData=None):
from server.models.ssuser import SSUser
if publishData == None:
return self
db = core.connect(SSUser.privateDb(self.createdBy))
dbs = []
author = SSUser.read(self.createdBy)
oldPublishData = dict(self.items())["publishData"]
allowed = []
# get the private status
isPrivate = True
if publishData and publishData.get("private") != None:
isPrivate = publishData.get("private")
else:
isPrivate = self.isPrivate()
# get the dbs being published to
publishDbs = (publishData and publishData.get("dbs")) or []
# get the list of dbs the user is actually allowed to publish to
allowed = []
if (publishData and isPrivate and len(publishDbs) > 0):
from server.models.group import Group
allowedGroups = author.writeable()
allowed = list(set(allowedGroups).intersection(set(publishDbs)))
# upate the private setting, the shift is no longer draft
self.publishData.private = isPrivate
self.publishData.draft = False
# publish or update a copy to group/x, group/y, ...
newGroupDbs = [s for s in allowed if s.split("/")[0] == "group"]
oldGroupDbs = [s for s in oldPublishData.get("dbs") if s.split("/")[0] == "group"]
newGroupDbs = list(set(newGroupDbs).difference(set(oldGroupDbs)))
if newGroupDbs and len(newGroupDbs) > 0:
dbs.extend(list(set(newGroupDbs)))
# publish to any user we haven't published to before
newUserDbs = [s for s in publishDbs if s.split("/")[0] == "user"]
if newUserDbs and len(newUserDbs) > 0:
userDbs = list(set(newUserDbs))
dbs.extend(userDbs)
self.shareWith([s.split("/")[1] for s in userDbs])
self.publishData.dbs = dbs
# store the human readable version
targets = publishData.get("targets")
if targets:
self.publishData.targets = targets
# update/add to group dbs
self.updateInGroups(oldGroupDbs)
self.addToGroups(newGroupDbs)
# if public shift
# create in user/public, delete from user/private
# replicate shiftspace/public to shiftspace/shared
if not isPrivate:
publicdb = SSUser.publicDb(self.createdBy)
if Shift.load(core.connect(publicdb), self.id):
self.updateIn(publicdb)
else:
# TODO: copyTo should probably just be store - David
self.copyTo(publicdb)
privatedb = core.connect(SSUser.privateDb(self.createdBy))
del privatedb[self.id]
# we need to delete the private copy out of shiftspace/shared
shared = core.connect("shiftspace/shared")
del shared[self.id]
# TODO: check that we have to force it in order to have it ready for replication - David
db = core.connect(publicdb)
core.replicate(publicdb, "shiftspace/public")
core.replicate(publicdb, "shiftspace/shared")
else:
privatedb = SSUser.privateDb(self.createdBy)
self.store(core.connect(privatedb))
core.replicate(privatedb, "shiftspace/shared")
return Shift.joinData(self, self.createdBy)