本文整理汇总了Python中models.Request.save方法的典型用法代码示例。如果您正苦于以下问题:Python Request.save方法的具体用法?Python Request.save怎么用?Python Request.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Request
的用法示例。
在下文中一共展示了Request.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_requests
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
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")
示例2: create
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
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
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
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)
示例4: test_login_as
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [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())
示例5: process_request
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
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()
示例6: process_request
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
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
示例7: home
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
def home(request):
if request.method == 'POST':
song_req = Request()
song_req.user = request.POST.get('user', '')
song_req.song = request.POST.get('song', '')
song_req.message = request.POST.get('message', '')
song_req.save()
else:
req = get_latest_request()
listeners = get_listeners()
title = get_title()
return render_to_response('home.html', {'latest':req, 'listeners':listeners, 'title':title})
示例8: TakeRequest
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
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://', '')))
示例9: profile_edit
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
def profile_edit(request, l):
error_msg = None
me = l.get_ldap_node(request.session['ldap_binddn'])
if request.method == 'POST':
f = ProfileForm(request.POST)
if f.is_valid():
me.displayName = f.cleaned_data['name']
me.cn = f.cleaned_data['nick']
me.save()
passwd_new = f.cleaned_data['passwd']
email_new = f.cleaned_data['email']
if passwd_new:
me.set_password(passwd_new)
request.session['ldap_passwd'] = passwd_new
if email_new != str(me.mail):
req = Request()
req.type = Request.EMAIL
req.uid = me.uid
req.email = email_new
req.save()
t = loader.get_template('accounts/email_email_request')
c = Context({
'name': me.displayName,
'url': request.build_absolute_uri(
reverse(process, kwargs={ 'token': req.token })),
'expire_in': settings.REQ_EXPIRE_STR,
})
send_mail(u'Confirmation email FedeRez', t.render(c), settings.EMAIL_FROM,
[req.email], fail_silently=False)
return HttpResponseRedirect('/')
else:
f = ProfileForm(label_suffix='', initial={ 'email': me.mail,
'name': me.displayName,
'nick': me.cn })
c = { 'form': f,
'name': me.displayName,
'nick': me.cn,
'email': me.mail,
'error_msg': error_msg, }
c.update(csrf(request))
return render_to_response('accounts/edit.html', c,
context_instance=RequestContext(request))
示例10: process_request
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
def process_request(self, request):
path_info = request.META['PATH_INFO']
exlude_list = [reverse('request-counter'),
reverse('admin:jsi18n'),
settings.MEDIA_URL,
settings.STATIC_URL]
if not any(url in path_info for url in exlude_list):
new_http_request = Request()
new_http_request.method = request.META['REQUEST_METHOD']
new_http_request.path_info = path_info
new_http_request.server_protocol = request.META['SERVER_PROTOCOL']
new_http_request.viewed = False
new_http_request.save()
示例11: local_search
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
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,
})
示例12: get_or_create_request
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
def get_or_create_request():
'''
Returns a request instance that is global for this request
If this function is called outside of a web request then the user_name is marked as system
'''
thread_ident = thread.get_ident()
request, rq = STATE.get(thread_ident, (None, None))
if not rq:
rq = Request()
if request:
rq.request_path = request.path
if request.user.is_anonymous():
rq.user_name = u'(Anonymous)'
else:
rq.user_pk = request.user.pk
rq.user_name = unicode(request.user)[:255]
else:
rq.user_name = u'(System)'
rq.save()
STATE[thread_ident] = (request, rq)
return rq
示例13: lookup
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
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,
})
示例14: services
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
def services(request):
r = Request(request_method=request.method,
request_path=request.path,
request_accept=request.META['HTTP_ACCEPT'],
request_body=request.body)
try:
action = Action.objects.get(request_method=request.method,
request_path=request.path,
request_accept=request.META['HTTP_ACCEPT'])
except ObjectDoesNotExist:
r.response_status_code = 404
r.save()
return HttpResponse(status=404)
else:
r.response_status_code = action.response_status_code
r.response_content = action.response_content
r.response_content_type = action.response_content_type
r.save()
return HttpResponse(status=action.response_status_code,
content=action.response_content,
content_type=action.response_content_type)
示例15: process
# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import save [as 别名]
def process(request):
if request.method == 'POST':
form = UploadedFileForm(request.POST, request.FILES)
if form.is_valid():
motive = form.cleaned_data["motive"]
instances_used = form.cleaned_data["instance_num"]
seed_content = request.FILES['file'].read()
fetcher = Fetcher("fetch_queue", instances_used)
instances_ids = fetcher.fetch(seed_content)
#Could not parse directly from form because of the file
req_model = Request()
req_model.motive = motive
req_model.instances_used = instances_used
req_model.user = request.user
req_model.content = seed_content
req_model.instances_ids = json.dumps(instances_ids)
req_model.save()
return HttpResponseRedirect("/process/%d" % req_model.id)