예제 #1
0
    def post(self):
      activeUser = self.current_user
      
      skate = Skate()
      skate.owner = activeUser
      if self.request.get('size'): 
          skate.size = float(self.request.get('size'))
      if self.request.get('price'):
          if self.request.get('price') == 'FREE!':
              skate.price = 0
          else:
              skate.price = int(self.request.get('price'))
      skate.note = self.request.get('notes')
      if self.request.get('image'):
          skatePic = True
          logging.info('image being stored as a blob');
          uploadImage = images.resize(self.request.get('image'),300)
          skate.picture = db.Blob(uploadImage)
      else:
          skatePic = False

      # @todo fill out other properties
      skate.swapped = False
      skate.status = 0
      skate.put()
      
      # log event
      event.createEvent(event.EVENT_SKATE_ADD, activeUser, skate, ('price=%s' % skate.price))

      # set styling for price
      if( not skate.price or skate.price == 0.0 ):
          priceStyle = 'free'
          price = 'free!'
      else:
          priceStyle = 'notfree'
          price = '$'+str(skate.price)
      
      # encapsulate in json
      response_dict = {}
      if activeUser.first:
          owner = activeUser.first + ' ' + activeUser.last
      else:
          owner = activeUser.nickname
      response_dict.update({'owner':owner,
                            'size':skate.size,
                            'color':skate.color,
                            'price':price,
                            'priceStyle':priceStyle,
                            'note':skate.note,
                            'picture':'/img?id=%s'%skate.key() if skatePic else '/img/iceskater.png',
                           })
      logging.debug('json response %s' % response_dict);
            
      self.response.headers['Content-Type'] = 'application/javascript'
      self.response.out.write(simplejson.dumps(response_dict))
예제 #2
0
    def current_user(self):
        if users.get_current_user():
            user = users.get_current_user()
            localUser = db.GqlQuery("select * from User where userID = :1", user.user_id()).get()
            if not localUser:
                user = User(userID=user.user_id(),
                            nickname=user.nickname())
                user.put()
                self.redirect('/user/edit?userKey=%s' % user.key())
            else:
                user = localUser
            self._current_user = user
        elif not hasattr(self, "_current_user"):
            self._current_user = None
            cookie = facebook.get_user_from_cookie(self.request.cookies, 
                                                   facebook.FACEBOOK_APP_ID, 
                                                   facebook.FACEBOOK_APP_SECRET)
            if cookie:
                # Store a local instance of the user data so we don't need
                # a round-trip to Facebook on every request
                user = User.get_by_key_name(cookie["uid"])
                if not user:
                    graph = facebook.GraphAPI(cookie["access_token"])
                    try:
                        profile = graph.get_object("me")
                    except facebook.GraphAPIError:
                        self._current_user = None
                        return None
                    
                    user = User(key_name=str(profile["id"]),
                                userID=str(profile["id"]),
                                nickname=profile["name"],
                                fbProfile_url=profile["link"],
                                email=profile["email"],
                                access_token=cookie["access_token"])
                    logging.info("New User object created for %s (%s)" % (profile["name"],profile["id"]))
                    user.put()
                    
                    # log event
                    event.createEvent(event.EVENT_USER_ADD, user, None, profile["id"])

                elif user.access_token != cookie["access_token"]:
                    user.access_token = cookie["access_token"]
                    user.put()
                self._current_user = user
        return self._current_user
예제 #3
0
    def post(self):
        activeUser = self.current_user
        event.createEvent(event.EVENT_USER_COMMENT,
                          activeUser,
                          None,
                          self.request.get('comment'),
                          None)
        if activeUser.fbProfile_url is None:
            profilePic = '<img src="/img/no-avatar.gif">'
        else:
            profilePic = ('<img src=http://graph.facebook.com/%s/picture>' % activeUser.userID)

        # encapsulate response in json
        response_dict = {}
        response_dict.update({'profilePic':profilePic,
                              'body':self.request.get('comment'),
                             })
        logging.debug('json response %s' % response_dict);
            
        self.response.headers['Content-Type'] = 'application/javascript'
        self.response.out.write(simplejson.dumps(response_dict))
예제 #4
0
    def post(self):
        activeUser = self.current_user;
        skateKey = self.request.get("key")
        logging.debug("looking for skate key %s" % skateKey)
        skate = db.get(skateKey)
        if skate is None:
            logging.error("Impossible. I couldn't find skate with that key")
            self.response.set_status(403)
            return
        else:
            logging.info("I found your skate! From %s, size %s (%s)" % (skate.owner.nickname, skate.size,skate.note))
        
        skate.status = 1
        skate.put() 

        # construction the email with the transaction details
        template_values = {'owner':skate.owner.nickname, 
                           'borrower':activeUser.nickname,
                           'borrowerEmail':activeUser.email,
                           'size':skate.size,
                           'price':skate.price,
                           'style':skate.style,
                           'note':skate.note,
                           }       
        path = os.path.join(os.path.dirname(__file__), 'checkout-email.html')
        body = template.render(path, template_values)
    
        # log event
        event.createEvent(event.EVENT_SKATE_CHECKOUT, activeUser, skate, str(skate.price))
      
        # send out email notification
        logging.debug("creating email task for checkout... send to owner %s and borrower %s" % (skate.owner.email,activeUser.email))
        task = Task(url='/event/email', params={'ownerEmail':skate.owner.email,
                                                'borrowerEmail':activeUser.email,
                                                'body':body})
        task.add('emailqueue')
        self.response.set_status(200)
        return