writing goodlist & blacklist -> db

This commit is contained in:
b3yond 2018-03-16 15:17:12 +01:00
parent 4b21dddddf
commit 7bbcbe1ab1
2 changed files with 100 additions and 43 deletions

View File

@ -137,6 +137,41 @@ def manage_bot():
else:
bottle.abort(401, "Sorry, access denied.")
@app.route('/settings/goodlist', method="POST")
def update_goodlist():
"""
Writes the goodlist textarea on /settings to the database.
This function expects a multi-line string, transmitted over the textarea form.
:return: redirect to settings page
"""
# get new goodlist
words = bottle.request.forms.get("goodlist")
# get user.id
email = bottle.cookie_decode("account", secret)
db.cur.execute("SELECT id FROM user WHERE email = ?", (email, ))
user_id = db.cur.fetchone()
# write new goodlist to db
db.cur.execute("UPDATE trigger_good SET ? WHERE user.id = ?", (words, user_id, ))
return bottle.redirect("/settings")
@app.route('/settings/blacklist', method="POST")
def update_blacklist():
"""
Writes the blacklist textarea on /settings to the database.
This function expects a multi-line string, transmitted over the textarea form.
:return: redirect to settings page
"""
# get new blacklist
words = bottle.request.forms.get("blacklist")
# get user.id
email = bottle.cookie_decode("account", secret)
db.cur.execute("SELECT id FROM user WHERE email = ?", (email, ))
user_id = db.cur.fetchone()
# write new goodlist to db
db.cur.execute("UPDATE trigger_bad SET ? WHERE user.id = ?", (words, user_id, ))
return bottle.redirect("/settings")
@app.route('/enable', method="POST")
def enable():

View File

@ -65,11 +65,33 @@
</form>
</section>
<!-- login with e-mail -->
<!-- offer mailing list creation button -->
<!-- good list entry field -->
<p>
Those words have to be contained in a report.
If none of these expressions is in the report, it will be ignored by the bot.
You can use the defaults, or enter some expressions specific to your city and language.
</p>
<form action="/settings/goodlist" method="post">
<textarea name="goodlist" wrap="physical">
<!-- find a way to display current good list. js which reads from a cookie? template? -->
</textarea>
<button type="submit">Submit trigger words</button>
</form>
<!-- blacklist entry field -->
<p>
Those words are not allowed in reports.
If you encounter spam, you can add more here - the bot will ignore reports which use such words.
<!-- There are words which you can't exclude from the blacklist, e.g. certain racist, sexist, or antisemitic slurs. (to be implemented) -->
</p>
<form action="/settings/blacklist" method="post">
<textarea name="blacklist" wrap="physical">
<!-- find a way to display current blacklist. js which reads from a cookie? template? -->
</textarea>
<button type="submit">Submit blacklist</button>
</form>
<script src="/static/js/functions.js"></script>