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


Python group.Group类代码示例

本文整理汇总了Python中server.models.group.Group的典型用法代码示例。如果您正苦于以下问题:Python Group类的具体用法?Python Group怎么用?Python Group使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: publish

 def publish(self, id):
     # NOTE: should maybe take publishData url parameter - David 9/5/2009
     loggedInUser = helper.getLoggedInUser()
     theShift = Shift.read(id, loggedInUser)
     if not theShift:
         return error("Resource does not exist.", ResourceDoesNotExistError)
     if theShift.type != "shift":
         return error("Resource is not of type shift", ResourceTypeError)
     publishData = json.loads(helper.getRequestBody())
     # convert targets to actual database references
     if publishData.get("targets"):
         from server.models.group import Group
         from server.models.ssuser import SSUser
         theUser = SSUser.read(loggedInUser)
         targets = publishData["targets"]
         # convert short names to group ids
         shortNames = [target[1:] for target in targets if target[0] == "&"]
         groupIds = Group.shortNamesToIds(shortNames)
         # convert user name to user ids
         userNames = [target[1:] for target in targets if target[0] == "@"]
         userIds = SSUser.namesToIds(userNames)
         # create list of dbs being published to
         dbs = [Group.db(groupId) for groupId in groupIds]
         dbs.extend([SSUser.db(userId) for userId in userIds])
         # validate
         writeable = theUser.writeable()
         if set(writeable) != set(dbs):
             return error("Operation not permitted. You don't have permission to publish to some of these gruops", PermissionError)
         publishData["dbs"] = dbs
     return data(theShift.publish(publishData))
开发者ID:gmatters,项目名称:shiftspace,代码行数:30,代码来源:shift.py

示例2: update

    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,代码行数:30,代码来源:shift.py

示例3: addToGroups

 def addToGroups(self, groupDbs):
     from server.models.group import Group
     # NOTE - do we need to delete from user/private? - David 11/12/09
     for db in groupDbs:
         dbtype, dbid = db.split("/")
         theGroup = Group.read(dbid)
         theGroup.addShift(self)
开发者ID:electrikfreak,项目名称:shiftspace,代码行数:7,代码来源:shift.py

示例4: create

    def create(cls, userId, groupId, otherId, level):
        from server.models.ssuser import SSUser
        from server.models.group import Group

        db = core.connect()
        if not groupId:
            raise MissingGroupError
        if not userId:
            raise MissingCreatorError
        if Permission.readByUserAndGroup(otherId, groupId):
            raise PermissionAlreadyExistsError

        adminable = [row.value for row in Permission.by_adminable(db, key=userId).rows]
        allowed = groupId in adminable
        if not allowed:
            theUser = SSUser.read(userId)
            allowed = theUser.isAdmin()
        if not allowed:
            theGroup = Group.read(groupId)
            allowed = theUser.isOwnerOf(theGroup)
        if not allowed:
            raise CreateEventPermissionError

        json = {
            "createdBy": userId,
            "userId": otherId,
            "groupId": groupId,
            "level": level
            }

        newPermission = Permission(**utils.clean(json))
        newPermission.store(db)
        return newPermission
开发者ID:electrikfreak,项目名称:shiftspace,代码行数:33,代码来源:permission.py

示例5: adminable

 def adminable(cls, userId, dbname=True):
     from server.models.group import Group
     db = core.connect()
     ids = core.values(Permission.by_adminable(db, key=userId))
     if dbname:
         return [Group.db(id) for id in ids]
     else:
         return ids
开发者ID:electrikfreak,项目名称:shiftspace,代码行数:8,代码来源:permission.py

示例6: members

 def members(self, id):
     from server.models.ssuser import SSUser
     theGroup = Group.read(id)
     loggedInUser = helper.getLoggedInUser()
     theUser = SSUser.read(loggedInUser)
     if theUser.isAdminOf(theGroup):
         return data(theGroup.members())
     else:
         return error("You don't have permission to view this groups members", PermissionError)
开发者ID:ShiftSpace,项目名称:shiftspace,代码行数:9,代码来源:group.py

示例7: create

 def create(self):
     loggedInUser = helper.getLoggedInUser()
     jsonData = helper.getRequestBody()
     if jsonData != "":
         theData = json.loads(jsonData)
         theData['createdBy'] = loggedInUser
         return data(Group.create(theData))
     else:
         return error("No data for group.", NoDataError)
开发者ID:ShiftSpace,项目名称:shiftspace,代码行数:9,代码来源:group.py

示例8: join

 def join(self, id):
     from server.models.ssuser import SSUser
     theGroup = Group.read(id)
     loggedInUser = helper.getLoggedInUser()
     theUser = SSUser.read(loggedInUser)
     if theUser.canJoin(theGroup):
         theUser.join(theGroup)
         return data(theGroup)
     else:
         return error("Operation not permitted. You don't have permission to join this group.", PermissionError)
开发者ID:ShiftSpace,项目名称:shiftspace,代码行数:10,代码来源:group.py

示例9: makeAdmin

 def makeAdmin(self, id, userId):
     from server.models.ssuser import SSUser
     theGroup = Group.read(id)
     theUser = SSUser.read(helper.getLoggedInUser())
     if theUser.isAdminOf(theGroup):
         otherUser = SSUser.read(userId)
         theGroup.setPrivilege(otherUser, 3)
         return ack
     else:
         return error("You don't have permission to promote members of this group to admin.", PermissionError)
开发者ID:ShiftSpace,项目名称:shiftspace,代码行数:10,代码来源:group.py

