예제 #1
0
def add_result():
    all_p = Player.query.order_by(Player.name.asc()).all()
    names = names_schema.dump(all_p)
    n_list = list(names.data)
    n_list.insert(0, {"name": " "})
    form = ResultForm(n_list)
    if form.validate_on_submit():
        if request.form["username"] == request.form["p2_name"]:
            return redirect("/add-match")
        p = Player.query.filter_by(
            name=request.form["username"]).first_or_404()
        if p.verify_password(request.form["password"]):
            new_match = Match(
                request.form["username"],
                request.form["p2_name"],
                request.form["p1_score"],
                request.form["p2_score"],
            )
            new_match.status = "pending"
            db.session.add(new_match)
            db.session.commit()
            return redirect("/add-match")
        else:
            return jsonify(data="Incorrect Password", status_code=401)
    return render_template("add-result.html",
                           title="Add Match Result",
                           form=form)
예제 #2
0
def edit_result(id):
    result = Result.query.get_or_404(id)
    form = ResultForm(obj=result)
    if form.validate_on_submit():
        form.populate_obj(result)
        db.session.commit()
    else:
        print form, form.errors
    print form.last_name.data
    return render_template("edit.html", result=form, id=id)
예제 #3
0
def card_edit(card_id):
    if can_user_edit_card(current_user, card_id):
        form = ResultForm(obj=Result.query.get_or_404(card_id))
        if form.validate_on_submit():
            form.populate_obj(Result.query.get_or_404(card_id))
            db.session.commit()
            return redirect(url_for('profile_show', id=current_user.id))
        else:
            print form.errors
        return render_template("card_edit.html", result=form, id=card_id)
    return redirect(url_for('start_page'))
예제 #4
0
def card_create():
    form = ResultForm()
    if form.validate_on_submit():
        form.user_id.data = current_user.id
        result = Result()
        form.populate_obj(result)
        db.session.add(result)
        db.session.commit()
        return redirect(url_for('profile_show', id=current_user.id))
    else:
        print form.errors
    return render_template('add_card.html', form=form)
예제 #5
0
def add_result():
    form = ResultForm()
    if form.validate_on_submit():
        p = Player.query.filter_by(name=request.form["username"]).first_or_404()
        if p.verify_password(request.form["password"]):
            new_match = Match(
                request.form["username"],
                request.form["p2_name"],
                request.form["p1_score"],
                request.form["p2_score"],
            )
            new_match.status = "pending"
            db.session.add(new_match)
            db.session.commit()
            return redirect("/rankings")
        else:
            return jsonify("Authentication error", status_code=401)
    return render_template("add-result.html", title="Add Match Result", form=form)
예제 #6
0
파일: webserver.py 프로젝트: CoNexDat/MIRA
def showResults(date):
    form = ResultForm(request.form)
    form.dates.choices = [(k, v) for k, v in measurementDates]

    # define the names for the graphics of the selected date
    imageNames = {
        'lanet_v4': date + '_edgelist_v4.png',
        'lanet_v6': date + '_edgelist_v6.png',
        'degree_v4': date + '_degree_distribution_v4.png',
        'degree_v6': date + '_degree_distribution_v6.png',
        'avg_neighbor_v4': date + '_avg_neighbor_v4.png',
        'avg_neighbor_v6': date + '_avg_neighbor_v6.png',
        'cluster_v4': date + '_cluster_v4.png',
        'cluster_v6': date + '_cluster_v6.png',
        'heatmap_v4': date + '_heatmap_v4.png',
        'heatmap_v6': date + '_heatmap_v6.png'
    }

    try:
        form.dlScript.data = session['dlScript']
    except KeyError:
        print('no saved value for dlScript found')

    if form.validate_on_submit() and form.changeDate.data:
        print('here')
        return redirect(url_for('showResults', date=form.dates.data))

    elif form.validate_on_submit() and form.download.data:
        # create temporary dir for the .json-files
        os.makedirs('downloads/files/')

        # create .json-files to download depending on input
        if request.form['dlMsmIds'] == 'yes':
            getMeasurementIds(tracerouteColl, date)
        if request.form['dlLanet'] == 'yes':
            getDlImg(imageNames['lanet_v4'])
            getDlImg(imageNames['lanet_v6'])
        if request.form['dlDegree'] == 'yes':
            getDlImg(imageNames['degree_v4'])
            getDlImg(imageNames['degree_v6'])
        if request.form['dlNeighbor'] == 'yes':
            getDlImg(imageNames['avg_neighbor_v4'])
            getDlImg(imageNames['avg_neighbor_v6'])
        if request.form['dlCluster'] == 'yes':
            getDlImg(imageNames['cluster_v4'])
            getDlImg(imageNames['cluster_v6'])
        if request.form['dlHeatmaps'] == 'yes':
            getDlImg(imageNames['heatmap_v4'])
            getDlImg(imageNames['heatmap_v6'])
        if request.form['dlAsns'] == 'yes':
            getDlData(asnColl, date)
        if request.form['dlProbes'] == 'yes':
            getDlData(probeColl, date)
        if request.form['dlEdges'] == 'yes':
            getDlData(edgeColl, date)
        if request.form['dlPaths'] == 'yes':
            try:
                shutil.copy('paths/' + date + '_paths_v4.csv',
                            'downloads/files/')
            except Exception:
                print('No IPv4 Paths found')
            try:
                shutil.copy('paths/' + date + '_paths_v6.csv',
                            'downloads/files/')
            except Exception:
                print('No IPv6 Paths found')
        # write .json-files into zipfile and make it accesible for Respone()
        data = io.BytesIO()
        with zipfile.ZipFile(data, 'w') as z:
            for file in os.listdir('downloads/files/'):
                z.write('downloads/files/' + file)
            # add dlScript, if selected
            if request.form['dlScript'] == 'yes':
                for file in os.listdir('downloads/'):
                    z.write('downloads/' + file)
        data.seek(0)

        # delete the directory
        shutil.rmtree('downloads/files/')

        # save the dlScript value into the session
        session['dlScript'] = request.form['dlScript']

        # return the zip-File as a Download
        return Response(data,
                        mimetype='application/zip',
                        headers={
                            'Content-Disposition':
                            'attachment;filename=%smeasurementData.zip' % date
                        })

    return render_template('results.html',
                           form=form,
                           **imageNames,
                           date=datetime.strptime(
                               date, '%Y%m%d').strftime("%d %b %Y"))