def create_request(): form = RequestForm(request.form) if request.method == 'POST' and form.validate(): geolocation = getGeocodeLocation(form.location_string.data) newrequest = Request(user_id=login_session['id'], meal_type=form.meal_type.data, location_string=form.location_string.data, latitude=geolocation[0], longitude=geolocation[1]) session.add(newrequest) session.commit() date_request = parse_datetime(year=form.year.data, month=form.month.data, day=form.day.data) if date_request == None: flash('Date no valid...') return redirect(url_for('users.index')) newrequestdate = DateTimeRequest( request=newrequest.id, mealtime=form.meal_time.data, date=date_request) session.add(newrequestdate) session.commit() flash('Succefully!') return redirect(url_for('users.index')) flash_errors(form) return redirect(url_for('users.index'))
def render_request_done(): # Если данные не были отправлены if request.method != "POST": abort(404) # Если данные были отправлены form = RequestForm() if not form.validate_on_submit(): # отправляем форму назад return render_template('request.html', form=form) # получаем данные client_name = form.clientName.data client_phone = form.clientPhone.data client_goal = form.clientGoal.data client_time = form.clientTime.data time = next((t[1] for t in form.clientTime.choices if t[0] == client_time), -1) goal = Goal.query.filter(Goal.code == client_goal).scalar() request_t = Request(name=client_name, phone=client_phone, goal=goal.goal, time=time) db.session.add(request_t) db.session.commit() # переходим на request_done return render_template('request_done.html', clientName=client_name, clientPhone=client_phone, clientGoal=request_t.goal, clientTime=request_t.time)
def render_request(): form = RequestForm() goals = get_goals_for_request_form(GOALS_JSON_PATH) form.goal.choices = goals form.goal.default = goals[0][0] form.process() return render_template('request.html', form=form)
def index(): form = ContactForm() request_form = RequestForm() if form.validate_on_submit(): name = form.name.data body = form.body.data email = form.email.data send_mail(name, email, body) return redirect(url_for('index')) if request_form.validate_on_submit(): name = request_form.name.data email = request_form.email.data phone = request_form.email.data option = request_form.select.data reply_request(name, email, option) return redirect(url_for('index')) return render_template('index.html', form=form, request_form=request_form)
def post(request): """ Parameters: a: Action t: Type p: Parameters d: Data(Optional) Response: rc: Return code msg: message """ # initial the responsor request returnobj = default_returnobj.copy() form = RequestForm(request.POST, request.FILES) # Error handler if not form.is_valid(): returnobj['rc'] = 1 returnobj['msg'] = form.errors return HttpResponse(simplejson.dumps(returnobj)) p = form.cleaned_data['p'] # Get the uploaded file contents if form.cleaned_data.get('d'): # If the file is loaded with generic POST method d = form.cleaned_data['d'] mime_type = d.content_type file_name = p.get('file_name', 'untitiled.' + mime_type.split('/')[1]) else: returnobj['rc'] = 1 returnobj['msg'] = 'File(Parameter "d") is necessary by uploading' return HttpResponse(simplejson.dumps(returnobj)) # Get the phone info phone = None pi = p.get('phone_info') if pi: phone, create = PhoneInfo.objects.get_or_create(device_id = pi['device_id']) phone.model = pi.get('model') phone.android_version = pi.get('android_version') phone.phone_number = pi.get('phone_number') phone.save() # Save the data desc = p.get('desc') latitude, longitude = p.get('latitude'), p.get('longitude') data = Data.objects.create( phone = phone, file_name = file_name, mime_type = mime_type, desc = desc, ip_address = request.META['REMOTE_ADDR'], latitude = latitude, longitude = longitude, ) data.data.save(file_name, request.FILES['d']) data.save() data.generate_thumbnails() return HttpResponse(simplejson.dumps(returnobj))
def recipe(): form = RequestForm() if form.validate_on_submit(): recipe = sands_client.ask_for_recipe(form.rq_text.data) #request.values['rq_text'] return str('show_recipe.html', recipe=recipe) return render_template('home.html', form=form)
def request_page(): form_request = RequestForm() if form_request.validate_on_submit(): request_goal = int(form_request.request_goal.data) request_client_name = form_request.request_client_name.data request_client_tel = form_request.request_client_tel.data request_new = Request(name=request_client_name, phone=request_client_tel, goal_id=request_goal) db.session.add(request_new) db.session.commit() return redirect(url_for('search_result_page')) return render_template('pick.html', form_request=form_request)
def create_request(request): form = RequestForm(request.POST or None) num_req = Exchange.objects.filter(receiver=request.user.id).count() if num_req >= 1: messages.error(request, "Looks like you've already created a request") return redirect('/exchange/participate/dashboard') else: if request.POST and form.is_valid(): gift_request = form.gift_request(request) print "GIFT", gift_request return HttpResponseRedirect('/exchange/participate/dashboard') return render(request, 'exchange/participate/create_request.html')
def request_post(request): if request.method == "POST": form = RequestForm(request.POST) if form.is_valid(): redirect_to = resolve_url('/partime/manage/') user = get_user(request) form.save(user) return HttpResponseRedirect(redirect_to) else: form = RequestForm() return render(request, 'partime/request/request_post.html', {'form': form, 'url': 'partime:request_post'})
def render_request_done(): goals = get_goals_for_request_form(GOALS_JSON_PATH) form = RequestForm() form.goal.choices = goals if form.validate(): goals = read_json(GOALS_JSON_PATH) goal = form.goal.data time = form.time.data name = form.name.data phone = form.phone.data write_request_to_json(goal, time, name, phone, REQUESTS_JSON_PATH) return render_template('request_done.html', goal=goals[goal], time=time, name=name, phone=phone) return 'Данные не получены '
def add(request, employee_id): employee = get_object_or_404(Employee, pk=employee_id) if request.method == 'POST': form = RequestForm(request.POST) if form.is_valid(): new_entry = form.save(commit=False) new_entry.user = Employee.objects.get(pk=employee_id) new_entry.save() return HttpResponseRedirect(reverse('employees:detail', args=(employee_id,))) else: print "not valid - returning" form = RequestForm() return render(request, 'employees/add.html', {'form': form, 'employee': employee})
def request_update(request, id): user = get_user(request) user_info = get_user_info(user) instance = get_object_or_404(Request, id=id, employee=user_info) if request.method == "POST": form = RequestForm(request.POST, instance=instance) if form.is_valid(): redirect_to = resolve_url('/partime/manage/') form.save() return HttpResponseRedirect(redirect_to) else: form = RequestForm(instance=instance) return render(request, 'partime/request/request_post.html', {'form': form, 'url': 'partime:request_update', 'id': id})
def recover(): form = RequestForm(request.args) if form.validate(): email = form.email.data element = mongo.db.accounts.find_one({'email': email}) if element: username = element.get('username') email = element.get('email') return f"Dear {username}, this functionality is not implemented yet!", 202 else: return jsonify({"email": 'email not found'}), 400 else: return jsonify(form.errors), 404
def bid_request (request, template_name="alerts/alert-form.html"): page_title = 'Product Bid Request' if request.method =='POST': form = RequestForm (request.POST) if form.is_valid(): req = form.save(commit=False) req.user = request.user req.save() return HttpResponseRedirect('/request-success/') else: form = RequestForm() return render_to_response(template_name, locals(), context_instance = RequestContext(request))
def get(): form = RequestForm(request.args) if form.validate(): email = form.email.data current_user = get_jwt_identity() element = mongo.db.accounts.find_one({'email': email}) if element and current_user == element.get('username'): username = element.get('username') email = element.get('email') return jsonify(username=username, email=email) else: return jsonify({"email": 'email not found'}), 400 else: return jsonify(form.errors), 400
def render_request_done(): form = RequestForm() if not form.phone.data: return render_template( 'request.html', form=form, ) name = form.name.data phone = form.phone.data have_hours = form.have_hours.data goal = form.goal.data if Student.query.filter(Student.phone == phone).scalar(): student = Student.query.filter(Student.phone == phone).scalar() else: student = Student(name=name, phone=phone) db.session.add(student) db.session.commit() current_request = Request(student_id=student.id, goal=goal, have_time=have_hours) db.session.add(current_request) db.session.commit() return render_template( 'request_done.html', form=form, )
def search(): form = SearchForm() request_form = RequestForm() last_objects = list() if request.method == 'GET': stuff_key = unicode(request.args.get('stuff')).lower() address_key = unicode(request.args.get('address')).lower() last_objects = Stuff.query.join(Address).join(User).filter( Stuff.owner_id == User.id, User.approved == True, Stuff.approved == 1, Address.id == Stuff.address_id, Stuff.title.ilike('%' + stuff_key + '%'), Address.detail.ilike('%' + address_key + '%') ) return render_template( "search.html", user=current_user, last_objects=last_objects, form=form, request_form=request_form )
def home(): form = SearchForm() request_form = RequestForm() last_objects_shared = Stuff.query.join(User).filter( Stuff.approved == 1, Stuff.is_wanted == False, Stuff.owner_id == User.id, User.approved == True ).order_by(Stuff.id.desc()).limit(9) last_objects_wanted = Stuff.query.join(User).filter( Stuff.approved == 1, Stuff.is_wanted == True, Stuff.owner_id == User.id, User.approved == True ).order_by(Stuff.id.desc()).limit(9) return render_template( "index.html", user=current_user, last_objects_wanted=last_objects_wanted, last_objects_shared=last_objects_shared, form=form, request_form=request_form )
def confirmation_page(request): form = RequestForm() session = request.session csrf_token = session.get_csrf_token() if 'uc' not in request.session: request.session.flash('Please login to place request') return HTTPFound(location=request.route_url('login')) submitter_email = request.session['uniqueName'] + '@' + \ request.registry.settings['EMAIL_DOMAIN'] name = request.session['firstName'] + ' ' + request.session['lastName'] sender = request.registry.settings['mail.username'] message = Message(subject="Relay account setup", sender=sender, recipients=[sender, submitter_email]) message.body = make_msg_text(name, submitter_email, request.session['requestDetails'], form) message.html = make_msg_html(name, submitter_email, request.session['requestDetails'], form) mailer = get_mailer(request) mailer.send_immediately(message, fail_silently=False) return { 'csrf_token': csrf_token, 'name': name, 'form': form, 'requestDetails': request.session['requestDetails'] }
def render_request(): form = RequestForm() return render_template( 'request.html', form=form, )
def chat_request(): if current_user.Customer: flash('You do not have access to post to this resource', 'danger') abort(401) elif current_user.ServiceRep: form = RequestForm() if form.validate_on_submit: req = ChatRequest.query.get(form.requests.data) if req.Accepted: flash('This request has already been accepted', 'danger') return redirect(url_for('home')) else: req.Accepted = True chat_session = ChatSession(CustomerId=req.CustomerId, ServiceRepId=current_user.id, Topic=req.Topic) db.session.add(chat_session) db.session.commit() chat_session = ChatSession.query.filter_by( CustomerId=req.CustomerId, ServiceRepId=current_user.id, Topic=req.Topic).first() req.ChatSessionId = chat_session.id db.session.commit() return redirect(url_for('chat', id=chat_session.id)) else: abort(401)
def render_booking(id_teach, day_weekly, time): form = RequestForm() teacher_info = db.session.query(Teacher).get_or_404(id_teach) return render_template("booking.html", name_teacher=teacher_info.name, day=days[day_weekly], time=time, form=form)
def request_book(id): session = Session() trans = session.query(Transaction).filter(Transaction.book == id).first() if (trans.address_to): return redirect(url_for("listings")) form = RequestForm() if form.validate_on_submit(): address = form.streetNameNum.data + " " + form.city.data + ", " + form.state.data + " " + form.zipcode.data trans.address_to = address trans.buyer = current_user.user_id addressf = trans.address_from session.commit() return redirect(url_for("index")) # Very important, make sure to initialize the field of the OWNER's # associated user's ID after the post request. To be handled later return render_template('request_book.html', form=form)
def RequestSwapp(): email1 = globals()['cur_user'] if email1 == '': flash("Login as user to view schedule.") return redirect(url_for('login')) else: form = RequestForm() if form.validate_on_submit(): email, examid, date, time, slot = form.email.data, form.examid.data, form.date.data, form.time.data, form.slot.data if email != email1: print(email, examid, date, time, slot) res = RequestSwap(email1, email, examid, date, time, slot) flash(res) return redirect(url_for("RequestSwapp")) elif email == email1: flash("you can't enter your own email!") return redirect(url_for("RequestSwapp")) return render_template('request_swap.html', form=form, ddtext='Request Swap')
def make_request(): form = RequestForm() if request.method == 'GET': return render_template('request.html', form=form) if request.method == 'POST': form = RequestForm() if form.validate_on_submit(): tr = TeacherRequest(goal=form.goals.data, availability=form.availability.data, clientName=form.clientName.data, clientPhone=form.clientPhone.data) db.session.add(tr) db.session.commit() return render_template('request_done.html', goal=tr.goal, availability=tr.availability, clientName=tr.clientName, clientPhone=tr.clientPhone) return render_template('request.html', form=form)
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 get(self): args = parser.parse_args() amount = args.get('amount') form = RequestForm('1HfMPfrRJVrcPygFRoBgt7WgA9iiefmvC9', amount, multiple='on') if form.errors == {}: seeder = controller.generate_receiver_for_seeding(amount) resp = {'address': seeder, 'amount': amount} return resp, 201 else: return form.errors, 400
def render_booking_done(): form = RequestForm() if request.method == 'POST': booking = Booking(name=form.client_teacher.data, day=form.client_weekday.data, time=form.client_time.data, name_user=form.name.data, phone_user=form.phone.data) db.session.add(booking) db.session.commit() return render_template("booking_done.html", form=form) return render_template("request.html", form=form)
def request_form(request): ''' Generates and processes request form. ''' csrf_token = request.session.get_csrf_token() if 'uc' in request.session: uc = request.session['uc'] else: try: request.session['uc'] = uc = appContext.create_user_context( result_uri=request.url, host=request.registry.settings['LMS_HOST'], encrypt_requests=request.registry.settings['ENCRYPT_REQUESTS']) except KeyError: request.session.flash('Please login.') return HTTPFound(location=request.route_url('login')) user_data = get_user_data(uc, request) store_user_data(request.session, user_data) code = get_semester_code() request.session['course_list'] = get_courses(uc, code, request) form = RequestForm(request.POST) form.course.choices = get_course_choices(request.session['course_list'], request) if form.course.choices == []: request.session.flash( 'No courses were found in D2L for this semester. \ Please log into D2L to confirm you have classes this semester.') return {'form': form, 'csrf_token': csrf_token} if 'form_submit' in request.POST and form.validate(): process_form(form, request.session) return HTTPFound(location=request.route_url('confirmation')) else: return {'form': form, 'csrf_token': csrf_token}
def render_request(): form = RequestForm() goals = db.session.query(Goal).all() choices = [(str(goal.id), goal.description) for goal in goals] form.goal.choices = choices form.goal.data = choices[0][0] if request.method == "POST": if form.validate_on_submit(): goal_id = form.goal.data goal = db.session.query(Goal).get_or_404(goal_id) time = form.time.data name = form.name.data phone = form.phone.data lesson_request = Request(goal=goal, goal_id=goal_id, time=time, name=name, phone=phone) db.session.add(lesson_request) db.session.commit() return render_template('request_done.html', goal=goal, time=time, name=name, phone=phone) return render_template('request.html', form=form)
def show_request(): form = RequestForm() if form.validate_on_submit(): goal = form.goal.data time = form.time.data name = form.name.data phone = form.phone.data new_request = Request(time=time, client_id=check_client(name, phone), goal_id=goal) goal_name = form.goal.choices[int(goal) - 1][1] db.session.add(new_request) db.session.commit() return render_template("request_done.html", goal=goal_name, time=have_time[time], name=name, phone=phone) return render_template("request.html", form=form)
def render_done(): form = RequestForm() if request.method == 'POST': req = Request(goal=form.goal.data, name_user=form.name.data, phone_user=form.phone.data, free_time=form.free_time.data) db.session.add(req) db.session.commit() return render_template("request_done.html", form=form, goals=get_goals_id_dict()) return render_template("request.html", form=form)
def request_form(request): ''' Generates and processes request form. ''' csrf_token = request.session.get_csrf_token() if 'uc' in request.session: uc = request.session['uc'] else: try: request.session['uc'] = uc = appContext.create_user_context( result_uri=request.url, host=request.registry.settings['LMS_HOST'], encrypt_requests=request.registry.settings['ENCRYPT_REQUESTS']) except KeyError: request.session.flash('Please login.') return HTTPFound(location=request.route_url('login')) user_data = get_user_data(uc, request) store_user_data(request.session, user_data) code = get_semester_code() request.session['course_list'] = get_courses(uc, code, request) form = RequestForm(request.POST) form.course.choices = get_course_choices(request.session['course_list'], request) if form.course.choices == []: request.session.flash('No courses were found in D2L for this semester. \ Please log into D2L to confirm you have classes this semester.') return {'form': form, 'csrf_token': csrf_token} if 'form_submit' in request.POST and form.validate(): process_form(form, request.session) return HTTPFound(location=request.route_url('confirmation')) else: return {'form': form, 'csrf_token': csrf_token}
def render_request(): form = RequestForm() goals = Goal.query.order_by(Goal.id) form.goal_id.choices = [(str(goal.id), goal.value) for goal in goals] goals = Goal.query.order_by(Goal.id).all() if request.method == 'POST' and form.validate_on_submit(): lesson_request = RequestLesson() form.populate_obj(lesson_request) db.session.add(lesson_request) db.session.commit() client_name = form.client_name.data client_phone = form.client_phone.data goal = list(filter(lambda x: x.id == int(form.goal_id.data), goals))[0].value free_time = form.free_time.data free_time = free_time + ' часа в неделю' if free_time == '1-2' else free_time + ' часов в неделю' return render_template('request_done.html', goal=goal, free_time=free_time, name=client_name, phone=client_phone) return render_template('request.html', form=form)
def request_done_view(): form = RequestForm() if form.validate_on_submit(): goal = form.goal.data time = form.time.data name = form.name.data phone = form.phone.data # Create and update request.json db_manager('request', [{ 'name': name, 'phone': phone, 'goal': goal, 'time': time }]) return render_template('request_done.html', goals=goals, goal=goal, time=time, name=name, phone=phone) else: return redirect(url_for('request_view', form=form))
def requests(): ##Create and Submit Requests form = RequestForm() if request.method == 'POST': ## If the form is not valid, then load the request template. if form.validate() == False: return render_template('request.html', form=form) else: ##get data from the form, hardcoded some fill-ins. newRequest = serviceRequest(form.address.data, form.zipcode.data, form.service_code.data, form.service_name.data, random.randint(100, 150), form.description.data, "Open", "N/A", form.request_date.data, "03-07-17", "03-09-17", "Pothole Fillers Inc.") db.session.add(newRequest) ##Add it to the database db.session.commit() return "Request Submitted!" ##Change to suitable page. elif request.method == 'GET': return render_template('request.html', form=form)
def render_request_done(): if request.method == "GET": return redirect("/request/") form = RequestForm() if form.validate_on_submit(): goal_abb = form.goal.data goal = db.session.query(Goal).filter(Goal.name_abb == goal_abb).first() time = form.time.data name = form.clientName.data phone = form.clientPhone.data s.request_successful(name, phone, goal, time) return render_template("request_done.html", name=name, phone=phone, time=time_week[time], goal=goal.name, title="Запрос отправлен!") return render_template("request.html", form=form, title="Подбор преподавателя")
def request_form(request): session = request.session csrf_token = session.get_csrf_token() print("CSRF", csrf_token) if 'uc' in session: print("looping if") uc = session['uc'] else: print("looping else") try: session['uc'] = uc = appContext.create_user_context( result_uri=request.url, host=request.registry.settings['LMS_HOST'], encrypt_requests=request.registry.settings['ENCRYPT_REQUESTS']) except KeyError: session.flash('Please login.') return HTTPFound(location=request.route_url('login')) user_data = get_user_data(uc, request) store_user_data(session, user_data) code = get_semester_code() session['course_list'] = get_courses(uc, code, request) form = RequestForm(request.POST) form.course.choices = get_course_choices(session['course_list']) if form.course.choices == []: session.flash('No courses were found in D2L for this semester. \ Please <a href="http://www.uwosh.edu/d2lfaq/d2l-login">log into \ D2L</a> to confirm you have classes in D2L.') return {'form': form, 'csrf_token': csrf_token} print request.scheme #CHECKING FOR HTTPS if request.method == 'POST' and form.validate(): process_form(form, session) ''' embed = 'no' if form.embed.data: embed = 'yes' download = 'no' if form.download.data: download = 'yes' share = 'no' if form.share.data: share = 'yes' training = 'no' if form.training.data: training = 'yes' session['requestDetails'] = { 'courseId' : str(form.course.data), 'embed' : embed, 'download' : download, 'share' : share, 'training' : training, 'location' : form.location.data, 'courseName' : form.courseName.data, 'comments' : form.comments.data, 'expiration' : form.expiration.data } ''' return HTTPFound(location=request.route_url('confirmation')) else: return {'form': form}
def make_request(stuff_id=None): form = RequestForm() message = None return_url = request.form['return_url'] if form.validate_on_submit(): message = form.message.data stuff_id = form.stuff_id.data duration = int(form.duration.data) unit = int(form.unit.data) address = Address.query.filter(Address.user_id == current_user.id).first() if address: if stuff_id is None or not (stuff_id > ''): flash(u'İstek gönderilemedi.') return redirect(return_url) stuff = Stuff.query.filter(Stuff.id == stuff_id).first() if stuff.is_wanted == True: user = stuff.owner from_user = current_user else: user = current_user from_user = stuff.owner new_request = Request( stuff_id=stuff_id, user_id=user.id, from_user_id=from_user.id, duration=(duration * unit) ) db.session.add(new_request) new_conversation = Conversation( title='%s' % stuff.title, users=[current_user, stuff.owner], request=new_request ) db.session.add(new_conversation) new_message = Message( from_user=current_user, to_user=stuff.owner, conversation=new_conversation, txt=message ) db.session.add(new_message) db.session.commit() msg_body = render_template('email/request.txt', to_user=user, from_user=from_user, stuff=stuff, conversation_url=new_conversation.url) html_msg = render_template('email/request.html', to_user=user, from_user=from_user, stuff=stuff, conversation_url=new_conversation.url) if stuff.is_wanted: msg_subject = u"%s sana %s ödünç vermek istiyor" % (from_user.name, stuff.title) else: msg_subject = u"%s için bir talip var!" % stuff.title msg = MailMessage( body=msg_body, html=html_msg, subject=msg_subject, sender=(u"Eşya Kütüphanesi", "*****@*****.**"), recipients=[stuff.owner.email] ) mail.send(msg) return redirect(url_for('my_messages')) else: flash(u'Ödünç istemek için adres girmelisin.') return redirect(url_for('new_address')) else: flash(u'İstek gönderilemedi. Kaç gün için ödünç istediğini girmelisin.') return redirect(return_url)