示例10: testPublishToGroupAndUser

 def testPublishToGroupAndUser(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     json = groupJson()
     json["createdBy"] = self.fakemary.id
     newGroup = Group.create(json)
     newPerm = Permission.create("shiftspace", newGroup.id, self.fakejohn.id, level=1)
     publishData = {
         "dbs": [Group.db(newGroup.id), SSUser.db(self.fakebob.id)]
         }
     newShift.publish(publishData)
     # should exist in subscriber's feed
     db = core.connect("shiftspace/shared")
     theShift = Shift.load(db, newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     newGroup.delete()
     # should exist in shiftspace/shared
     # TODO: inbox if user is peer - David 11/18/09
     theShift = Shift.load(core.connect("shiftspace/shared"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
开发者ID:xncroft,项目名称:shiftspace,代码行数:21,代码来源:shift_model_test.py

示例11: inviteUsers

 def inviteUsers(self, id, users):
     from server.models.ssuser import SSUser
     loggedInUser = helper.getLoggedInUser()
     groupAdmin = SSUser.read(loggedInUser)
     theGroup = Group.read(id)
     if groupAdmin.isAdminOf(theGroup):
         db = core.connect()
         users = SSUser.all(db, keys=json.loads(users))
         for user in users:
             groupAdmin.inviteUser(theGroup, user)
         return data(theGroup)
     else:
         return error("Operation not permitted. You don't have permission to modify this group", PermissionError)
开发者ID:ShiftSpace,项目名称:shiftspace,代码行数:13,代码来源:group.py

示例12: update

 def update(self, id):
     from server.models.ssuser import SSUser
     loggedInUser = helper.getLoggedInUser()
     theUser = SSUser.read(loggedInUser)
     theGroup = Group.read(id)
     jsonData = helper.getRequestBody()
     if jsonData != "":
         if theUser.isAdminOf(theGroup):
             groupData = json.loads(jsonData)
             return data(theGroup.update(groupData))
         else:
             return error("You don't have permission to update this group", PermissionError)
     else:
         return error("No data for group.", NoDataError)
开发者ID:ShiftSpace,项目名称:shiftspace,代码行数:14,代码来源:group.py

示例13: testPublishToGroup

 def testPublishToGroup(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     json = groupJson()
     json["createdBy"] = self.fakemary.id
     newGroup = Group.create(json)
     # make sure fakemary owns the group
     newPerm = Permission.readByUserAndGroup(self.fakemary.id, newGroup.id)
     self.assertTrue(newPerm.level == 4)
     # create read permission for fakejohn
     newPerm = Permission.create("shiftspace", newGroup.id, self.fakejohn.id, level=1)
     fakejohn = SSUser.read(self.fakejohn.id)
     self.assertTrue(Group.db(newGroup.id) in fakejohn.readable())
     publishData = {
         "dbs": [Group.db(newGroup.id)]
         }
     newShift.publish(publishData)
     # should exists in shiftspace/shared
     db = core.connect("shiftspace/shared")
     theShift = Shift.load(db, newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     newGroup.delete()
开发者ID:xncroft,项目名称:shiftspace,代码行数:23,代码来源:shift_model_test.py

示例14: info

 def info(self, id):
     from server.models.ssuser import SSUser
     # TODO: bulk call - David 12/13/2009
     theGroup = Group.read(id)
     memberCount = theGroup.memberCount()
     adminCount = theGroup.adminCount()
     shiftCount = theGroup.shiftCount()
     info = {
         "memberCount": memberCount,
         "adminCount": adminCount,
         "shiftCount": shiftCount
         }
     theUser = SSUser.read(helper.getLoggedInUser())
     info["isAdmin"] = theUser.isAdminOf(theGroup)
     return data(info)
开发者ID:ShiftSpace,项目名称:shiftspace,代码行数:15,代码来源:group.py

示例15: deletedbs

def deletedbs():
    """
    Delete the databases, the database path must have been set
    first for this to work.
    """
    from server.models import core
    from server.models.ssuser import SSUser
    from server.models.group import Group

    # delete all core dbs and user and group dbs
    server = core.server()
    [group.delete() for group in core.objects(Group.all(core.connect()))]
    [user.delete() for user in core.objects(SSUser.all(core.connect()))]
    del server["shiftspace/public"]
    del server["shiftspace/shared"]
    del server["shiftspace/messages"]
    del server["shiftspace/master"]
    #[comment.deleteInstance() for comment in core.object(Comment.all(core.connect()))]
    # cleanup, remove any empty folders (left from deleted users
    try:
        fh = open("config/conf.json")
    except:
        print "config/conf.json does not exist. Set the path the database first."
        sys.exit(2)
    conf = json.loads(fh.read())
    if conf.get("dbpath"):
        userdbdir = os.path.join(conf["dbpath"], "user")
        if os.path.exists(userdbdir):
            for file in os.listdir(userdbdir):
                filepath = os.path.join(userdbdir, file)
                if os.path.isdir(filepath):
                    os.rmdir(filepath)
            os.rmdir(userdbdir)
        grpdbdir = os.path.join(conf["dbpath"], "group")
        if os.path.exists(grpdbdir):
            os.rmdir(grpdbdir)
        ssdbdir = os.path.join(conf["dbpath"], "shiftspace")
        if os.path.exists(ssdbdir):
            os.rmdir(ssdbdir)
开发者ID:electrikfreak,项目名称:shiftspace,代码行数:39,代码来源:shifty.py


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