def post(self, request): form = MainForm(request.POST) if not form.is_valid(): context = {'form': MainForm(), 'risk_score': None} return render(request, self.template_name, context) address = request.POST['destination_address'] risk_score = get_address_risk_score(address) context = {'form': form, 'risk_score': risk_score} return render(request, self.template_name, context)
def index(request): if request.method == 'POST': form = MainForm(request.POST, request.FILES) if form.is_valid(): return createCSV(request.FILES['result_ranks'], request.FILES['website_list']) else: form = MainForm() return render(request, 'index.html', { 'form': form, })
def add_birthdate(request): if (request.method == 'POST'): form = MainForm(request.POST) if form.is_valid(): form.save() return fun(request) else: print form.errors else: form = MainForm() return render(request, 'add_birthdate.html', {'form': form})
def upload_from_partners(request): vals = None if request.method == 'POST': form = MainForm(request.POST, request.FILES) if form.is_valid(): vals = createCSV(request.FILES['partner_csv']) else: form = MainForm() return render(request, 'upload_from_partners.html', { 'form': form, 'vals': vals })
def choice(): global executeCommand global textOutput if request.method == "POST" and request.form.get( 'connection') == 'disconnect': helper.disconnectFromSerialPort() executeCommand = False return render_template('index.html') print('Data is {} JS0N is {}'.format(request.form.get('choice'), request.json)) form = MainForm() print('FOrm exec: {} output {}'.format(executeCommand, textOutput)) if request.method == "POST" and executeCommand == True: command = form.command.raw_data[0] textOutput += "\n" + helper.runCommandAndGetOutput(command) form.outputText = textOutput form.isConnected = True form.command.raw_data[0] = "" elif request.method == "POST": choice = form.choice.raw_data[0] print(choice) helper.initialiseSerialPort(choice) form.isConnected = True executeCommand = True textOutput = "Connected to " + choice + "\n" textOutput += "AT\n" + helper.runCommandAndGetOutput('AT') form.outputText = textOutput form.command.data = "" return render_template('choice.html', form=form)
def home(): form = MainForm() if request.method == 'POST': if form.validate_on_submit(): if not verify(form.url_field.data): flash('Please enter a valid YouTube URL', 'danger') format_display = dict(FormatChoices).get(form.output_format.data) if format_display == 'Video': result = downloadVideo(form.url_field.data) print(result) if result == "-1" or result == "-2": flash('An unexpected error has occured. Please try again', 'danger') else: flash('File successfully converted', 'success') form.url_field.data = "" return redirect('/downloadfile/' + result) elif format_display == "Audio": result = downloadAudio(form.url_field.data) if result == "-1" or result == "-2": flash('An unexpected error has occured. Please try again', 'danger') else: flash('File successfully converted', 'success') return redirect('/downloadfile/' + result) return render_template('index.html', form=form)
def __init__(self): self.main_form = MainForm() self.grid_form = GridForm() self.ellipsoids_ini = self.__parse_ellipsoids() self.ellipsoid = None self.sphere_projection_type = None self.sphere_projections_list = None self.__init_ui()
def index(): if 'username' in session: mform_2 = MainForm() if mform_2.validate_on_submit() : return render_template('main.html', mform = mform_2, username = session['username'], search = search_games(mform_2)) return render_template('main.html', mform = mform_2, username = session['username'], search=get_all()) return render_template('index.html')
def main_view(request): if request.method == "POST": form = MainForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] email = form.cleaned_data['email'] message = form.cleaned_data['message'] enc_message = form.cleaned_data['enc_message'] ## SAVING DATA TO DB user = User(name=name, email=email, message=message, enc_message=enc_message) user.save() return redirect('success/') else: form = MainForm() return render(request, 'index.html', {'form': form})
def main(): """Main page.""" form = MainForm() if request.method == 'POST': if not form.validate(): return render_template('main.html', form=form) else: link = match_texts(form.text_1.data, form.text_2.data) return redirect('results/' + link) elif request.method == 'GET': return render_template('main.html', form=form)
def index(): form = MainForm() if form.validate_on_submit(): c_i = form.number_of_cities.data c_o = form.number_of_colors.data n_r = form.number_of_relations.data t_r = form.relations.data results = process_the_info(c_i, c_o, n_r, t_r) return redirect(url_for('result', results=results)) return render_template('index.html', form=form)
def hello_world(): today = datetime.now().strftime('%A %d %b %Y') global dollarRates form = MainForm() if form.validate_on_submit(): if form.firstCurr.data == form.secondCurr.data: return redirect('/') else: uri = '/search?in=' + form.firstCurr.data + '&out=' + form.secondCurr.data return redirect(uri) return render_template('main.html', form=form, dollarRates=dollarRates, today=today)
def display_prices_history(coin_symbol): form = MainForm() if request.method == 'POST': if form.validate_on_submit(): name = request.form['crypto_name'] return redirect('/prices/history/monthly/' + name) data = get_prices_history_monthly(coin_symbol) return render_template('coins/history.html', values_usd=data['values_usd'], values_eur=data['values_eur'], labels=data['labels'], symbol=coin_symbol)
def mainPage(): form = MainForm() if request.method == 'POST': order = form.choice.raw_data[0] print('{}'.format(form.choice.raw_data[0])) if str(order) == '2': form = M2() elif str(order) == '3': form = M3() print('Returning {}'.format(type(form))) return render_template('matrix.html', form=form, choice=order) return render_template('choice.html', title='Choice', form=form)
def api_root(): if username == 'unknown': return redirect('/login') form = MainForm() if form.validate_on_submit(): for device in form.devices.data: device_params = form.get_device(device) if icomera.reboot(device_params['ip'], form.configure.data): flash('Перезагружаю ' + device_params['name'], category='ok') else: flash('Не могу подключиться к ' + device_params['name'], category='error') return render_template('index.html', title=username, username=fullname, form=form)
def main(): main_form = MainForm() message = None # post method for main form to work with spotify API if main_form.validate_on_submit(): search_name = main_form.search_name.data first_query = spotify.search('artist', search_name, session.get('auth_header')) if (len(first_query[spotify.SPOTIFY_ARTISTS][spotify.SPOTIFY_ITEMS]) == 0): return redirect(url_for('bad_query')) artist_id = first_query[spotify.SPOTIFY_ARTISTS][ spotify.SPOTIFY_ITEMS][0][spotify.SPOTIFY_ID] # getting related artists for a specific artist second_query = spotify.get_related_artists(artist_id, session.get('auth_header')) rel_artists = [] for artist in second_query[spotify.SPOTIFY_ARTISTS]: rel_artists.append(artist['name']) if len(rel_artists) > 10: rel_artists = rel_artists[:10] # getting top tracks for a specific artist third_query = spotify.get_artists_top_tracks( artist_id, session.get('auth_header')) top_tracks = [] for track in third_query[spotify.SPOTIFY_TRACKS]: top_tracks.append(track['name']) if len(top_tracks) > 10: top_tracks = top_tracks[:10] db.db.artist.insert({ "name": search_name, "related_artists": rel_artists, "top_tracks": top_tracks }) return redirect(url_for('user')) return render_template('main.html', main_form=main_form)
def index(): form = MainForm() if request.method == 'POST': result = cache.get('result') if result is None: result = get_tweets(app, TWEET_LIMIT) if form.validate_on_submit(): name = request.form['crypto_name'] results, sentiment, avg_sentiment = get_coin_sentiment_data(name) return render_template('index.html', messages=result, form=form, crypto_name=name, sentiment={ 'result': enumerate(results), 'sentiment': sentiment, 'avg_sent': avg_sentiment }) else: result = get_tweets(app, TWEET_LIMIT) cache.set('result', result, 300) return render_template('index.html', messages=result, form=form)
def root(): form = MainForm() if form.validate_on_submit(): return redirect(form.authorizeTransaction()) return render_template('base.html', title='Kinect Sentry Gun', form=form)
def get(self, request): context = {'form': MainForm(), 'risk_score': None} return render(request, self.template_name, context)