Ejemplo n.º 1
0
def run_edit(request, object_id):
	"""
	FIXME
	@param request:
	@type request:
	@param object_id:
	@type object_id:
	"""
	aRun = Run.objects.get(pk=object_id)
	if canEditRun(aRun,request.user):
		pass
	else:
		return HttpResponseRedirect(aRun.get_absolute_url())
	if request.method == "POST":
		form = RunForm(request.POST,instance=aRun)
		if form.is_valid():
			run=form.save()
			return HttpResponseRedirect(run.get_absolute_url())
	else:
		form = RunForm(instance=aRun)
		form.larp=object_id
	return render_to_response('eventCRUD/run_edit.html', {
		'form':form, 
		'larp':aRun.larp
		},
		context_instance=RequestContext(request)
	)
Ejemplo n.º 2
0
def edit_run(runid):
    run = Run.query.filter_by(id=runid).first_or_404()
    form = RunForm(request.form, obj=run)
    users = User.query.all()
    form.person.choices = [(user.id, user.name) for user in users]
    cafes = Cafe.query.all()
    form.cafeid.choices = [(cafe.id, cafe.name) for cafe in cafes]
    if request.method == "GET":
        print run.time.strftime('%Y-%m-%d %H:%M:%S %Z%z')
        return render_template("runform.html",
                               form=form,
                               formtype="Edit",
                               current_user=current_user)
    if request.method == "POST" and form.validate_on_submit():
        person = User.query.filter_by(id=form.data["person"]).first()
        run.person = person.id
        run.fetcher = person
        run.cafeid = form.data["cafeid"]
        run.pickup = form.data["pickup"]

        db.session.commit()
        write_to_events("updated", "run", run.id)
        db.session.commit()
        flash("Run edited", "success")
        return redirect(url_for("view_run", runid=run.id))
    else:
        for field, errors in form.errors.items():
            flash("Error in %s: %s" % (field, "; ".join(errors)), "danger")
        return render_template("runform.html",
                               form=form,
                               formtype="Edit",
                               current_user=current_user)
Ejemplo n.º 3
0
def add_run(cafeid=None):
    form = RunForm(request.form)
    users = User.query.all()
    form.person.choices = [(user.id, user.name) for user in users]
    cafes = Cafe.query.all()
    if not cafes:
        flash(
            "There are no cafes currently configured. Please add one before creating a run",
            "warning")
        return redirect(url_for("home"))
    form.cafeid.choices = [(cafe.id, cafe.name) for cafe in cafes]
    if request.method == "GET":
        if cafeid:
            form.cafe.data = cafeid
        form.person.data = current_user.id
        form.time.data = sydney_timezone_now() + timedelta(
            minutes=30)  # strftime("%Y/%m/%d %H:%M:%S")
        return render_template("runform.html",
                               form=form,
                               formtype="Add",
                               current_user=current_user)
    if form.validate_on_submit():
        # Add run
        print form.data
        run = Run(form.data["time"])
        person = User.query.filter_by(id=form.data["person"]).first()
        run.person = person.id
        run.fetcher = person
        run.cafeid = form.data["cafeid"]
        run.pickup = form.data["pickup"]
        #run.modified = sydney_timezone_now()
        run.modified = sydney_timezone_now()
        db.session.add(run)
        db.session.commit()
        write_to_events("created", "run", run.id)
        flash("Run added", "success")
        return redirect(url_for("view_run", runid=run.id))
    else:
        for field, errors in form.errors.items():
            flash("Error in %s: %s" % (field, "; ".join(errors)), "danger")
        return render_template("runform.html",
                               form=form,
                               formtype="Add",
                               current_user=current_user)
Ejemplo n.º 4
0
def edit_run(runid):
    run = Run.query.filter_by(id=runid).first_or_404()
    form = RunForm(request.form, obj=run)
    statuses = Status.query.all()
    form.statusid.choices = [(s.id, s.description) for s in statuses]
    users = User.query.all()
    form.person.choices = [(user.id, user.name) for user in users]
    cafes = Cafe.query.all()
    form.cafeid.choices = [(cafe.id, cafe.name) for cafe in cafes]
    if request.method == "GET":
        print run.time.strftime('%Y-%m-%d %H:%M:%S %Z%z')
        return render_template("runform.html", form=form, formtype="Edit", current_user=current_user)
    if request.method == "POST" and form.validate_on_submit():
        print form.data
        #print type(form.data["time"])
        #print type(run.time)
        #print type (sydney_timezone_now())
        oldstatus = run.status.description
        #form.populate_obj(run)
        person = User.query.filter_by(id=form.data["person"]).first()
        run.person = person.id
        run.fetcher = person
        run.cafeid = form.data["cafeid"]
        run.pickup = form.data["pickup"]
        run.statusid = form.data["statusid"]
        
        #localtz = pytz.timezone("Australia/Sydney")
        newstatus = Status.query.filter_by(id=form.data["statusid"]).first().description
        #run.modified = sydney_timezone_now()
        db.session.commit()
        write_to_events("updated", "run", run.id)
        db.session.commit()
        flash("Run edited", "success")
        if oldstatus != newstatus and newstatus == "Pickup":
            call_to_pickup(run)
        return redirect(url_for("view_run", runid=run.id))
    else:
        for field, errors in form.errors.items():
            flash("Error in %s: %s" % (field, "; ".join(errors)), "danger")
        return render_template("runform.html", form=form, formtype="Edit", current_user=current_user)
