Exemple #1
0
    def save(did, user, email, content):
    
        diary_detail = Diary.get_detail(did)

        # init comments_count in single-diary
        comments_count = diary_detail.get('comments_count')
        if comments_count is None:
            comments_count = 0

        comment = {
                "_id": Kid.kid(), 
                "did": int(did),
                "user": user,
                "email": email,
                "content": content,
                "publish_time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                }

        db.diaries.update({'_id': int(did)}, {'$inc': {'comments_count': 1}, 
                                         '$push': {'comment': comment}})

        # Save in Comments Collection for Admin 
        diary_title = diary_detail.get('title')
        comment['diary_title'] = diary_title
        db.comments.save(comment)
        return
Exemple #2
0
    def reply(did, cid, content):

        comment = {
                "_id": Kid.kid(), 
                "did": int(did),
                "parent_id": int(cid),
                "user": "******",
                "content": content,
                "publish_time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                }

        db.diaries.update({'_id': int(did)}, {'$inc': {'comments_count': 1}, 
                                         '$push': {'comment': comment}})

        # Save in Comments Collection for Admin 
        diary_detail = Diary.get_detail(did)
        diary_title = diary_detail.get('title')
        comment['diary_title'] = diary_title
        db.comments.save(comment)
        return