Ejemplo n.º 1
0
 def _addSessionToWishlist(self, request):
     #Check if the user is logged in
     
     user = self._getLoggedInUser()
     user_id = getUserId(user)
         
     #Check if the theSession exists
     theSession = ndb.Key(urlsafe=request.websafeSessionKey).get()
     
     if not theSession:
         raise endpoints.BadRequestException("Invalid session key")
     
     #Get user profile
     prof = ndb.Key(Profile, user_id).get()
     
     if not prof:
         raise endpoints.BadRequestException("Unable to find user profile")
     
     wishlistEntry = UserWishlist.query(ancestor=prof.key).filter(
         getattr(UserWishlist, "wishlistedSessionKey") == request.websafeSessionKey
     ).get()
     
     print wishlistEntry
     
     #If the desired wishlist entry doesn't already exist, create it.
     if not wishlistEntry:
         wishlistEntry = UserWishlist(parent=prof.key)
         setattr(wishlistEntry, "wishlistedSessionKey", request.websafeSessionKey)
         wishlistEntry.put()
         
     return self._getUserWishlistByProfile(prof)     
Ejemplo n.º 2
0
 def _getUserWishlistByProfile(self, profile):
     #Given a profile, get its key and return the sessions on the wishlist 
     
     if not profile:
         raise endpoints.BadRequestException("Invalid profile!")
     
     #Get the wishlist entries and add them to the wishlist to return.
     wishlistEntries = UserWishlist.query(ancestor=profile.key).fetch(limit=None)
     finishedWishlist = SessionForms()
     
     if wishlistEntries:
         for entry in wishlistEntries:
             theSession = ndb.Key(urlsafe=getattr(entry, "wishlistedSessionKey")).get()
             sf = self._copySessionToForm(theSession)
             sf.check_initialized()
             finishedWishlist.items.append(sf)
             
     return finishedWishlist