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, w): """Copy relevant fields from WishList to WishListForm.""" wf = WishListForm() for field in wf.all_fields(): setattr(wf, field.name, getattr(w, 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
def _copyWishListToForm(self, wishlist): """Copy relevant fields from Wishlist to WishlistForm.""" wlform = WishListForm() for field in wlform.all_fields(): if hasattr(wishlist, field.name): # convert Key to key string and just copy others if field.name.endswith('sessionKey'): setattr(wlform, field.name, str(getattr(wishlist, field.name))) else: print "[_copyWishListToForm] No sessionKey but: ",field.name setattr(wlform, field.name, getattr(wishlist, field.name)) wlform.check_initialized() return wlform
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 addSessionToWishlist(self, request): """Add particular Session to users wishlist""" # make sure user is authed user = endpoints.get_current_user() if not user: raise endpoints.UnauthorizedException('Authorization required') # make sure session Key is provided if not request.sessionKey: raise endpoints.BadRequestException("Session 'key' field required") # make sure the session Key provided is already there in datastore skey = request.sessionKey sess = ndb.Key(urlsafe=skey).get() if not sess: raise endpoints.NotFoundException( 'No Session found with key: %s' % sess) # Check if the user has already added this session in wishlist earlier userID = getUserId(user) w = WishList.query(ndb.AND( WishList.userId == userID, WishList.sessionKey == request.sessionKey) ).fetch() if w: raise ConflictException("You have already added this session to wishlist") # copy WishListForm/ProtoRPC Message into dict data= {} data['userId'] = userID data['sessionKey'] = request.sessionKey # Store the data in data store WishList(**data).put() # return WishListForm wlf = WishListForm() wlf.userId = userID wlf.sessionKey = request.sessionKey wlf.check_initialized() return wlf
def _copyWishListToForm(self, wishlist): ''' Creates a message from a wishlist ''' wishlist_form = WishListForm() wishlist_form.sessions = self._getSessionFormsFromWsKeys( wishlist.sessions) return wishlist_form