def addSessionToWishlist(self, request): """Add a Session to a wish list. the session is taken by its websafeKey and inserted in the WishList entity""" user = endpoints.get_current_user() if not user: raise endpoints.UnauthorizedException('Authorization required') user_id = getUserId(user) safe_key = request.websafeSessionKey # Get the session entity session = ndb.Key(urlsafe=safe_key).get() # define the required fields from the session in the wishlist. data = {'name': '', 'speaker': ''} data['name'] = session.name data['speaker'] = session.speaker p_key = ndb.Key(Profile, user_id) # Create the WishList entity wish = WishList( sessionName=data['name'], sessionSpeaker=data['speaker'], sessionKey=safe_key, parent=p_key ) wish.put() return WishListForm( sessionName=data['name'], sessionSpeaker=data['speaker'], sessionKey=safe_key )
def _copyWishListToForm(self, wish): """Copy relevant fields from Conference to ConferenceForm.""" wf = WishListForm() for field in wf.all_fields(): if hasattr(wish, field.name): setattr(wf, field.name, getattr(wish, field.name)) wf.check_initialized() return wf
def _copyWishListToForm(self, sess): """Set the fields from WishList to WishListForm""" wl = WishListForm() for field in wl.all_fields(): if hasattr(sess, field.name): setattr(wl, field.name, getattr(sess, field.name)) elif field.name == "sessionKey": setattr(wl, field.name, sess.key.urlsafe()) wl.check_initialized() return wl