Пример #1
0
def addparameter_response(model_id, interface_id):
    if not session.get("logged_in"):
        return redirect(url_for("login"))
    add_parameter_response = ParameterResponseForm()
    submit = SubmitForm()
    if submit.validate_on_submit():
        add = Parameter(interface_id=interface_id,
                        parameter_type=20,
                        parameter_group_id=add_parameter_response.parameter_group_id.data,
                        parameter_name=add_parameter_response.parameter_name.data,
                        necessary=add_parameter_response.necessary.data,
                        type=add_parameter_response.type.data,
                        default=add_parameter_response.default.data,
                        remark=add_parameter_response.remark.data,
                        level=add_parameter_response.level.data)
        db.session.add(add)
        db.session.commit()
        return redirect(url_for("parameter_response",
                                model_id=model_id,
                                interface_id=interface_id))
    return render_template("addparameter_response.html",
                           add_parameter_response=add_parameter_response,
                           model_id=model_id,
                           interface_id=interface_id,
                           submit=submit)
Пример #2
0
def editinterface(model_id, interface_id):
    if not session.get("logged_in"):
        return redirect(url_for("login"))
    interface_model_one = Interface.query.filter_by(interface_id=interface_id).first()
    edit_interface_model = InterfaceForm()
    submit = SubmitForm()
    if submit.validate_on_submit():
        interface_model_one.interface_name = edit_interface_model.interface_name.data
        interface_model_one.interface_url = edit_interface_model.interface_url.data
        interface_model_one.interface_method = edit_interface_model.interface_method.data
        interface_model_one.request_exam = edit_interface_model.request_exam.data
        interface_model_one.response_exam = edit_interface_model.response_exam.data
        db.session.commit()
        return redirect(url_for("interface",
                                model_id=model_id))
    edit_interface_model.interface_name.data = interface_model_one.interface_name
    edit_interface_model.interface_url.data = interface_model_one.interface_url
    edit_interface_model.interface_method.data = interface_model_one.interface_method
    edit_interface_model.request_exam.data = interface_model_one.request_exam
    edit_interface_model.response_exam.data = interface_model_one.response_exam
    return render_template("editinterface.html",
                           model_id=model_id,
                           interface_id=interface_id,
                           edit_interface_model=edit_interface_model,
                           submit=submit)
Пример #3
0
def editparameter_response(model_id, interface_id, parameter_id):
    if not session.get("logged_in"):
        return redirect(url_for("login"))
    parameter_response_one = Parameter.query.filter_by(parameter_id=parameter_id).first()
    edit_parameter_response = ParameterResponseForm()
    submit = SubmitForm()
    if submit.validate_on_submit():
        parameter_response_one.parameter_name = edit_parameter_response.parameter_name.data
        parameter_response_one.necessary = edit_parameter_response.necessary.data
        parameter_response_one.type = edit_parameter_response.type.data
        parameter_response_one.default = edit_parameter_response.default.data
        parameter_response_one.remark = edit_parameter_response.remark.data
        parameter_response_one.parameter_group_id = edit_parameter_response.parameter_group_id.data
        parameter_response_one.level = edit_parameter_response.level.data
        db.session.commit()
        return redirect(url_for("parameter_response",
                                model_id=model_id,
                                interface_id=interface_id))
    edit_parameter_response.parameter_name.data = parameter_response_one.parameter_name
    edit_parameter_response.necessary.data = parameter_response_one.necessary
    edit_parameter_response.type.data = parameter_response_one.type
    edit_parameter_response.default.data = parameter_response_one.default
    edit_parameter_response.remark.data = parameter_response_one.remark
    edit_parameter_response.parameter_group_id.data = parameter_response_one.parameter_group_id
    edit_parameter_response.level.data = parameter_response_one.level
    return render_template("editparameter_response.html",
                           model_id=model_id,
                           interface_id=interface_id,
                           parameter_id=parameter_id,
                           edit_parameter_response=edit_parameter_response,
                           submit=submit)
Пример #4
0
def contact():
    form = SubmitForm(request.form)
    contact = ContactAdmin(request.form)
    if contact.validate_on_submit():
        flash(
            Markup("<strong>Thank you!</strong> Your message has been sent."))
        msg = Messages(timestamp=dt.utcnow(),
                       email=contact.email.data,
                       msg=contact.msg.data)
        db.session.add_all([msg])
        db.session.commit()
        return redirect(url_for('contact'))

    if form.validate_on_submit():
        flash(
            Markup(
                "<strong>Success!</strong> Thank you for submitting a resource. Your post is being reviewed."
            ))
        post = Posts(post_title=form.post_title.data,
                     email=form.email.data,
                     description=form.description.data,
                     post_type=form.post_type_submit.data,
                     link=form.link.data,
                     ph_num=form.ph_num.data,
                     timestamp=dt.utcnow())
        db.session.add_all([post])
        db.session.commit()
        return redirect(url_for('contact'))
    return render_template('contact.html', contact=contact, form=form)


