def index(): # Update the database #update() form = SubmitForm() print(form.errors) print(form.validate_on_submit()) if form.validate_on_submit(): item_name = str.lower(form.input.data) items = Item.query.filter(Item.name.contains(item_name)).all() if not items: print('unlisted') flash( 'This item you have searched is not listed on the Grand Exchange.' ) return render_template('index.html', form=form) else: return render_template('index.html', form=form, items=items, item_name=item_name, number_of_results=len(items)) return render_template('index.html', form=form)
def index(): form = SubmitForm() if request.method == 'POST': if form.validate_on_submit(): infile = request.form['infile'] outfile = request.form['outfile'] address = request.form['address'] iso = request.form['iso'] key = request.form['key'] geonames = request.form['geonames'] usetools = request.form['usetools'] encoding = request.form['encoding'] resultsper = request.form['resultsper'] buffer = request.form['buffer'] batch_geocode.geocode_from_flask(infile=infile, iso=iso, outfile=outfile, keygm=key, geonames=geonames, address=address, usetools=usetools, encoding=encoding, resultspersource=resultsper, buffer=buffer) flash( 'Your output file for input file, {}, usingtools {}, with {} results per source, and a buffer of {} ' 'is now ready to view at {}'.format(form.infile.data, form.usetools.data, form.resultsper.data, form.buffer.data, form.outfile.data)) return render_template('index.html', title='Home', form=form) else: flash('Need to enter all required fields') return render_template('index.html', title='Home', form=form)
def submit(): form = SubmitForm() if form.validate_on_submit(): flash("Submitting a post: {}".format(form.title.data)) post = Posts(title=form.title.data, body=form.body.data) db.session.add(post) db.session.commit() return redirect(url_for('index')) return render_template('submit.html', title="NKOSL submit", form=form)
def index(): submit_form = SubmitForm() reset_form = ResetForm() if submit_form.validate_on_submit(): old_recipe = submit_form.recipe.data new_recipe, replacements = vegeterizer.vegeterize(old_recipe) replacements = [{'ingr': key, 'r': val} for key, val in replacements.items()] return render_template('index.html', new_recipe=new_recipe, replacements=replacements, reset_form=reset_form, old_recipe=old_recipe) return render_template('index.html', submit_form=submit_form)
def submit(): form = SubmitForm() if form.validate_on_submit(): post = Post(code=form.code.data, author=current_user) post.judge_code() db.session.add(post) db.session.commit() flash("Submit successfully, check below") return redirect(url_for('user', username=current_user.username)) return render_template('submit.html', title='Submit', form=form)
def submit(): form = SubmitForm() if form.validate_on_submit(): uploaded_file = request.files['file'] # Get csv from request data = gb.preprocessing(uploaded_file) # Turn survey responses into graph agreement_graph = gb.build_graph(data) image = clq.make_seating(agreement_graph,form.chaotic.data) # Create the seating arrangement return render_template('result.html', title='Result', image=image, chaotic=form.chaotic.data) return render_template('submit.html', title='Submit', form=form)
def submit(): if not current_user.is_authenticated: flash('-You must be logged in to submit your artwork!') return redirect('/') form = SubmitForm() if form.validate_on_submit(): print('hi') # TODO: submission back-end flash('|Artwork Submitted') return redirect('/')
def index(): form = SubmitForm() if form.validate_on_submit(): print("=============[ Entry Confirmation ]=============") x = form.data x.pop('csrf_token') x.pop('submit') flash(str(predictor.predict(x))) print(result) return redirect(url_for('result')) return render_template('form.html', form=form, title="Form")
def submit(): form = SubmitForm() if form.validate_on_submit(): flash('Submission \'{}\' made successfully'.format(form.title.data)) p = Post(title=form.title.data, body=form.body.data, user_id=current_user.id, uname=current_user.username, contact=current_user.email) db.session.add(p) db.session.commit() return redirect(url_for('index')) return render_template('submit.html', form=form)
def submit_user(): form = SubmitForm() if form.validate_on_submit(): verify_user = IgAccount.query.filter_by( username=form.username.data).first() if not verify_user: new_user = IgAccount(username=form.username.data) db.session.add(new_user) db.session.commit() flash(f'New account added to the database : {form.username.data}') return redirect(url_for('results', username=form.username.data)) return render_template('submit.html', title='Submit Username', form=form)
def submit(): form = SubmitForm() if form.validate_on_submit(): submission = Submission(title=form.title.data, submitter=form.submitter.data, submission=form.submission.data, publishing_status="new") db.session.add(submission) db.session.commit() flash( 'Your leak has been saved and is going to be reviewed. Thank you for leaking with <em>Leakyleaks</em>' ) return redirect(url_for('process')) return render_template('submit.html', form=form)
def index(): form = SubmitForm() country = form.country.data if form.validate_on_submit(): country = form.country.data print(form.country.data) return redirect(url_for('movies', country=country)) return render_template('index.html', title='Home', country=country, form=form)
def index(): form = SubmitForm() combo_word_list = [] if form.validate_on_submit(): letters = form.letters.data with open('app/static/words') as f: word_list = [word.rstrip("\n").lower() for word in f] word_list = { word for word in word_list if 8 >= len(word) >= 3 and not word.endswith("'s") } combo_word_list = solution(letters, word_list) return render_template('index.html', combo_word_list=combo_word_list, form=form)
def submit(): form = SubmitForm() if form.validate_on_submit(): text = form.review.data matrix = tokenizer.texts_to_matrix([text]) pred = np.argmax(model_rnn.predict(matrix.reshape((1, 1, n_words))) ) + 1 if pred == 1: return render_template('star.html', user_image="https://dublinbookworm.files.wordpress.com/2015/07/1-star2.jpg?w=300&h=60") elif pred == 2: return render_template('star.html', user_image="https://dublinbookworm.files.wordpress.com/2015/07/2-star2.jpg?w=300&h=60") elif pred == 3: return render_template('star.html', user_image="https://dublinbookworm.files.wordpress.com/2015/07/3-star2.jpg?w=300&h=60") elif pred == 4: return render_template('star.html', user_image="https://dublinbookworm.files.wordpress.com/2015/07/4-star2.jpg?w=300&h=60") else: return render_template('star.html', user_image="https://dublinbookworm.files.wordpress.com/2015/07/5-star2.jpg?w=300&h=60") return render_template('submit.html', form=form)
def index(): if datetime.now() < Config.data["Time"]["start"]: return create_response(render_template('index_wait.html')) form = SubmitForm() return create_response(render_template('index.html', form=form))
def browse(): form = SubmitForm() puzzles = db.session.query(Puzzles).all() if 'action' in request.form: session['solved_puzzle'] = solve(request.form['action']) return redirect(url_for('solution')) return render_template('browse.html', puzzles=[(i.puzzle, i.difficulty) for i in puzzles], form=form)
def submit(): # The below code is ugly and so are you. """View function for the submit site, which contains a standard form. Creates initial variables for mutable variables like upvotes, downvotes and importance, to avoid any TypeErrors.""" form = SubmitForm() if form.validate_on_submit(): # Checks whether the topic exists, so as to not make identical topics. if check_topic_exists(form.topics.data): topic = Topic.query.filter_by(tag_name=form.topics.data).first() post = Post(title=form.title.data, text=form.text.data, user_id=current_user.id, topics=[topic]) elif not check_topic_exists(form.topics.data): post = Post(title=form.title.data, text=form.text.data, user_id=current_user.id, topics=[Topic(tag_name=form.topics.data)]) # Checks to see if post is link or url. if form.link.data == "": post.is_link = False else: post.is_link = True if form.link.data == "" and form.text.data == "": flash("Please input either a link or text, or both.") return redirect(url_for('submit')) post.upvotes = 1 post.link = form.link.data post.downvotes = 0 post.importance = 10 post.hotness = post.get_hotness() post.score = post.get_score() db.session.add(post) db.session.commit() flash('You have now made a post!') return redirect(url_for('index')) return render_template('submit.html', title='Submit', form=form)
def addweibo(): ''' : addweibo: 增加一条任务 ''' form = SubmitForm() # 生成任务编写表单 if form.validate_on_submit(): # 若用户输入了合法的任务内容,则将用户的任务发送到数据库中 # 1. 从表单中收集任务编写内容 f = form.file.data filename = secure_filename( f.filename) # filename一般可以伪装,因此必须使用secure_filename来进行处理 post = Post(body=form.body.data, user_id=current_user.id, timestamp=datetime.utcnow(), state=0) # 2. 将新的任务加入数据库的Post表单中 db.session.add(post) db.session.commit() # 3. 将任务上传的视频保存到对应的文件夹: /weibofile/<weibo_id> save_dir = app.config['UPLOAD_FOLDER'] + '\\' + str(post.id) os.mkdir(save_dir) f.save(os.path.join(save_dir, filename)) tar_post = Post.query.filter(Post.id == post.id).first() tar_post.filedir = 'img' + '/' + str(post.id) + '/' + filename db.session.commit() # 4. 将新的任务的id加入消息队列 producer.produce(post.id) # 5. 提示用户信息,并跳转至应用首页 flash('任务已成功提交') return redirect(url_for('index')) return render_template('addweibo.html', form=form, title='新任务', isuser=current_user.is_authenticated)
def index(): form = SubmitForm() if request.method == "POST": abc = request.form['query'] print(abc) csv_file = open('data.csv', 'w') writer = csv.writer(csv_file) writer.writerow(abc) redirect('/') return render_template('index.html', form=form)
def submit(): """View function for the submit site, which contains a standard form. Creates initial variables for mutable variables like upvotes, downvotes and importance, to avoid any TypeErrors.""" form = SubmitForm() if form.validate_on_submit(): post = Post(title=form.title.data, text=form.text.data, user_id=current_user.id, topics=[Topic(tag_name=form.topics.data)]) post.upvotes = 1 post.downvotes = 0 post.importance = 1 post.score = post.get_score() db.session.add(post) db.session.commit() flash('You have now made a post!') return redirect(url_for('index')) return render_template('submit.html', title='Submit', form=form)
def submit(request): if not request.user.is_authenticated(): return HttpResponseRedirect('/signup') if request.method == "POST": form = SubmitForm(request.POST) if form.is_valid(): address = form.cleaned_data['address'] latitude = form.cleaned_data['latitude'] longitude = form.cleaned_data['longitude'] category=form.cleaned_data['category'] comments=form.cleaned_data['comments'] total_id = Complaints.objects.count() print total_id print address new_id = total_id + 1 string_id = str(new_id) case_id = "citizen311_"+string_id print case_id comments_created_date=datetime.datetime.now() user_id = request.user.id Complaints.objects.create(address=address, category=category, case_id=case_id, id=new_id, latitude=latitude, longitude=longitude) Comments.objects.create(comments=comments, comments_created_date=comments_created_date, user_id=user_id, complaints_id=new_id) return HttpResponseRedirect('/') else: form = SubmitForm() data = { "form":form } return render(request, 'submit.html', data)
def index(): form = SubmitForm() if form.validate_on_submit(): try: flash('Submitted for number {} of {}'.format( form.usernum.data, form.usercity.data)) place = form.usercity.data user_num = '+1' + form.usernum.data weather = Weather(place, API_ID) send_message = Send(MY_ACCOUNT, MY_TOKEN, user_num) send_message.send_message(weather.city, weather.current, weather.high, weather.low, weather.condition) return redirect(url_for('index')) except: flash( 'ERROR: City Name Not Spelled Correctly! e.g. los angeles, not losangeles' ) return redirect(url_for('index')) else: return render_template('index.html', form=form)
def submit(): form = SubmitForm() if form.validate_on_submit(): if form.flag.data == "steg{wh1t3 Is c0Ol}": flash("Congrats!You Completed Your Challenge") elif form.flag.data == "steg{g_o_t_y_o_u_r_f_l_a_g}": flash("Congrats!You Completed Your Challenge") elif form.flag.data == "steg{h1ng3d It}": flash("Congrats!You Completed Your Challenge") elif form.flag.data == "steg{p13sa'nt s0und m'ak3s a' dAy}": flash("Congrats!You Completed Your Challenge") elif form.flag.data == "steg{H3R3_15_y0ur_fl4g}": flash("Congrtas!You Completed Your Challenge") elif form.flag.data == "steg{StrAnGe Idea}": flash("Congrtas!You Completed Your Challenge") elif form.flag.data == "steg{C0OL_Y0U_4R3_1337}": flash("Congrats!You Completed Your Challenge") elif form.flag.data == "steg{3NCRYPTI0N5_4R3_C00L}": flash("Congrats!You Completed Your Challenge") else: flash("Try Again!Better Luck") app.logger.debug(app.config.get("ENV")) return render_template('submit.html', title='Steganography CTF', form=form)
def submit(): form = SubmitForm() SubmitTime = datetime.now() if not current_user.adm and not ok_addr(request.remote_addr): flash("Invalid submission") with open('log/badIP', 'a') as file: file.write("{} {} {}\n".format(current_user.uid, SubmitTime, request.remote_addr)) elif SubmitTime <= Config.data["Time"]["end"] and SubmitTime >= Config.data["Time"]["start"]: f = form.code.data SubmitTime = SubmitTime.strftime("%Y-%m-%d %H:%M:%S") sid = None if ok_file(f): prefix = "VJudge Submission, {{User:'******', Time:'{}', Language:'{}'}}\n".format(current_user.uid, SubmitTime, form.language.data) if file_ext(f.filename) == 'py': prefix = "#" + prefix else: prefix = "//" + prefix if Config.data["User"]["maxSubmission"] != -1 and Config.data["User"]["maxSubmission"] <= len(Submission.query.filter_by(uid=current_user.uid).all()): flash("Too many submissions") return redirect(url_for('index')) else: sid = OJ.submit(form.problem.data, form.language.data, "Main.{}".format(file_ext(f.filename)), f, prefix=prefix) else: flash("Invalid file extension") return redirect(url_for('index')) if sid == None: flash("Submitted failed, please try again later") else: with open("log/submissions", "a") as log: log.write("sid: {}, user:{}, pid:{}, lang:{}, time:{}\n".format(sid, current_user.uid, form.problem.data, form.language.data, SubmitTime)) db.session.add(Submission(sid=sid, uid=current_user.uid, pid=form.problem.data)) db.session.commit() return redirect(url_for('index')) else: flash("Invalid submission") return redirect(url_for('index'))
def flash_errors(form, type): for field, errors in form.errors.items(): for error in errors: flash(type+error) return render_template('home.html', activePage = page, lform = LoginForm(), sform = RegistrationForm(), uform = SubmitForm(), user = current_user)
def index(): orgs = allPosts = myPosts = False allPosts = Post.query.order_by(Post.timestamp).all() if current_user.is_authenticated: orgs = Organization.query.filter_by(user_id=current_user.id) myPosts = Post.query.filter_by(user_id=current_user.id).order_by(Post.timestamp).all() return render_template('home.html', activePage = page, lform = LoginForm(), sform = RegistrationForm(), uform = SubmitForm(), user = current_user, allPosts = allPosts, orgs = orgs, myPosts = myPosts) return render_template('home.html', activePage = page, lform = LoginForm(), sform = RegistrationForm(), uform = SubmitForm(), user = current_user, allPosts = allPosts)
def submit(): if not can_submit(): return render_template('submissions-closed.html', title='Submissions are closed!'), 403 form = SubmitForm(meta={'csrf': False}) if form.validate_on_submit(): t_priv = form.private_id.data team = Team.query.filter(Team.private_id == t_priv).first() t_id = team.id t_name = team.name # Find previous submission time (if exists) prev_sub = Submission.query.filter( Submission.team_id == t_id).order_by( Submission.sub_time.desc()).first() prev_time = datetime.strptime(ORIG_TIME, DB_TIME_FORMAT) if prev_sub: prev_time = prev_sub.sub_time # Rate limit submissions now = datetime.utcnow() if app.config['SUBMIT_DELAY']: diff = (now - prev_time).total_seconds() if diff < app.config['SUBMIT_DELAY']: # Status code: 429 Too Many Requests return render_template( 'rate-limit.html', time_diff=diff, sub_delay=app.config['SUBMIT_DELAY']), 429 f = form.file.data now_str = now.strftime(ZIP_TIME_FORMAT) filename = 'team_{}_{}.zip'.format(t_id, now_str) location = os.path.join(app.config['SUBMIT_DIR'], filename) os.makedirs(os.path.dirname(location), exist_ok=True) f.save(location) h = '' with open(location, "rb") as f: bytes = f.read() h = hashlib.sha256(bytes).hexdigest() # XXX: stages; we don't need a check here, since submissions with .buy # will be rejected outright # Reject submissions that try to buy more boosters than they can afford num_coins = get_balance(t_id) good_purchase, total, extra = False, 0, None try: good_purchase, total, extra = validate_booster_purchase( num_coins, location) except UnicodeDecodeError: return render_template('boosters-fail.html', not_decoded=True) if extra is not None and len(extra) > 0: return render_template('boosters-fail.html', extra=extra) if not good_purchase: # Status code: 402 Payment Required return render_template('boosters-fail.html', num_coins=num_coins, total=total), 402 # Schedule for grading # TODO: this will just timeout if the broker is offline spent_coins = total grade.delay(t_id, t_priv, t_name, now_str, filename, h, spent_coins) # Register submission in database sb = Submission(team_id=t_id, name=filename, hash=h, sub_time=now) db.session.add(sb) db.session.commit() # Acknowledge submission to team gd = grades_dir(t_priv) os.makedirs(gd, exist_ok=True) sf = os.path.join(gd, SUBMISSIONS_FILE) with open(sf, 'a+') as f: f.write('{} -> {}\n'.format(now_str, h)) # Create team identifiers in case they don't exist nf = os.path.join(gd, TEAM_NAME_FILE) with open(nf, 'w') as f: f.write('{}\n'.format(t_name)) idf = os.path.join(gd, TEAM_ID_FILE) with open(idf, 'w') as f: f.write('{}\n'.format(t_id)) team_folder = '/grades/{}/'.format(t_priv) return render_template('submitted.html', filename=filename, hash=h, team_folder=team_folder) return render_template('submit.html', title='Submit a solution', form=form)