當前位置: 首頁>>代碼示例>>Python>>正文


Python Request.query方法代碼示例

本文整理匯總了Python中models.Request.query方法的典型用法代碼示例。如果您正苦於以下問題:Python Request.query方法的具體用法?Python Request.query怎麽用?Python Request.query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Request的用法示例。


在下文中一共展示了Request.query方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get

# 需要導入模塊: from models import Request [as 別名]
# 或者: from models.Request import query [as 別名]
  def get(self):
    user = self.user_model
    get_notifications(user)
    current_date = datetime.datetime.now() - datetime.timedelta(hours=8)

    all_requests = Request.query(Request.start_time >= current_date).order(Request.start_time)
    all_requests = [r for r in all_requests if r.sender != user.key]
    pending_requests = Request.query(Request.status == 'pending').order(Request.start_time)
    pending_requests = [r for r in pending_requests if r.start_time < current_date]

    # Sort by food type
    type_sort = sorted(all_requests, key=lambda x:x.food_type)
    types = {}

    for r in type_sort:
      # Get all types
      if r.food_type not in types:
        types[r.food_type] = []

    for r in type_sort:
      for t in types:
        if r.food_type == t:
          types[t].append(r)
          break

    self.response.out.write(template.render('views/feed.html', {'user': user,
      'pending_requests': pending_requests, 'all_requests': all_requests, 'food_type':types}))
開發者ID:Qiwis,項目名稱:foodie,代碼行數:29,代碼來源:main.py

示例2: get

# 需要導入模塊: from models import Request [as 別名]
# 或者: from models.Request import query [as 別名]
 def get(self):
   current_time = datetime.datetime.now() - datetime.timedelta(hours=8)
   max_time = current_time + datetime.timedelta(hours=1)
   dead_accepted_requests = Request.query(Request.start_time > current_time, Request.start_time < max_time).fetch()
   dead_accepted_requests = [x for x in dead_accepted_requests if x.status == "sms" and x.recipient != None]
   for request in dead_accepted_requests:
     request.status = "dead"
   dead_requests = Request.query(Request.start_time < current_time).fetch()
   dead_requests = [x for x in dead_requests if x.status == "waiting for a bid" or x.status =="pending"]
   for request in dead_requests:
     print "Removing request: " + str(request)
     request.key.delete()
開發者ID:Qiwis,項目名稱:foodie,代碼行數:14,代碼來源:confirmed_requests.py

示例3: get_notifications

# 需要導入模塊: from models import Request [as 別名]
# 或者: from models.Request import query [as 別名]
def get_notifications(user):
  #Get Requests for Notifications
  accepted_requests = []
  new_requests = []
  current_time = datetime.datetime.now() - datetime.timedelta(hours=8)
  # Check for last login/update
  check_time = user.last_check
  print "Last Check: " , check_time
  if check_time is None:
    # Pull all results from previous week
    check_time = datetime.datetime.now() - datetime.timedelta(days=7, hours=8)
    print "Updated time: ", check_time

  # New requests
  available_requests = Request.query(Request.sender != user.key).fetch()
  available_requests = [r for r in available_requests if r.creation_time >= check_time]
  available_requests = [r for r in available_requests if r.start_time >= current_time]
  available_requests = [r for r in available_requests if r.recipient == None]

  # Approved requests
  approved_requests = Request.query(Request.recipient == user.key).fetch()
  approved_requests = [r for r in approved_requests if r.accept_time != None]
  approved_requests = [r for r in approved_requests if r.start_time >= current_time]
  approved_requests = [r for r in approved_requests if r.accept_time >= check_time]


  # Pending requests
  pend_requests = Request.query(Request.sender == user.key).fetch()
  pend_requests = [r for r in pend_requests if r.start_time >= current_time]
  pend_requests = [r for r in pend_requests if len(r.bidders) > 0]
  new_bidders = 0
  if len(pend_requests) > 0:
    for r in pend_requests:
      for bid in r.bidders:
        bid = bid.get()
        if bid.bid_time != None:
          if bid.bid_time > check_time:
            print "Bid Time: " , bid.bid_time
            new_bidders += 1
  else:
    pend_requests = [r for r in pend_requests if r.creation_time >= check_time]
    print "No bidders: ", pend_requests

  user.pending_requests = new_bidders
  user.available_requests = len(available_requests)
  print len(available_requests)
  user.approved_requests = len(approved_requests)
  print len(approved_requests)
  user.put()
  print "user updated"
開發者ID:Qiwis,項目名稱:foodie,代碼行數:52,代碼來源:foodie_requests.py

示例4: get

# 需要導入模塊: from models import Request [as 別名]
# 或者: from models.Request import query [as 別名]
  def get(self):
    user = self.user_model
    date = cgi.escape(self.request.get("date"))
    time = cgi.escape(self.request.get("time"))
    active_request = cgi.escape(self.request.get("edit_request"))
    if active_request:
      edit_request = ndb.Key(urlsafe=active_request).get()

    # Check for lack of values
    if len(date) < 1:
      if active_request:
        date = edit_request.start_time.strftime("%Y-%m-%d")
      else:
        self.response.out.write('Please choose date')

    # Convert date and time to datetime
    format_date = str(date+ " " +time+":00.0")
    start_time = datetime.datetime.strptime(format_date, "%Y-%m-%d %H:%M:%S.%f")

    # Check for current request within time limit
    ongoing_request = Request.query(Request.sender == user.key).fetch()

    # Remove current request if applicable
    if active_request:
      ongoing_request.remove(edit_request)
    alloted_date = start_time + datetime.timedelta(minutes=20) #Max limit

    create = timeCheck(ongoing_request, alloted_date, start_time)
    if create is True:
      self.response.out.write('Available')
    else:
      self.response.out.write('Time Already Passed/Reserved')
開發者ID:Qiwis,項目名稱:foodie,代碼行數:34,代碼來源:foodie_requests.py


注:本文中的models.Request.query方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。