当前位置: 首页>>代码示例>>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;未经允许,请勿转载。