def create_request(): print(request.form) valid = Requests.submit_request(request.form) if not valid: return render_template('partials/errors.html') else: Requests.add_request(request.form) return "success"
def process_request(self, request): if request.is_ajax(): pass else: save_request = Requests(request=request, pub_date=t.now() + t.timedelta(hours=3), path=request.build_absolute_uri()) return save_request.save()
def process_response(self, request, response): if request.is_ajax(): pass else: http_req = Requests(path=request.build_absolute_uri(), req_time=timezone.now(), method=request.method, status=response.status_code) http_req.save() return response
def viewInfoAboutMyself(request): about = User.objects.all() contacts = Contacts.objects.all() obj = Requests.objects.all() num = len(obj) if request.method == 'POST': d = Requests(num + 1, text = request.POST['text']) d.save() requestData = Requests.objects.order_by('-id')[:10] return HttpResponseRedirect('/', {'about': about, 'contacts': contacts, 'requestData': requestData}) elif request.method == 'GET': requestData = Requests.objects.order_by('-id')[:10] return render_to_response('infopage.html', {'about': about, 'contacts': contacts, 'requestData': requestData})
def test_command_output(self): """ Testing command """ req = Requests(request='request', pub_date=t.now() + t.timedelta(hours=3), path='/' ) req.save() out = StringIO() # flake8: noqa call_command('model_list', stderr=out) self.assertIn('apps.hello.models.Requests', out.getvalue())
def logrequest(): #import pdb; pdb.set_trace() if request.method == "POST": form = { 'title': request.form['reqtitle'], 'body' : request.form['reqmessage'], } logs = Requests(**form) logs.save() return redirect(url_for('showlogs')) return render_template ('logrequest.html') flash('Your request has been logged.')
def viewRequests(): from flask import request if request.method == "POST": listOfApprovedBookings = [int(x) for x in request.form.getlist("approval")] for request_id in listOfApprovedBookings: Requests.edit(request_id) request = Requests.query.filter_by(request_id=request_id).first() confirmMessage = "Booking details: " + "\nRoom: " + request.room + "\nDay: " + request.day + "\nTime: " + request.time ping("Request ID: " + str(request_id) + " approved", confirmMessage) return redirect(url_for('viewRequests')) allRequests = Requests.query.all() allRequests.reverse() return render_template('requestsTable.html', allRequests=allRequests)
def request(): rooms = Rooms.query.all() rooms_list = [(-1, 'No Preference')] for room in rooms: rooms_list.append((room.room_id, room.name)) form = RequestForm() form.room.choices = rooms_list if form.validate_on_submit(): username = current_user.get_id() Requests.insert(requestee=username, room= dict(form.room.choices)[form.room.data], day=dict(form.day.choices)[form.day.data], time=dict(form.time.choices)[form.time.data]) return redirect(url_for("home")) return render_template("request.html", form=form)
def requests(receiver=None): if request.method == "POST": receiver = int(receiver) req = Requests(session["user"], receiver) db.session.add(req) db.session.commit() return redirect("/page/" + str(receiver)) reqs = Requests.query.filter_by(user_2=session["user"]).all() senders = [] for i in reqs: one = Users.query.get(i.user_1) senders.append(one) return render_template("requests.html", reqlist=senders)
def request_done(): goal = request.args.get('goal') time = request.args.get('time') clientName = request.args.get("clientName") clientPhone = request.args.get("clientPhone") with app.app_context(): db.create_all() new_request = Requests(goal=goal, time=time, clientName=clientName, clientPhone=clientPhone) db.session.add(new_request) db.session.commit() return render_template("request_done.html", goal=study_goals['goals'][goal], time=time, clientName=clientName, clientPhone=clientPhone)
def fit(): """ Form submit of meds :return: """ form = MedForm(request.form) if request.method == 'POST' and form.validate(): zipcode = form.zipcode.data # Check the zipcode plan = form.plan.data medication = form.medication.data ip = str(request.environ.get('HTTP_X_REAL_IP', request.remote_addr)) rq = Requests(**dict(user=current_user.id, ip=ip, zipcode=zipcode, plan=plan, drug=medication)) rq.save() # Process either medicare or medicaid plan_type = form.plan_type.data try: if plan_type == 'medicare': table = get_medicare_plan(medication, plan, zipcode) else: table = get_medicaid_plan(medication, plan, zipcode, plan_type) except tools.BadPlanName as e: form.errors['plan_name'] = str(e) context = {'form': form} html = 'fit.html' except tools.BadLocation as e: form.errors['zipcode'] = str(e) context = {'form': form} html = 'fit.html' else: # You have to order the data in a list or it won't show right data = [] for item in table['data']: row = [item[h] for h in table['heading']] data.append(row) context = { 'data': data, 'head': table['heading'], 'drug': medication, 'pa': table['pa'], 'zipcode': zipcode, 'plan': plan, 'plan_type': form.plan_type.data, } html = 'table.html' # If its a GET see if parameters were passed else: if request.method == 'GET': form.zipcode.data = request.args.get('zipcode', "") form.plan.data = request.args.get('plan', "") form.medication.data = request.args.get('drug', "") form.plan_type.data = request.args.get('plan_type', "medicare") # a POST with errors elif form.errors: if 'plan_type' in form.errors: form.errors[ 'plan_type'] = "Please pick a Medicare, Medicaid, or Private plan" context = {'form': form} html = 'fit.html' content = render_template(html, **context) return content
def process_request(self, request): if request.is_ajax(): return None save_request = Requests(request=request, path=request.build_absolute_uri()) return save_request.save()
def get_requests(): if request.method == "POST": requests = Requests() requests.id = request.json.get("id") requests.id_commune = request.json.get("id_commune") requests.request_status = request.json.get("request_status") requests.full_name = request.json.get("full_name") requests.last_name = request.json.get("last_name") requests.contact_phone = request.json.get("contact_phone") requests.address = request.json.get("address") requests.date = request.json.get("date") requests.hour = request.json.get("hour") db.session.add(requests) db.session.commit() return jsonify(requests.serialize_all_fields()), 200 if request.method == "GET": requests = Requests.query.all() requests = list(map(lambda request: request.serialize_strict(), requests)) return jsonify(requests), 200
def post_volume(self, volume_group_reference, name): url = '{}/volumes'.format(self.base_url) payload = Requests.CreateVolumeRequest(volume_group_reference, name) return self.session.post(url, json=vars(payload))
# For each station for station in Stations.query.all(): # Request page with all schedule data for that station url = 'http://dv.njtransit.com/mobile/tid-mobile.aspx?sid=' + station.abbr request_time = time.time() trains_page = requests.get(url) request_time = time.time() - request_time trains_tree = html.document_fromstring(trains_page.text) # Scrape stations for elem in trains_tree.xpath('//table'): if len(elem.getchildren()) == 1 and len( elem.getchildren()[0].getchildren()) == 6: values = [ re.sub('[^a-zA-Z0-9- :_*.]', '', x.text_content().strip()) for x in (elem.getchildren()[0].getchildren()) ] schedule = Schedule(values[0], values[1], values[2], values[3], values[4], values[5]) station.schedules.append(schedule) print values db.session.add(Requests(url, request_time, version)) db.session.commit() print "Success."
def post_storage_pool(self, drive_id_list): payload = Requests.CreateStoragePoolRequest(drive_id_list) url = '{}/storage-pools'.format(self.base_url) return self.session.post(url, json=vars(payload))