def comments(self, start=None, end=None, limit=25): from server.models.comment import Comment if not self.hasThread(): return [] db = core.connect(Comment.db(self.id)) return Comment.joinData( core.objects(Comment.by_created(db, limit=limit)))
def hasThread(self): from server.models.comment import Comment try: server = core.sharedServer() thread = server[Comment.db(self.id)] return thread != None except Exception: return False
def subscribe(self, aShift): from server.models.comment import Comment db = core.connect(Comment.db(aShift.id)) if not self.isSubscribed(aShift): db.create({ "_id": "user:%s" % self.id, "shiftId": aShift.id, "type": "subscription", "userId": self.id, })
def testCreate(self): json = shiftJson() json["createdBy"] = self.fakemary.id newShift = Shift.create(json) newShift.publish({"private":False}) # create new comment newComment = Comment.create(self.fakejohn.id, newShift.id, "1st comment!") # shift comment db should now exist self.assertNotEqual(core.connect(Comment.db(newShift.id)), None) # shift should have thread self.assertTrue(newShift.hasThread()) # should be a comment count of 1 for shift count = newShift.commentCount() self.assertEqual(count, 1) # should be one message in fakemary's inbox from fakejohn messages = self.fakemary.messages() self.assertEqual(len(messages), 1) # delete the comment # TODO: separate fixture - David newComment.delete() # delete the thread newShift.deleteThread()
def testCreate(self): json = shiftJson() json["createdBy"] = self.fakemary.id newShift = Shift.create(json) newShift.publish({"private": False}) # create new comment newComment = Comment.create(self.fakejohn.id, newShift.id, "1st comment!") # shift comment db should now exist self.assertNotEqual(core.connect(Comment.db(newShift.id)), None) # shift should have thread self.assertTrue(newShift.hasThread()) # should be a comment count of 1 for shift count = newShift.commentCount() self.assertEqual(count, 1) # should be one message in fakemary's inbox from fakejohn messages = self.fakemary.messages() self.assertEqual(len(messages), 1) # delete the comment # TODO: separate fixture - David newComment.delete() # delete the thread newShift.deleteThread()
def subscribers(self): from server.models.comment import Comment db = core.connect(Comment.db(self.id)) return core.values(Comment.all_subscribed(db))
def deleteThread(self): from server.models.comment import Comment server = core.sharedServer() # TODO - use bulk API to delete all comment stubs - David del server[Comment.db(self.id)]
def comments(self, start=None, end=None, limit=25): from server.models.comment import Comment if not self.hasThread(): return [] db = core.connect(Comment.db(self.id)) return Comment.joinData(core.objects(Comment.by_created(db, limit=limit)))
def unsubscribe(self, aShift): from server.models.comment import Comment db = core.connect(Comment.db(aShift.id)) if self.isSubscribed(aShift): del db["user:%s" % self.id]
def isSubscribed(self, aShift): from server.models.comment import Comment db = core.connect(Comment.db(aShift.id)) return db.get("user:%s" % self.id) != None