Esempio n. 1
0
def _checkpoint_details():
    """
    Gets detailed information about a (User)Checkpoint given its id.   
    """
    CheckpointDetail = namedtuple("CheckpointDetail", 
                                  ("user_checkpoint_obj", 
                                   "total_likes",
                                   "total_shares",
                                   "current_user_like",
                                   "comments",
                                   "user",                                   
                                   ))
    
    user_id = request.args.get("user_id")
    user_checkpoint_id = request.args.get("user_checkpoint_id")
    user_obj = get_user(user_id)
    
    user_checkpoint_obj = get_user_checkpoint(user_checkpoint_id)
    total_likes = get_total_likes(user_checkpoint_obj)
    total_shares = get_total_shares(user_checkpoint_obj)
    current_user_like = (not get_like_w_attr(user_obj, user_checkpoint_obj.checkpoint) is None)
    comments = get_checkpoint_comments(user_checkpoint_obj.checkpoint)
    checkpoint_user_obj = user_checkpoint_obj.user
    user = {"name": checkpoint_user_obj.facebook_user.name,
            "facebook_portrait_url": "https://graph.facebook.com/%s/picture" % checkpoint_user_obj.facebook_user.id,
            }
    
    res = CheckpointDetail(user_checkpoint_obj,
                           total_likes,
                           total_shares,
                           current_user_like,
                           comments,
                           user
                           )
    return res
Esempio n. 2
0
 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(),
             }