• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python shift.Shift类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: shifts

 def shifts(self, start=None, end=None, limit=25, filter=False, query=None):
     from server.models.shift import Shift
     db = core.connect("shiftspace/shared")
     if not filter:
         if not start:
             start = [self.id]
         if not end:
             end = [self.id, {}]
         results = Shift.by_user_and_created(db, limit=limit)
         return Shift.joinData(core.objects(results[start:end]))
     else:
         lucene = core.lucene()
         queryString = "createdBy:%s" % self.id
         theFilter = core.dictToQuery(query)
         if theFilter:
             queryString = queryString + " AND " + theFilter
         try:
             print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
             print queryString
             rows = lucene.search(db, "shifts", q=queryString, include_docs=True, sort="\modified")
         except Exception, err:
             print err
             return []
         shifts = [row["doc"] for row in rows]
         return Shift.joinData(shifts, self.id)
开发者ID:gmatters,项目名称:shiftspace,代码行数:25,代码来源:ssuser.py


示例2: testDelete

 def testDelete(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     self.assertNotEqual(newShift, None)
     newShift.delete()
     theShift = Shift.read(newShift.id, self.fakemary.id)
     self.assertEqual(theShift, None)
开发者ID:xncroft,项目名称:shiftspace,代码行数:8,代码来源:shift_model_test.py


示例3: testUpdate

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


示例4: testRead

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


示例5: testPublishToUser

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


示例6: testPagingFeatures

 def testPagingFeatures(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift1 = Shift.create(json)
     newShift2 = Shift.create(json)
     newShift3 = Shift.create(json)
     fav1 = Favorite.create(self.fakejohn.id, newShift1.id)
     fav2 = Favorite.create(self.fakejohn.id, newShift2.id)
     fav3 = Favorite.create(self.fakejohn.id, newShift3.id)
     favorites = self.fakejohn.favorites(limit=2)
     self.assertEqual(len(favorites), 2)
     fav1.delete()
     fav2.delete()
     fav3.delete()
开发者ID:ShiftSpace,项目名称:shiftspace,代码行数:14,代码来源:favorite_model_test.py


示例7: testPublishToFollowers

 def testPublishToFollowers(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     self.fakejohn.follow(self.fakemary)
     fakejohn = SSUser.read(self.fakejohn.id)
     # should be in the list of people fakejohn is following
     self.assertTrue(self.fakemary.id in fakejohn.following())
     # should be in the list of fakemary's followers
     followers = self.fakemary.followers()
     self.assertTrue(self.fakejohn.id in followers)
     newShift.publish({"private":False})
     # should exist in shiftspace/shared db
     theShift = Shift.load(core.connect("shiftspace/shared"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
开发者ID:xncroft,项目名称:shiftspace,代码行数:15,代码来源:shift_model_test.py


示例8: testCanModify

 def testCanModify(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     self.assertTrue(self.fakemary.canModify(newShift))
     self.assertTrue(not self.fakejohn.canModify(newShift))
     self.assertTrue(self.root.canModify(newShift))
开发者ID:xncroft,项目名称:shiftspace,代码行数:7,代码来源:shift_model_test.py


示例9: 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


示例10: testSubscribe

 def testSubscribe(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private":False})
     # make a comment
     newComment = Comment.create(
         self.fakejohn.id,
         newShift.id,
         "1st comment!",
         subscribe=True
         )
     # check that shift author is subscribed
     subscribers = newShift.subscribers()
     self.assertTrue(self.fakemary.id in subscribers)
     # check that commenter is subscribed
     self.assertTrue(self.fakejohn.id in subscribers)
     # check that there is a message in shift author message db
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].text, "fakejohn just commented on your shift!")
     # check that there is _not_ a message in commenters message db
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 0)
     newShift.deleteThread()
开发者ID:ShiftSpace,项目名称:shiftspace,代码行数:25,代码来源:comment_model_test.py


示例11: unpublish

 def unpublish(self, id):
     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)
     return data(theShift.unpublish())
开发者ID:gmatters,项目名称:shiftspace,代码行数:8,代码来源:shift.py


示例12: testBasicPublish

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


示例13: create

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


示例14: comment

 def comment(self, id):
     loggedInUser = helper.getLoggedInUser()
     jsonData = helper.getRequestBody()
     if jsonData != "":
         theShift = Shift.read(id)
         if not theShift:
             return error("Resource does not exist.", ResourceDoesNotExistError)
         if theShift.type != "shift":
             return error("Resource is not of type shift", ResourceTypeError)
         from server.models.ssuser import SSUser
         theUser = SSUser.read(loggedInUser)
         theData = json.loads(jsonData)
         if theUser.canRead(theShift):
             from server.models.comment import Comment
             Comment.create(theUser.id, theShift.id, theData["text"], theData.get("subscribe") or False)
             return data(Shift.read(theShift.id, theUser.id))
         else:
             return error("Operation not permitted. You don't have permission to comment on this shift.", PermissionError)
     else:
         return error("No data for comment.", NoDataError)
开发者ID:gmatters,项目名称:shiftspace,代码行数:20,代码来源:shift.py


示例15: info

 def info(self):
     from server.models.follow import Follow
     from server.models.shift import Shift
     # TODO: use the bulk API - David 12/10/09
     result = {}
     db = core.connect()
     shared = core.connect("shiftspace/shared")
     result["followerCount"] = core.value(Follow.followers_count(db, key=self.id)) or 0
     result["followingCount"] = core.value(Follow.following_count(db, key=self.id)) or 0
     result["publishedShiftCount"] = core.value(Shift.count_by_user_and_published(shared, key=self.id)) or 0
     return result
开发者ID:gmatters,项目名称:shiftspace,代码行数:11,代码来源:ssuser.py


示例16: share

 def share(self, id, users):
     from server.models.ssuser import SSUser
     loggedInUser = helper.getLoggedInUser()
     theShift = Shift.read(id)
     if not theShift or theShift.publishData.private:
         return error("You don't have permission to view this shift.", PermissionError)
     targets = users.split(" ")
     userNames = [target[1:] for target in targets if target[0] == "@"]
     userIds = SSUser.namesToIds(userNames)
     theShift.shareWith(userIds, fromUser=SSUser.read(loggedInUser))
     return ack
开发者ID:ShiftSpace,项目名称:shiftspace,代码行数:11,代码来源:shift.py


示例17: create

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


示例18: 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


示例19: feed

 def feed(self, start=None, end=None, limit=25):
     # NOT IMPLEMENTED: will have to wait until we get to the point where
     # we're writing p2p code - David
     from server.models.shift import Shift
     results = Shift.by_created(core.connect(SSUser.feedDb(self.id)), limit=limit)
     if start and not end:
         return core.objects(results[start:])
     if not start and end:
         return core.objects(results[:end])
     if start and end:
         return core.objects(results[start:end])
     return core.objects(results[start:end])
开发者ID:gmatters,项目名称:shiftspace,代码行数:12,代码来源:ssuser.py


示例20: read

 def read(self, id):
     from server.models.ssuser import SSUser
     loggedInUser = helper.getLoggedInUser()
     theUser = SSUser.read(loggedInUser)
     theShift = Shift.read(id, loggedInUser)
     if theShift and theUser.canRead(theShift):
         return data(theShift)
     else:
         if not theShift:
             return error("Resource does not exist.", ResourceDoesNotExistError)
         else:
             return error("Operation not permitted. You don't have permission to view this shift. %s" % theShift, PermissionError)
开发者ID:gmatters,项目名称:shiftspace,代码行数:12,代码来源:shift.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ssuser.SSUser类代码示例发布时间:2022-05-27
下一篇:
Python permission.Permission类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap