예제 #1
0
def describe_notification(notification_obj): 
    """
    Describes a notification in a human understandable manner.
    Returns a dictionary that
     
    - contains a text string that will explain
    what this notification is about;
    - a url to the checkpoint image
    - and the id of the relevant user checkpoint obj 
    """
    from action.like import get_like
    from action.comment import get_comment
    from action.share import get_share
    from action.user_checkpoint import get_user_checkpoint_attr
    from action.serve import get_checkpoint_img_url
    
    ucp_id = None
    txt = ""
    ucp_url = None
    
    relevant_user_name = notification_obj.from_user.facebook_user.name
    
    if notification_obj.type == "new_like":
        #format: XXX likes your Checkpoint: "Chicken Rice"
        like_obj = get_like(notification_obj.relevant_id)
        user_checkpoint_obj = get_user_checkpoint_attr(notification_obj.affected_user, like_obj.checkpoint)
        
        ucp_id = user_checkpoint_obj.id
        ucp_url = get_checkpoint_img_url(like_obj.checkpoint)
        txt = "%s likes your Checkpoint: %s" % (relevant_user_name, like_obj.checkpoint.name)
                
    elif notification_obj.type == "new_comment":
        #format: XXX commented on Checkpoint: "Chicken Rice"
        comment_obj = get_comment(notification_obj.relevant_id)
        user_checkpoint_obj = get_user_checkpoint_attr(notification_obj.affected_user, comment_obj.checkpoint)
        ucp_id = user_checkpoint_obj.id
        ucp_url = get_checkpoint_img_url(user_checkpoint_obj.checkpoint)
        txt = "%s commented on Checkpoint: %s" % (relevant_user_name, comment_obj.checkpoint.name)
        
    elif notification_obj.type == "new_share":
        #format: XXX recommends you to check out a Checkpoint: "Chicken Rice"
        share_obj = get_share(notification_obj.relevant_id)
        user_checkpoint_obj = share_obj.user_checkpoint
        ucp_id = user_checkpoint_obj.id
        ucp_url = get_checkpoint_img_url(user_checkpoint_obj.checkpoint)
        txt = "%s recommends you to check out a Checkpoint: %s" % (relevant_user_name, user_checkpoint_obj.checkpoint.name)
        
    return {"notification_text": txt,
            "checkpoint_img_url": ucp_url,
            "user_checkpoint_id": ucp_id,
            }
예제 #2
0
파일: db.py 프로젝트: nubela/spawt-backend
 def serialize(self):
     """
     Return this object data into an easily serializable form (For JSON)
     """
     from action.like import get_total_likes_checkpoint
     from action.comment import get_checkpoint_comments
     from action.user import get_user
     
     return {
             "id": self.id,
             "creator": self.creator,
             "creator_name": get_user(self.creator).facebook_user.name,
             "name": self.name,
             "description": self.description,
             "price": self.price,
             "expiry": serialize_json_datetime(self.expiry),
             "date_created": serialize_json_datetime(self.date_created),
             "type": self.type,
             "image": self.image,
             "image_url": get_checkpoint_img_url(self),
             "longitude": self.longitude,
             "latitude": self.latitude,
             
             "total_likes": get_total_likes_checkpoint(self),
             "total_comments": get_checkpoint_comments(self).count(),
             }