本文整理汇总了Python中models.Request类的典型用法代码示例。如果您正苦于以下问题:Python Request类的具体用法?Python Request怎么用?Python Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: requestsv2
def requestsv2():
if not request.args or not request.args['key'] or request.args['key'] != IOS_API_KEY:
abort(401)
if request.method == "POST":
if not request.json or not 'google_places_id' in request.json or not 'name' in request.json or not 'vicinity' in request.json:
abort(400)
report_request = Request(google_places_id=request.json['google_places_id'],
name=request.json['name'],
vicinity=request.json['vicinity'])
questions = ''
more_questions = ''
if 'ios_device_id' in request.json:
report_request.populate(ios_device_id=request.json['ios_device_id'])
if 'questions' in request.json:
report_request.populate(questions=request.json['questions'])
questions = request.json['questions']
if 'more_questions' in request.json:
report_request.populate(more_questions=request.json['more_questions'])
more_questions = request.json['more_questions']
try:
report_request.put()
sender_address = "Scout Support <[email protected]>"
user_address = "[email protected]"
subject = "Update requested at %s" % request.json['name']
body = """Name: %s\nAddress: %s\nQuestions: %s\nMore Questions: %s""" % (request.json['name'], request.json['vicinity'], ', '.join(questions), more_questions)
logging.info('questions: %s', ', '.join(questions))
logging.info('more_questions: %s', more_questions)
mail.send_mail(sender_address, user_address, subject, body)
return jsonify(report_request.to_dict())
except CapabilityDisabledError:
abort(400)
示例2: create
def create(request):
if request.method=='POST':
name = request.POST['username']
email = request.POST['email']
sex = request.POST['sex']
mobile_number = request.POST['mobile_number']
exam_city = request.POST['exam_city']
current_city = request.POST['current_city']
exam_date = request.POST['exam_date']
if exam_date == '' or name == '' or email == '' or mobile_number == '' :
return render_to_response('share/create.html')
else :
new_obj = Users(name = name, email = email, sex = sex, mobile_number = mobile_number,exam_city_id = exam_city,exam_date = exam_date, current_city = current_city)
new_obj.save()
if "requested_to" in request.session:
obj = Request(requester = new_obj.id,requested_to = request.session["requested_to"])
obj.save()
del request.session["requested_to"]
return HttpResponseRedirect('/thanks/')
return HttpResponseRedirect('/thankyou/')
if "exam_city" in request.session:
return render_to_response('share/create.html',{'exists':1,'exam_date':request.session["exam_date"]})
return render_to_response('share/create.html',{'exists':0})
示例3: get
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}))
示例4: test_requests
def test_requests(self):
request = Request(path = "/foo")
request.save()
django_response = HttpResponse(self.text)
# No rules, should pass
self.assertEqual(len(check_request_rules(request, django_response)), 0)
# Should have one error now that the status is not 200
django_response.status_code = 442
self.assertEqual(len(check_request_rules(request, django_response)), 1)
# set it back for the rest of the tests
django_response.status_code = 200
self.assertEqual(len(check_request_rules(request, django_response)), 0)
rule1 = RequestRule(request = request, target = "content", operator = "contains", value = "Teletubbies")
rule1.save()
self.assertEqual(len(check_request_rules(request, django_response)), 0)
# add a rule that fails
rule2 = RequestRule(request = request, target = "content", operator = "!contains", value = "Teletubbies")
rule2.save()
self.assertEqual(len(check_request_rules(request, django_response)), 1)
# Done testing requests, now test functionality on the models that have been created
# str the request to test the __unicode__ method
str(request)
# Test the display_operator
self.assertEqual(rule2.display_operator, "does not contain")
rule2.operator='foo'
# Should not fail on unrecognized operator
self.assertEqual(rule2.display_operator, "foo")
示例5: get
def get(self, url):
ip = self.request.remote_addr #to prevent abuses, only a request every minute is served
request = Request.gql("where ip='%s'" % ip).get() #Look for request from the same IP address
if not request is None:
delta = request.is_allowed()
if delta > 0: #too little time has passed from the previous request
#self.error(408) #Timeout Error
self.response.set_status(408, "Your IP address has issued a request less than 1 min ago. Please wait %d seconds" % delta)
return
else:
request = Request(ip=ip, page_crawled=url)
request.save()
self.response.headers['Content-Type'] = 'application/json'
handler = CrawlerHandler()
site_image = memcache.get(url)
if site_image is None:
home_page = handler.start_crawling(url, MAX_PAGE_DEPTH, MAX_PAGES_TO_CRAWL, 0.01) #causes a little delay, but not too big (one 100th of a sec)
if home_page is None:
self.error(400) #Bad Request
return
else:
site_image = handler.page_graph(home_page)
memcache.set(url, site_image)
self.__responde(site_image)
示例6: test_login_as
def test_login_as(self):
user = User.objects.create_user(username = TEST_USER, password = TEST_PASS, email = TEST_USER)
request = Request(path = "/foo", login_as_user = user)
request.save()
response = create_django_response(request)
self.assertTrue(response.context["user"].is_authenticated())
示例7: process_request
def process_request(self, request):
method = request.method
path = request.path
time = datetime.now().strftime('%d/%b/%Y %H:%M:%S')
if not request.is_ajax() and path != '/requests/':
request = Request(method=method, path=path, time=time)
request.save()
示例8: requests
def requests():
'''Route to Requests Collection.'''
if ('past' == request.args.get('date')):
requests = Request.get_past_reqs()
else:
requests = Request.get_open_reqs()
user = g.user
return render_template('request/requests.html', requests=requests, user=user)
示例9: process_request
def process_request(self, request):
data = {}
data['Path'] = request.path
data['Method'] = request.method
data['Meta'] = str(request.META)
req = Request(request=data)
if request.user.is_authenticated():
req.priority = 1
req.save()
return None
示例10: get
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()
示例11: starting_page
def starting_page():
print 'Submitting a task'
r = Request()
r.name = 'Some random name'
db.session.add(r)
db.session.commit()
context = dict()
context['id'] = r.id
db.session.close()
db.session.remove()
run_workflow(context)
return ('Task submitted %r' % context['id']), 201
示例12: TakeRequest
def TakeRequest(request, url):
request_url = URL(url)
robj = Request.objects.filter(target__contains=request_url.host)
if not robj:
r = Request(request_type='HttpRequest', storage_type='UrlStorage',
action='mirror', target=request_url.host, flag='requested')
else:
r = robj[0]
r.flag = 'requested'
r.save()
return HttpResponseRedirect('http://%s/%s' % (getifip(web_server_interface), request_url.with_www().replace('http://', '')))
示例13: get_notifications
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"
示例14: api_view_request
def api_view_request(request_rid):
check_admin()
request = Request.find_by('where rid = ?', request_rid)
response = Response.find_by('where rid = ?', request_rid)
if request is None or response is None:
raise notfound()
return dict(request=content_escape(request), response=html_encode(response))
示例15: get
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')