예제 #1
0
  def post(self, request_id):
    location = self.request.get('location')
    # Get request
    request = ndb.Key(urlsafe=request_id).get()
    location = location.split('^')

    # Check if location has been previously used
    existing_location = Location.query(Location.name == location[0], Location.address == location[1]).get()
    if existing_location is None:
      # Add new location
      categories = location[3].split(',')
      coordinates = location[4].split(' ')
      new_location = Location()
      new_location.name = location[0]
      new_location.address = location[1]
      new_location.image_url = location[2]
      for c in categories:
        new_location.categories.append(c)
      new_location.longitude = float(coordinates[0])
      new_location.latitude = float(coordinates[1])
      new_location.put()
      
    else:
      new_location = existing_location

    if request != None:
      # Check if already appended
      add = True
      if len(request.bidders) > 0:
        for bid in request.bidders:
          bid = bid.get()
          if bid.name == self.user_model.username:
            print "Already bid"
            add = False
      if add is True:
          print "Haven't bid"
          bidder = Bidder()
          bidder.sender = self.user_model.key
          bidder.location = new_location.key
          bidder.name = self.user_model.username
          bidder.bid_time = datetime.datetime.now() - datetime.timedelta(hours=8)
          bidder.price = request.price
          bidder.put()
          request.bidders.append(bidder.key)
          request.status = "pending"
          request.put()
    else:
      print "Already connected"

    self.redirect('/feed')
예제 #2
0
def bidders(request):
    query = request.GET.get('query', '')
    return render_to_response('auction/bidders.html', {'bidders':Bidder.search(query).order_by('name'), 'query':query}, context_instance=RequestContext(request))