# @app.route('/api',methods=['GET'])
# def api():
#     return jsonify(Posts.query.order_by(Posts.timestamp.desc()).all().to_dict())
Пример #5
0
def index():
    form = SubmitForm()
    q = Complaint()

    if request.mimetype == "application/json" and request.method == "POST":
        code, message = json_handler(request.json, q, db)
        return jsonify(message), code, {"content-type": "application/json"}

    if request.method == "GET":
        return render_template("index.html", form=form)

    if form.validate_on_submit():
        print(form.validate())
        print("It is working.")

        q.lat = form.lat.data
        q.long = form.long.data
        # q.accuracy = form.accuracy.data
        q.short_describtion = form.short_describtion.data
        q.long_describtion = form.long_describtion.data
        db.session.add(q)
        db.session.commit()
        flash("Thank you so much for your submission!")
        address = get_address(form.lat.data, form.long.data)
    else:
        print("Where to f**k i f****d up.")
        for error in form.errors.items():
            flash(error)

    return render_template("index.html", form=form, address=address)
Пример #6
0
def index():
    form = SubmitForm()

    # if form was submitted, do the following
    if form.validate_on_submit():
        data = {}
        data["callsign"] = form.callsign.data
        data["weight"] = form.weight.data
        data["parachute"] = form.parachute.data
        data["balloon"] = form.balloon.data
        data["helium"] = form.helium.data

        host = "127.0.0.1"
        port = 50001
        
        sock = socket.socket()
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.connect((host,port))
        sock.send(json.dumps(['start_real_time', data]))
        msg = sock.recv(1028)
        print(msg)
        sock.close()

        return redirect('http://127.0.0.1:5000/map/{0}.html'.format(data["callsign"]))

    return render_template('submit.html',
                           title='Home',
                           form=form)
Пример #7
0
def submit():
    form = SubmitForm()
    if form.validate_on_submit():
        conn = sql.connect('database.db')
        conn.execute('INSERT INTO users (username, message) VALUES (?,?)',
                     (form.username.data, form.message.data))
        conn.commit()
        conn.close()
        return (redirect(url_for('view')))
    return render_template('submit.html', form=form)
def home():
    form = SubmitForm()
    if form.validate_on_submit():
        hp = int(form.horsepower.data)
        mpg = int(form.mileage.data)
        sit = float(form.seats.data)
        cyl = int(form.cylinders.data)
        gr = int(form.gears.data)

        return setpost(mpg, cyl, hp, gr, sit)

    return render_template('home.html', title='Home', form=form)
Пример #9
0
def addmodel():
    if not session.get("logged_in"):
        return redirect(url_for("login"))
    add_model = ModelForm()
    submit = SubmitForm()
    if submit.validate_on_submit():
        add = Model(model_name=add_model.model_name.data)
        db.session.add(add)
        db.session.commit()
        return redirect(url_for("model"))
    return render_template("addmodel.html",
                           add_model=add_model,
                           submit=submit)
Пример #10
0
def editmodel(model_id):
    if not session.get("logged_in"):
        return redirect(url_for("login"))
    model_one = Model.query.filter_by(model_id=model_id).first()
    edit_model = ModelForm()
    submit = SubmitForm()
    if submit.validate_on_submit():
        model_one.model_name = edit_model.model_name.data
        db.session.commit()
        return redirect(url_for("model"))
    edit_model.model_name.data = model_one.model_name
    return render_template("editmodel.html",
                           edit_model=edit_model,
                           submit=submit)
Пример #11
0
def submit():
    # return render_template('submit.html', title='Submit')
    form = SubmitForm()
    if form.validate_on_submit():
        # START DROP DOWN EFFORT HERE

        task = Submit(task=form.task.data,
                      email=form.email.data,
                      priority=form.priority.data)
        db.session.add(task)
        db.session.commit()
        flash(f'Task for {form.email.data} added.', 'success')
        return redirect(url_for('home'))

    return render_template('submit.html', form=form)
