当前位置: 首页>>代码示例>>Python>>正文


Python SSUser.privateDb方法代码示例

本文整理汇总了Python中server.models.ssuser.SSUser.privateDb方法的典型用法代码示例。如果您正苦于以下问题:Python SSUser.privateDb方法的具体用法?Python SSUser.privateDb怎么用?Python SSUser.privateDb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在server.models.ssuser.SSUser的用法示例。


在下文中一共展示了SSUser.privateDb方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [as 别名]
 def create(cls, shiftJson):
     from server.models.ssuser import SSUser
     newShift = Shift(**utils.clean(shiftJson))
     createdBy = newShift.createdBy
     db = core.connect(SSUser.privateDb(createdBy))
     newShift.domain = utils.domain(newShift.href)
     newShift.store(db)
     core.replicate(SSUser.privateDb(createdBy), "shiftspace/shared")
     return Shift.joinData(newShift, newShift.createdBy)
开发者ID:gmatters,项目名称:shiftspace,代码行数:11,代码来源:shift.py

示例2: update

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [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)
开发者ID:electrikfreak,项目名称:shiftspace,代码行数:32,代码来源:shift.py

示例3: testUpdate

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [as 别名]
 def testUpdate(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.update({"summary":"changed!"})
     theShift = Shift.read(newShift.id, self.fakemary.id)
     self.assertEqual(theShift.summary, "changed!")
     db = core.connect(SSUser.privateDb(self.fakemary.id))
     del db[theShift.id]
开发者ID:xncroft,项目名称:shiftspace,代码行数:11,代码来源:shift_model_test.py

示例4: delete

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [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")
开发者ID:electrikfreak,项目名称:shiftspace,代码行数:12,代码来源:shift.py

示例5: testRead

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [as 别名]
 def testRead(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     theShift = Shift.read(newShift.id, self.fakemary.id)
     self.assertEqual(theShift.source.server, newShift.source.server)
     self.assertEqual(theShift.source.database, newShift.source.database)
     self.assertEqual(theShift.createdBy, self.fakemary.id)
     db = core.connect(SSUser.privateDb(self.fakemary.id))
     del db[theShift.id]
开发者ID:xncroft,项目名称:shiftspace,代码行数:12,代码来源:shift_model_test.py

示例6: create

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [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
开发者ID:gmatters,项目名称:shiftspace,代码行数:56,代码来源:comment.py

示例7: testCreate

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [as 别名]
 def testCreate(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     theShift = Shift.create(json)
     self.assertEqual(theShift.type, "shift")
     self.assertEqual(theShift.createdBy, self.fakemary.id)
     self.assertNotEqual(theShift.created, None)
     self.assertEqual(type(theShift.created), datetime.datetime)
     self.assertNotEqual(theShift.modified, None)
     self.assertEqual(type(theShift.modified), datetime.datetime)
     self.assertEqual(theShift.domain, "http://google.com")
     db = core.connect(SSUser.privateDb(self.fakemary.id))
     del db[theShift.id]
开发者ID:xncroft,项目名称:shiftspace,代码行数:15,代码来源:shift_model_test.py

示例8: read

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [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)
开发者ID:gmatters,项目名称:shiftspace,代码行数:16,代码来源:shift.py

示例9: delete

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [as 别名]
 def delete(self):
     """
     Delete a single comment.
     """
     from server.models.ssuser import SSUser
     db = core.connect(SSUser.privateDb(self.createdBy))
     try:
         del db[self.id]
     except:
         pass
     db = core.connect(Comment.db(self.shiftId))
     try:
         del db[self.id]
     except:
         pass
     core.replicate(Comment.db(self.shiftId), "shiftspace/shared")
开发者ID:gmatters,项目名称:shiftspace,代码行数:18,代码来源:comment.py

示例10: testBasicPublish

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [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)
开发者ID:xncroft,项目名称:shiftspace,代码行数:19,代码来源:shift_model_test.py

示例11: read

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [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)
开发者ID:electrikfreak,项目名称:shiftspace,代码行数:25,代码来源:shift.py

示例12: publish

# 需要导入模块: from server.models.ssuser import SSUser [as 别名]
# 或者: from server.models.ssuser.SSUser import privateDb [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)
开发者ID:electrikfreak,项目名称:shiftspace,代码行数:84,代码来源:shift.py


注:本文中的server.models.ssuser.SSUser.privateDb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。