本文整理汇总了Python中models.Request类的典型用法代码示例。如果您正苦于以下问题:Python Request类的具体用法?Python Request怎么用?Python Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:kcmoffat,项目名称:bumpn-backend,代码行数:31,代码来源:views.py
示例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})
开发者ID:avinashbangar,项目名称:student-partner-service,代码行数:27,代码来源:views.py
示例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}))
开发者ID:Qiwis,项目名称:foodie,代码行数:27,代码来源:main.py
示例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")
开发者ID:gorillamania,项目名称:django-url-watcher,代码行数:35,代码来源:tests.py
示例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)
开发者ID:mlarocca,项目名称:V-rawler,代码行数:34,代码来源:v-rawler.py
示例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())
开发者ID:gorillamania,项目名称:django-url-watcher,代码行数:8,代码来源:tests.py
示例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()
开发者ID:atmaramaman,项目名称:FortyTwoTestTask,代码行数:8,代码来源:middleware.py
示例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)
开发者ID:kevana,项目名称:ummbNet,代码行数:8,代码来源:views.py
示例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
开发者ID:razumov,项目名称:42test,代码行数:10,代码来源:middleware.py
示例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()
开发者ID:Qiwis,项目名称:foodie,代码行数:12,代码来源:confirmed_requests.py
示例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
开发者ID:httpPrincess,项目名称:celery-flask-problem,代码行数:13,代码来源:views.py
示例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://', '')))
开发者ID:Murodese,项目名称:CANDICE,代码行数:13,代码来源:views.py
示例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"
开发者ID:Qiwis,项目名称:foodie,代码行数:50,代码来源:foodie_requests.py
示例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))
开发者ID:akz747,项目名称:NagaScan,代码行数:7,代码来源:urls.py
示例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')
开发者ID:Qiwis,项目名称:foodie,代码行数:32,代码来源:foodie_requests.py
示例16: get
def get(self, id):
try:
currentRequest = Request.get(id = id)
except peewee.DoesNotExist:
abort(404, message="Request {} doesn't exist".format(args.request_id))
return currentRequest
开发者ID:happymap,项目名称:UberChallenge,代码行数:7,代码来源:ApiRequest.py
示例17: update_request
def update_request(id):
user = g.user
if not request.json:
abort(400)
errors = Request.validate(request.json)
if len(errors) == 0:
return jsonify( { 'result': True } )
return jsonify({"message": "The request is invalid."},errors = [error for error in errors]) ,400
开发者ID:anilramdeo,项目名称:Assignment2_Meet_n_Eat,代码行数:9,代码来源:views.py
示例18: local_search
def local_search(request, place_type):
if request.GET.get('coords', ''):
form = SearchForm(request.GET)
if form.is_valid():
(lat,lon) = form.cleaned_data['coords'].split(',')
search_point = Point(float(lat),float(lon))
r = Request(point=search_point, place_type=place_type)
r.save()
places = Place.objects.distance(search_point).filter(place_type=place_type).filter(point__distance_lte=(search_point, distance(mi=2))).order_by('distance')
return render_to_response('_local_search.html', {
'title': place_type,
'places': places
})
else:
form = SearchForm()
return render_to_response('search.html', {
'form': form,
})
开发者ID:eknuth,项目名称:pimh,代码行数:19,代码来源:views.py
示例19: lookup
def lookup(request):
if request.GET.get('coords', ''):
form = SearchForm(request.GET)
if form.is_valid():
(lat,lon) = form.cleaned_data['coords'].split(',')
pnt=Point(float(lat),float(lon))
n = get_neighborhood_by_point(pnt)
r = Request(point=pnt, place_type="neighborhood")
r.save()
search_response = {'name': n.name.title(), 'polygon': n.gpoly(),
'slug': n.slug, 'wiki': n.wiki,
'centroid_x': "%.5f" % n.poly.centroid.x,
'centroid_y': "%.5f" % n.poly.centroid.y}
return HttpResponse(simplejson.dumps(search_response),
mimetype='application/json')
else:
form = SearchForm()
return render_to_response('search.html', {
'form': form,
})
开发者ID:eknuth,项目名称:pimh,代码行数:21,代码来源:views.py
示例20: post
def post(self):
args = request_parser.parse_args()
try:
currentRequest = Request.get(id = args.request_id)
currentRequest.current_latitude = args.current_latitude
currentRequest.current_longitude = args.current_longitude
currentRequest.save()
except peewee.DoesNotExist:
abort(404, message="Request {} doesn't exist".format(args.request_id))
return currentRequest.id, 200
开发者ID:happymap,项目名称:UberChallenge,代码行数:12,代码来源:ApiRequest.py
注:本文中的models.Request类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论