def blast(): form = InputForm() title = "Blast - " try: with open('content/blast_page.md', encoding='utf-8') as c: name = get_title(c) next(c) c = c.read() except Exception: abort(404) if request.method == 'POST': sequence = request.form.get('id_sequences') file = request.form.get('id_file_text') function = request.form.get('job') print(file) if form.validate() == False: flash('All fields are required.') return render_template('blast.html', content=to_md(c), name=name, form=form, title=title, description="") elif sequence == "" and file == "": flash('You need to at least have one input.') return render_template('blast.html', content=to_md(c), name=name, form=form, title=title, description="") elif sequence != "" and file != "": flash('You can only have one input.') return render_template('blast.html', content=to_md(c), name=name, form=form, title=title, description="") else: if sequence != "" and file == "": query = sequence elif sequence == '' and file != '': query = file if function == 'blastp': records = blastp(query) elif function == 'blastx': records = blastx(query) return render_template('result_blastp.html', records=records, title=title, description="") elif request.method == 'GET': return render_template('blast.html', content=to_md(c), name=name, form=form, title=title, description="")
def submit(): global resp form = InputForm() if form.validate_on_submit(): resp = get_atis(form.icao) return redirect('/success', ) return render_template('submit.html', form=form)
def input(): form = InputForm() if form.validate_on_submit(): character_name = {form.character_name.data} return redirect(url_for('output', character_name=character_name)) return render_template('input.html', title='Enter Data', form=form)
def input_item(): form = InputForm() if form.validate_on_submit(): filename = 'default.jpg' f = form.Item_icon.data if f: filename = secure_filename(f.filename) f.save(os.path.join('static\icons', filename)) item = Item(Category=form.Category.data, Item_Title=form.Item_Title.data, Item_Description=form.Item_Description.data, Item_Price=form.Item_Price.data, image_file=url_for('static', filename='icons/' + filename)) print(url_for('static', filename='icons/' + filename)) print(item.image_file) db.session.add(item) db.session.commit() flash( f'you have added your last item with product id {item.id} successfully', 'success') return redirect(url_for('home')) Errors = [] fields = [] if form.errors: fields = form.errors.keys() Errors = form.errors.values() return render_template('input_item.html', form=form, errors=Errors)
def main(): form = InputForm() amr = request.args.get('amr') model = request.args.get('model') sent = None if form.validate_on_submit(): sent = amrtotext.run(form.input_amr.data, form.input_amr.model) elif amr is not None: sent = amrtotext.run(amr, model) if sent is not None: app.logger.info('Input: ' + amr) link = "http://bollin.inf.ed.ac.uk:9020/amrtotext?model=" + model + "&amr=" + "+".join( [t for t in amr.split()]) return jsonify( { 'sent': sent.replace("\n", "<br/>").replace(" ", " "), 'link': link }, sort_keys=True, indent=4, separators=(',', ': ')) else: return jsonify({ 'sent': 'ERROR', 'link': '' }, sort_keys=True, indent=4, separators=(',', ': '))
def get_profile(request): form = InputForm(request.GET) if not form.is_valid(): error_msg = "" for k, v in form.errors.items(): error_msg += "%s: %s\n" % (k, ", ".join(v)) return HttpResponse(json.dumps({ 'success': False, 'msg': error_msg }), content_type="application/json") subscriber_id = form.cleaned_data['userName'] transaction_id = form.cleaned_data['transactionId'] free_quota = form.cleaned_data['freeQuota'] pcrf_client = PCRFClient() profile_result = pcrf_client.get_profile(subscriber_id=subscriber_id, free_quota=free_quota) logger.debug("Getting profile for user (%s), transaction id: (%s)", subscriber_id, transaction_id) if not profile_result['action_result']: response = { 'success': True if profile_result.get('action_error_message').endswith( "does not exist") else profile_result['action_result'], 'msg': profile_result.get('action_error_message'), } if 'not_exist' in profile_result: response['not_exist'] = profile_result['not_exist'] log_action(inspect.stack()[0][3], request, response, transaction_id=transaction_id) return HttpResponse(json.dumps(response), content_type="application/json") topups_result = pcrf_client.get_services(subscriber_id, service_type='topup', free_quota=free_quota) response = { 'success': True if topups_result.get('action_error_message', '').endswith("does not exist") else topups_result['action_result'], 'msg': topups_result.get('action_error_message'), 'profile': profile_result.get('profile'), 'topups': topups_result.get('services') } log_action(inspect.stack()[0][3], request, response, transaction_id=transaction_id) return HttpResponse(json.dumps(response), content_type="application/json")
def index(): form = InputForm() if form.validate_on_submit(): session['session_id'] = unicode(uuid4()) session['state'] = form.state.data session['age'] = form.age.data session['zipcode'] = form.zipcode.data session['health'] = form.health.data session['income'] = form.income.data session['hhsize'] = form.hhsize.data if session['income'] and session['hhsize']: caps = CalcAcaSubsidy(session['income'], session['hhsize']) if caps: session['premium_cap'] = int(caps[1]) else: session['premium_cap'] = 0 else: session['premium_cap'] = 0 session['query_weights'] = get_weights(session['state'], str(session['health'])) log_query( session_id = session['session_id'], state = session['state'], age = session['age'], zipcode = session['zipcode'], health = session['health'] ) return redirect(url_for('main.results')) return render_template('index.html', form=form)
def tan(request): t = None # initial value of result if request.method == 'POST': form = InputForm(request.POST) if form.is_valid(): form = form.save(commit=False) radianos = form.radianos t = calculate_tan(radianos) else: form = InputForm() return render_to_response('tan.html', { 'form': form, 't': '%.5f' % t if isinstance(t, float) else '' }, context_instance=RequestContext(request))
def index(): if request.method == 'GET': return render_template('index.html', params=None) if request.method == 'POST': if request.form['action'] == 'make': form = InputForm(request.form) if form.validate(): params = { 'minstr': form.data['minstr'], 'start_date': form.data['start_date'].strftime('%Y-%m-%d'), 'finish_date': form.data['finish_date'].strftime('%Y-%m-%d') } unique_incidents = get_query_results('query_1.sql', params) chart_data = get_query_results('query_2.sql', params) incidents_by_persons = get_query_results('query_3.sql', params) incidents_by_roads = get_query_results('query_4.sql', params) labels = [x['Caption'] for x in chart_data] values = [x['ver'] for x in chart_data] return render_template( 'index.html', unique_incidents=unique_incidents, labels=labels, values=values, incidents_by_persons=incidents_by_persons, incidents_by_roads=incidents_by_roads, params=params) else: errors = form.errors return render_template('error.html', errors=errors)
def submitform(): form = InputForm() user_id = current_user.id user_kategori_wbs = current_user.kategori_wbs user_wbs_spesifik = current_user.wbs_spesifik if request.method == 'POST': file_name = files.save(form.upload_file.data) file_url = files.url(file_name) new_post = Post(user_id=user_id, post_kategori_wbs=user_kategori_wbs, post_wbs_spesifik=current_user.wbs_spesifik, post_wbs_level2=form.select_wbs_level2.data, post_wbs_level3=form.select_wbs_level3.data, post_judul=form.judul.data, post_deskripsi=form.deskripsi.data, post_jenis_toppgun=form.select_jenis_toppgun.data, post_kategori_lean=form.select_kategori_lean.data, post_file_url=file_url, post_wbs_terkait=form.sebutkan.data, post_date=datetime.now()) db.session.add(new_post) db.session.commit() return redirect('profile') return render_template('profile.html', form=form)
def index(): form = InputForm() #if request.method == 'POST' and form.validate(): if request.method == 'POST': if validate_date(request.form['date']) != 0: #datetime_object = datetime.strptime(request.form['date'], '%Y-%m-%d') print(request.form['city']) print(request.form['date']) city = request.form['city'] date = request.form['date'] if city in image_cities: file = 'images/' + city + '.jpg' table1 = 'images/' + city + ' Temp.jpg' table2 = 'images/' + city + ' Combo.jpg' table3 = 'images/' + city + ' Humidity.jpg' all_images = [file, table1, table2, table3] else: file = 'images/default.jpg' all_images = [file, file, file, file] results = predict_all_attrib(city, date) return render_template('submission.html', city=request.form['city'], date=request.form['date'], all_images=all_images, results=results) else: return render_template('errorindex.html', form=form) return render_template('index.html', form=form)
def get_session(request): form = InputForm(request.GET) if not form.is_valid(): error_msg = "" for k, v in form.errors.items(): error_msg += "%s: %s\n" % (k, ", ".join(v)) return HttpResponse(json.dumps({ 'success': False, 'msg': error_msg }), content_type="application/json") subscriber_id = form.cleaned_data['userName'] transaction_id = form.cleaned_data['transactionId'] logger.debug("Getting session for user (%s), transaction id: (%s)", subscriber_id, transaction_id) pcrf_client = PCRFClient() result = pcrf_client.query_session(subscriber_id=subscriber_id) response = { 'success': result['action_result'], 'msg': result.get('action_error_message'), 'session': result.get('session') } log_action(inspect.stack()[0][3], request, response, transaction_id=transaction_id) return HttpResponse(json.dumps(response), content_type="application/json")
def populate_from_instance(instance): form = InputForm() for field in form: try: field.data = getattr(instance, field.name) except AttributeError: continue return form
def input(): form = InputForm(request.form) if request.method == 'POST' and form.validate(): output = test_function(form.input1.data, form.input2.data) return render_template("output.html", output=output, title='Output') else: flash('Please enter a valid value', 'danger') return render_template("input.html", form=form, title='Input')
def index(): """Страница "Главная" """ form = InputForm() if form.validate_on_submit(): message = form.message.data answer = request.form['req'] return sent(message, answer) return render_template("main.html", title='Главная', form=form, warning='')
def sent(message, answer): """Обработка запросов с "Главной" """ answers = [ 'Вывод пользователей (введите users)', 'Книга(введите название)', 'Автор(введите имя и фамилию)' ] a = answers.index(answer) form = InputForm() if a == 0: if current_user.id == 1: return redirect('/request/users') else: return render_template("main.html", title='Главная', form=form, warning='Недостаточно прав') elif a == 1: session = db_session.create_session() book = session.query(Books).filter(Books.title == message).first() if book: author = session.query(Author).filter( Author.id == book.author_id).first() genre = session.query(Genre).filter( Genre.id == book.genre_id).first().genre b = "_".join(book.title.strip().split()) url = f'https://ru.wikipedia.org/wiki/{b}' return render_template('books.html', title='Книга', books=[book], names=[author.name], surnames=[author.surname], extra_info=[url], genres=[genre], err='') return render_template('books.html', title='Книга', err='Данной книги у нас нет в наличии') elif a == 2: session = db_session.create_session() try: name, surname = message.split() except ValueError: return render_template( 'authors.html', title='Автор', err='Вы нарушили формат. Напишите только имя и фамилию') author = session.query(Author).filter( Author.name == name, Author.surname == surname).first() if author: url = f'https://ru.wikipedia.org/wiki/{author.name} {author.surname}' return render_template('authors.html', title='Автор', authors=[author], extra_info=[url], err='') return render_template('authors.html', title='Автор', err='Книг данного писателя у нас нет в наличии')
def initiate(request): """Request user's phone number. This would ordinarily be provided by the mobile operator; we need it to correctly simulate interaction .""" data = {} data.update(csrf(request)) if request.method == 'POST': form = InputForm(request.POST) if form.is_valid(): request.session['phone_number'] = form.cleaned_data['input'] return HttpResponseRedirect(reverse('interact')) else: form = InputForm() data['form'] = form return render_to_response('initiate.html', data, context_instance=RequestContext(request))
def hello(): form = InputForm() if form.validate_on_submit(): message = request.form["message"] name = request.form["name"] note = Note(message=message, name=name) note.add() #return redirect(url_for("success", message=message, name=name, lookupId = note.lookupId)) return render_template("success.html", message=message, name=name, lookupId = note.lookupId) return render_template("index.html", form=form)
def input(): form = InputForm() if form.validate_on_submit(): response = requests.get(form.github_url.data) print(form.github_url.data) if response.status_code == 200: global soup soup = BeautifulSoup(response.text, 'html.parser') output_dict = total_issues() return render_template('output.html', output_dict=output_dict) return render_template('input.html', title='Input', form=form)
def translate(): form = InputForm(request.form) if form.validate(): writer = WriteLike(request.values.get('style')) output_text = writer.style_convert_string( request.values.get('input_text')) return jsonify({'output': output_text}) return jsonify({'errors': form.errors})
def dataProc(): form = InputForm(request.form) data = readAscii() used = [] session["checkboxes"] = form.bools for field in form.columns: for box in form.bools: if field.name == box.label: used.append(int(field.data)) code = plotData(data, used) return render_template("data_process.html", form=form, code=code)
def char_gen_form(): form = InputForm() if form.validate_on_submit(): random.seed(form.name_input.data) char_num = "%0.16d" % random.randint(0, 9999999999999999) char_dict = char_gen.main(form.name_input.data, char_num) return render_template("char-gen-result.html", form=form, char_dict=char_dict) return render_template("char-gen-form.html", form=form)
def home(): form = InputForm() prediction_message = Prediction_Message() if form.validate_on_submit(): prediction_message.initial, prediction_message.pred1, prediction_message.pred2, prediction_message.pred3 = \ predict(model, form.tweet.data, glove.get_glove_emb(), sequence_length=62, use_gpu=False) # if form.tweet.data == 'helloworld': # flash('Entered correct input!', 'success') # return redirect(url_for('home')) # else: # flash('Invalid Tweet!', 'danger') return render_template('home.html', title='DeepFeels', form = form, prediction_message = prediction_message)
def hello(): form = InputForm() if form.validate_on_submit(): principle = int(request.form['principle']) interestRateYear = float(request.form['interestRateYear']) periodYears = int(request.form['periodYears']) flash('Thanks for the information!') # return periodYears and principle and interestRateYear # return test(principle, interestRateYear, periodYears) return ammortization(principle, interestRateYear, periodYears) # return redirect(url_for('schedule')) return render_template('home.html', title='Input', form=form)
def home(): form = InputForm() if form.validate_on_submit(): prediction = simulator.run_simulation([ form.num_col.data, form.num_brit.data, form.general.data, form.offensive.data, form.allies.data ]) print(prediction) flash(f'It looks like the {prediction} win this one!', 'info') # return redirect(url_for('home')) return render_template('index.html', form=form)
def profile(): current_user_id = current_user.id user_id_kategori_wbs = current_user.kategori_wbs user_kategori_wbs = KategoriWbs.query.filter_by( id_kategori_wbs=user_id_kategori_wbs).first() user_id_wbs_spesifik = current_user.wbs_spesifik user_wbs_spesifik = WbsSpesifik.query.filter_by( id_wbs_spesifik=user_id_wbs_spesifik).first() # user_wbs_level2 = WbsLevel2.query.filter_by(id_wbs_level2=user_id_wbs_spesifik).first() # form = InputForm() # form.select_kategori_wbs.choices = [ # ("", "---")]+[(i.id_kategori_wbs, i.kategori_wbs) for i in KategoriWbs.query.all()] form = InputForm() form.select_wbs_level2.choices = [("", "---")] + [ (i.id_wbs_level2, i.wbs_level2) for i in WbsLevel2.query.filter_by( id_wbs_spesifik=user_id_wbs_spesifik).all() ] #Buat default query untuk choice form.select_kategori_wbs.choices = [(user_kategori_wbs.id_kategori_wbs, user_kategori_wbs.kategori_wbs)] form.select_wbs_spesifik.choices = [(user_wbs_spesifik.id_wbs_spesifik, user_wbs_spesifik.wbs_spesifik)] results = db.session.query( InputWbs, WbsLevel3, WbsLevel2, WbsSpesifik, KategoriWbs).select_from(InputWbs).join(WbsLevel3).join( WbsLevel2).join(WbsSpesifik).join(KategoriWbs).all() recap = db.session.query( Post, KategoriWbs, WbsSpesifik, WbsLevel2, WbsLevel3, JenisToppgun, KategoriLean).select_from(Post).join(KategoriWbs).join( WbsSpesifik).join(WbsLevel2).join(WbsLevel3).join( JenisToppgun).join(KategoriLean).filter( Post.user_id == current_user_id).all() # results = Post.query.all() # return '{}'.format(type(results)) return render_template('profile.html', current_user=current_user, user_kategori_wbs=user_kategori_wbs, user_wbs_spesifik=user_wbs_spesifik, form=form, results=results, recap=recap)
def show_board(): new_board = print_board() form = InputForm() print "test" if form.validate_on_submit(): flash("you are validated") print 'valid test' else: flash("ehhh...ehh!, form didn't go") print 'invalid test' return render_template("test.html", form=form, board_1=new_board[0], \ board_2=new_board[1], \ board_3=new_board[2])
def main(): form = InputForm(request.form) if form.validate_on_submit(): contributors = [(form.name_1.data, form.val_1.data), (form.name_2.data, form.val_2.data), (form.name_3.data, form.val_3.data), (form.name_4.data, form.val_4.data)] carrot_image = generate_image(contributors) return render_template('carrot.html', form=form, img_src=convert_pil_image(carrot_image)) print(form.errors) return render_template('carrot.html', form=form, img_src=None)
def interact(request): """Accept input from user and display menus from the application""" if 'phone_number' not in request.session: return HttpResponseRedirect(reverse('initiate')) data = {} data.update(csrf(request)) user_input = INITIAL_INPUT if request.method == 'POST': form = InputForm(request.POST) if form.is_valid(): user_input = form.cleaned_data['input'] # Always create a new unbound form (so that previous inputs don't # show up in current form fields) form = InputForm() args = { 'EXTRA': request.session.get('extra', ''), 'LEVEL': request.session.get('level', INITIAL_LEVEL), 'MSISDN': request.session['phone_number'], 'SESSIONID': '1', 'INPUT': user_input } base_url = 'http://wezatele.webfactional.com/maji/maji.php' # base_url = request.build_absolute_uri(reverse('dispatch')) url = '%s?%s' % (base_url, urlencode(args)) response = urlopen(url).read() data['response'] = response level, data['message'], status, extra = response.split('^') request.session['level'] = level request.session['extra'] = extra data['form'] = form data['status'] = status return render_to_response('interact.html', data, context_instance=RequestContext(request))
async def input(): form = InputForm() if form.validate_on_submit(): r_form = await request.form model_type = r_form['model_type'] inp_text = r_form['input_text'] div_factor = r_form['div_factor'] return redirect( url_for('result', model_type=model_type, inp_text=inp_text, div_factor=float(div_factor))) return await render_template('homepage.html', form=form)