Ejemplo n.º 5
0
def run_add(request, object_id):
	"""
	FIXME
	@param request:
	@type request:
	@param object_id:
	@type object_id:
	"""
	larp = get_object_or_404(Larp, pk=object_id)
	aRun = Run(larp=larp,creator=request.user)
	if request.method == "POST":
		form = RunForm(request.POST,instance=aRun)
		if form.is_valid():
			run=form.save()
			return HttpResponseRedirect(run.get_absolute_url())
	else:
		form = RunForm()
		form.larp=object_id
	return render_to_response('eventCRUD/run_add.html', {
		'form':form, 
		'larp':larp,
		},
		context_instance=RequestContext(request)
	)
Ejemplo n.º 6
0
def result_select():
    form = RunForm()
    if request.method == 'POST':
        username = request.form.get('username')
        print("要查询的名称是:", username)
        number = request.form.get('number')
        #number=int(number)
        #这里使用username作为限定条件,执行sql查询
        db = OpenationDbInterface()
        sql = "select * from interface_result where username = '******'" + " ORDER BY id DESC LIMIT 0," + number
        print("sql:", sql)
        interfaces = db.select_data(sql)
        #redirect(url_for('write'))
        #time.sleep(5)
        return render_template('result.html', interfaces=interfaces)

    return render_template('result_select.html')
Ejemplo n.º 7
0
def run():
    form = RunForm()
    if request.method == 'POST':
        username = request.form.get('username')
        #number=request.form.get('number')
        #newrun.myrun(username)
        RunMain = RunTest(username)
        RunMain.go_to_run()

        #print("要执行的用户是:",username)
        print("要执行的用户名称是:", username)
        # 这里使用username作为限定条件,执行sql查询
        db = OpenationDbInterface()
        sql = "select * from interface_result where username = '******'" + " ORDER BY id DESC LIMIT 0,20"
        interfaces = db.select_data(sql)
        # redirect(url_for('write'))
        #time.sleep(5)
        return render_template('result.html',
                               interfaces=interfaces)  #点击之后跳转到结果页面就行了

        #return redirect(url_for('check'))
    return render_template('run.html')
Ejemplo n.º 8
0
def run():
    form = RunForm()

    if request.method == "POST" and form.validate():
        file = request.files["uploaded_file"]
        text = request.form["uploaded_text"]
        jobname = request.form["job_id"]

        # If a file is not selected for upload...
        if file.filename == "":
            # ...and a sequence is not also provided
            if text == "":
                flash("No data submitted. Please check your input.")
                return redirect(request.url)
            # ...and a sequence is provided but is not DNA or proteins
            elif text != "" and not allowed_text(text):
                flash("Input data is not DNA nor proteins.")
                return redirect(request.url)
            # ...and a sequence is provided and is DNA or proteins
            elif text != "" and allowed_text(text):
                path = os.path.join(app.config["UPLOAD_FOLDER"],
                                    form.job_id.data)
                open(
                    path,
                    "w",
                ).write(form.uploaded_text.data)
                session["jobname"] = jobname
                job = q.enqueue(
                    func=conodictor,
                    args=(
                        path,
                        os.path.join(app.config["RESULT_FOLDER"], jobname),
                    ),
                    job_id=jobname,
                    job_timeout=3600,
                    result_ttl=5000,
                )
                return render_template(
                    "run.html",
                    form=form,
                    path=path,
                    jobname=jobname,
                    resout=session["resout"],
                )
        # If a file is selected for upload...
        elif file.filename != "":
            # ...and the filename is allowed
            if allowed_file(file.filename):
                filename = secure_filename(file.filename)
                path = os.path.join(app.config["UPLOAD_FOLDER"], filename)
                file.save(path)

                session["jobname"] = jobname
                job = q.enqueue(
                    func=conodictor,
                    args=(
                        path,
                        os.path.join(app.config["RESULT_FOLDER"], jobname),
                    ),
                    job_id=jobname,
                    job_timeout=3600,
                    result_ttl=5000,
                )
                return render_template(
                    "run.html",
                    form=form,
                    path=path,
                    jobname=jobname,
                    resout=session["resout"],
                )
            # ...and the filename is not allowed
            else:
                flash("Provided file is not supported. Please select" +
                      " a fasta file either gzipped or not.")
                return redirect(request.url)

    return render_template("run.html", form=form)