Пример #12
0
def event_update_entry(event_id, song_id):
    evt = database.Event(event_id)
    if evt.are_submissions_open:
        form = SubmitForm()
        if form.validate_on_submit():
            evt.update_entry(form.bms_name.data,
                             form.bms_author.data,
                             form.fake_author.data,
                             form.bga_author.data,
                             form.description.data,
                             form.bms_link.data,
                             form.bms_email.data,
                             song_id, form.token.data)
        return redirect(url_for('event_song_impressions', event_id=event_id, song_id=song_id))
    else:
        return render_template("section_closed.html", event=evt)
Пример #13
0
def index():
    form = SubmitForm()
    if form.validate_on_submit():
        try:
            session = DBSession()
            a = Generate_Board().go(session)
            b = 0
            session.commit()
        except:
            session.rollback()
            a, b = random.randint(50, 100), 0
        finally:
            session.close()

        return redirect(url_for('choose_mode', a=a, b=b))
    return render_template("start.html", form=form)
Пример #14
0
def doctor():
    form = SubmitForm(csrf_enabled=False)
    if form.validate_on_submit():
        rawlist = []
        for item in form:
            if item.type == "BooleanField" and item.data == True:
                rawlist.append(item.name)

        token,query_dict = tr.query_info(rawlist,form.identifier.data)

        return render_template('query_result.html',
                          token= token,
                          json = json.dumps(query_dict,indent=4))

    return render_template('submit.html',
                           form=form)
Пример #15
0
def submit():
    form = SubmitForm()
    if form.validate_on_submit():
        questiondata = Questions(question=form.question.data,
                                 option1=form.option1.data,
                                 option2=form.option2.data,
                                 option3=form.option3.data,
                                 option4=form.option4.data,
                                 answer=form.answer.data,
                                 creatorid=current_user.id,
                                 category=form.category.data,
                                 difficulty=form.difficulty.data)
        db.session.add(questiondata)
        db.session.commit()
        flash('Your question has been nestled deep within the quizzing engine')
        return render_template('submit.html', form=form, users=getStandings())
    return render_template('submit.html', form=form, users=getStandings())
Пример #16
0
def main():
    form = SubmitForm(request.form)
    if form.validate_on_submit():
        flash(
            "Success! Thank you for submitting a resource. Your post is being reviewed."
        )
        post = Posts(post_title=form.post_title.data,
                     email=form.email.data,
                     description=form.description.data,
                     post_type=form.post_type_submit.data,
                     link=form.link.data,
                     ph_num=form.ph_num.data,
                     timestamp=dt.utcnow())
        db.session.add_all([post])
        db.session.commit()
        return redirect(url_for('main'))
    data = Posts.query.order_by(Posts.timestamp.desc()).all()
    return render_template('main.html', form=form, data=data, choices=choices)
Пример #17
0
def submit():
	form = SubmitForm()
	if form.validate_on_submit():
		questiondata = Questions(
			question=form.question.data,
			option1=form.option1.data,
			option2=form.option2.data,
			option3=form.option3.data,
			option4=form.option4.data,
			answer=form.answer.data,
			creatorid=current_user.id,
			category=form.category.data,
			difficulty=form.difficulty.data
		)
		db.session.add(questiondata)
		db.session.commit()
		flash('Your question has been nestled deep within the quizzing engine')
		return render_template('submit.html', form=form, users=getStandings())
	return render_template('submit.html', form=form, users=getStandings())
Пример #18
0
def home():
    form = SubmitForm(request.form)
    options = Options()
    if request.form:
        if form.validate_on_submit():
            return render_template('home.html',
                                   title="Home",
                                   form=SubmitForm(),
                                   prediksjon=predict(form),
                                   options=options)
        else:
            return render_template('home.html',
                                   title="Home",
                                   form=form,
                                   invalid=True,
                                   options=options)
    return render_template('home.html',
                           title="Home",
                           form=form,
                           options=options)
Пример #19
0
def addinterface(model_id):
    if not session.get("logged_in"):
        return redirect(url_for("login"))
    add_interface = InterfaceForm()
    submit = SubmitForm()
    if submit.validate_on_submit():
        add = Interface(interface_name=add_interface.interface_name.data,
                        model_id=model_id,
                        interface_url=add_interface.interface_url.data,
                        interface_method=add_interface.interface_method.data,
                        request_exam=add_interface.request_exam.data,
                        response_exam=add_interface.response_exam.data)
        db.session.add(add)
        db.session.commit()
        return redirect(url_for("interface",
                                model_id=model_id))
    return render_template("addinterface.html",
                           add_interface=add_interface,
                           model_id=model_id,
                           submit=submit)
