+@app.route('/admin/votes/addattachment/<voteid>', methods=['POST'])
+def admin_vote_addattachment(voteid):
+ if not session.get('user').get('is_admin'):
+ abort(401)
+ vote = query_db('select * from votes where id = ?', [voteid], one=True)
+ if vote is None:
+ abort(404)
+ g.db.execute('insert into attachments (url, id_vote) values (?, ?)', [request.form['url'], voteid])
+ g.db.commit()
+ return redirect(url_for('admin_vote_edit', voteid=voteid))
+
+@app.route('/admin/votes/deleteattachment/<voteid>/<attachmentid>')
+def admin_vote_deleteattachment(voteid, attachmentid):
+ if not session.get('user').get('is_admin'):
+ abort(401)
+ attachment = query_db('select * from attachments where id = ? and id_vote = ?', [attachmentid, voteid], one=True)
+ if attachment is None:
+ abort(404)
+ g.db.execute('delete from attachments where id = ? and id_vote = ?', [attachmentid, voteid])
+ g.db.commit()
+ return redirect(url_for('admin_vote_edit', voteid=voteid))
+