simple debug feature - edit game json directly

This commit is contained in:
Jeremy Penner 2012-05-24 08:45:08 -04:00
parent 79d6455236
commit 18b796481d
3 changed files with 25 additions and 1 deletions

View file

@ -117,9 +117,24 @@ def disc_json(id):
disc = g.db.query(models.Disc).filter_by(id=id).one()
return json.dumps(models.toJso(disc))
@app.route('/disc/<int:id>/edit/')
@app.route('/disc/<int:id>/edit/', methods=['GET', 'POST'])
@requires_login
def disc_edit(id):
if request.method == 'POST':
try:
jsoDisc = json.loads(request.form['jsonNew'])
if 'qtes' in jsoDisc:
g.db.query(models.Qte).filter(models.Qte.disc_id == id).delete()
for jsoQte in jsoDisc['qtes']:
qte = models.fromJso(jsoQte, models.Qte)
qte.disc_id = id
g.db.add(qte)
g.db.commit()
else:
raise Exception("Invalid json")
except:
g.db.rollback()
flask.flash("Could not parse json")
return render_disc(id, urlPostQte=flask.url_for('edit_qte', id=id, _external=True), csrf=create_session(id).guid)
@app.route('/disc/<int:id>/qte/', methods=['POST'])

View file

@ -3,6 +3,7 @@ a, h1, h2 { color: #377BA8; }
h1, h2 { font-family: 'Georgia', serif; margin: 0; }
h1 { border-bottom: 2px solid #eee; }
h2 { font-size: 1.2em; }
textarea { width: 100%;}
.page { margin: 2em auto; width: 800px; border: 5px solid #ccc;
padding: 0.8em; background: white; }

View file

@ -41,4 +41,12 @@
src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"
alt="Get Adobe Flash player" /></a></p>
</div>
{% if 'urlPostQte' in flashvars %}
<form method="POST">
<textarea rows="5" name="jsonNew">
{{ flashvars['jsonDisc'] }}
</textarea>
<input type="submit" value="edit game"/>
</form>
{% endif %}
{% endblock %}