Пример #20
0
def submit():
    global next_run_id

    form = SubmitForm()
    if form.validate_on_submit():
        problem_id = int(request.form.get('problem_id', ''))
        code = request.form.get('source', '')
        language = request.form.get('language', '')
        if not os.path.exists(USER_CODE_DIR + current_user.username + '/'):
            os.mkdir(USER_CODE_DIR + current_user.username)
        with open(USER_CODE_DIR + current_user.username + '/' +
                  str(next_run_id) + LANGUAGE_IDX2NAME[language][1],
                  'w',
                  encoding='utf-8') as f:
            f.writelines(code.split('\n'))

        attempts[str(next_run_id)] = {
            'run_id': next_run_id,
            "user_id": current_user.username,
            "problem_id": problem_id,
            "result": "Judging",
            "memory": "***",
            "time": "***",
            "language": LANGUAGE_IDX2NAME[language][0],
            "code_length": str(len(code)) + 'B',
            "submit_time": time.strftime('%Y-%m-%d %H:%M:%S')
        }
        with open(ATTEMPTS_FILE, 'w', encoding='utf-8') as f:
            json.dump(attempts, f, indent=4, ensure_ascii=False)
        threading.Thread(target=judge, args=[next_run_id]).start()

        next_run_id += 1
        return redirect(url_for('usr_status', id=current_user.username))

    return render_template('submit.html',
                           form=form,
                           username=current_user.username,
                           problem_id=request.args.get('id'))
Пример #21
0
def event_handle_submission(event_id):
    try:
        evt = database.Event(event_id)
        if evt.are_submissions_open:
            form = SubmitForm()

            if form.validate_on_submit():
                name = form.bms_name.data
                author = form.bms_author.data
                fake_author = form.fake_author.data
                bga_author = form.bga_author.data
                description = form.description.data
                link = form.bms_link.data
                email = form.bms_email.data

                token = evt.insert_entry(name,
                                         author,
                                         fake_author,
                                         bga_author,
                                         description,
                                         link,
                                         email)

                return render_template("submit_success.html",
                                       name=name,
                                       author=author,
                                       link=link,
                                       event=evt,
                                       token=token,
                                       success=True)
            return render_template("submit.html",
                                   form=form,
                                   event=evt,
                                   success=False)
        else:
            return render_template("section_closed.html", event=evt)
    except database.IncorrectEvent as e:
        return render_template("section_closed.html", event=None)
Пример #22
0
def submit(pid = None):
	form = SubmitForm()
	if request.method == 'POST':
		if form.validate_on_submit() and check_qaptcha():
			pid = form.problem_id.data
			p = Problem.query.get(pid)
			if p is None:
				flash("Problem %d doesn't exist!" % (pid))
				return redirect(url_for('submit'))
			elif (p.released == False) and (g.user.role not in ['admin', 'ta']): #problem not released
				flash("You don't have access to problem %d!" % (pid))
				return redirect(url_for('submit'))
			else:
				try:
					languages[form.language.data]
				except KeyError:
					flash('Language not allowed!')
					return redirect(url_for('submit'))
				#mkdir
				filename = secure_filename(form.upload_file.data.filename)
				file_data = form.upload_file.data.read()
				if not os.path.exists(os.path.join(basedir, 'users/%s/' % (g.user.username))):
					os.makedirs(os.path.join(basedir, 'users/%s/' % (g.user.username)))
				#rename
				hmd5 = hashlib.md5()
				hmd5.update(file_data)
				filehash = hmd5.hexdigest()
				if form.language.data == C:
					extension = '.c'
				elif form.language.data == CPP:
					extension = '.cpp'
                                        
                                rfn = rand_fn()
				filepath = os.path.join(basedir, 'users/%s/%s%s' % (g.user.username, datetime.now().strftime('%Y-%m-%d-%H:%M:%S'), '_' + filehash[0:5] + rfn + extension))
				#save file with new name
				fnew = open(filepath, 'w')
                                # test utf8
                                try:
                                        fnew.write(file_data.decode("utf8"))
                                except:
                                        try:
                                                fnew.write(file_data.decode("gbk").encode("utf8"))
                                        except:
                                                #detect encoding
                                                result = chardet.detect(file_data)
                                                if result['encoding'] is not None:
                                                        try:
                                                                fnew.write(file_data.decode(result['encoding']).encode("utf8"))
                                                        except:
                                                                fnew.write(file_data)
                                                else:
                                                        fnew.write(file_data)
				fnew.close()

				#write database
				sub = Submit(problem = pid,
					user = g.user.id,
					language = form.language.data,
					submit_time = datetime.now(),
					code_file = filepath)
				db.session.add(sub)
				db.session.commit()

                                return redirect(url_for('status'))
	return render_template('submit.html',
                               form = form,
                               pid = pid, 
                               user = g.user)