本文整理汇总了Python中server.models.shift.Shift类的典型用法代码示例。如果您正苦于以下问题:Python Shift类的具体用法?Python Shift怎么用?Python Shift使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Shift类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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]
示例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]
示例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)
示例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()
示例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)
示例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))
示例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))
示例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()
示例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())
示例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)
示例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)
示例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)
示例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