part (iii) marking scheme:
This is the full code which would implement an edit view. However, you do not have to write complete or perfect code in order to get marks.
As you will see from the marking scheme below, the markers will be looking for a general understanding of the process and some evidence of familiarity with the code, rather than perfect recall of big chunks of code.
Correct snippets of code will definitely attract marks, but pseudo code can also be included.
@app.route('/edit_post', methods = ['GET', 'POST'])
@login_required
def edit_post():
form = editPostForm()
if request.args.get('id'):
post_id = request.args.get('id')
post = db.get_post(post_id)
form.post.data = post[0]
form.post_id.data = twit_id
return render_template('edit_post.html',form=form,post=post)
if form.validate_on_submit():
post = form.post.data
post_id = form.post_id.data
db.update_post(post,post_id)
return redirect(url_for('index'))
(The code here uses flask-wtforms but a version that doesn't would be fine as well)
- login is required (after all, we are editing the site) - 1 mark
- the answer includes both GET (part a) and POST (part b) requests - 1 mark
- use of request.args for the GET part - 1 mark
- use of request.form or form.post.data for the POST part - 1 mark
- sensible use of post id to identify post in both parts - 2 marks
- understanding of the need to get the post data from the database for editing - 1 mark
- understanding that the database needs to be updated with the new post - 1 mark
- some idea of form sanitisation / validation - 1 mark
- use of render_template - 1 mark
- use of redirect - 1 mark