add ability to store an email for a user for recommendations
This commit is contained in:
parent
970a9e24cf
commit
49995465df
@ -124,6 +124,11 @@ def get_last_active_db(flag='r', autocommit=True):
|
|||||||
ladb = SqliteDict(DICT_DB_FILE, tablename='last_active', flag=flag, autocommit=autocommit)
|
ladb = SqliteDict(DICT_DB_FILE, tablename='last_active', flag=flag, autocommit=autocommit)
|
||||||
return ladb
|
return ladb
|
||||||
|
|
||||||
|
def get_email_db(flag='r', autocommit=True):
|
||||||
|
assert flag in ['r', 'c']
|
||||||
|
edb = SqliteDict(DICT_DB_FILE, tablename='email', flag=flag, autocommit=autocommit)
|
||||||
|
return edb
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
"""
|
"""
|
||||||
our "feature store" is currently just a pickle file, may want to consider hdf5 in the future
|
our "feature store" is currently just a pickle file, may want to consider hdf5 in the future
|
||||||
|
|||||||
23
serve.py
23
serve.py
@ -8,6 +8,7 @@ ideas:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
from random import shuffle
|
from random import shuffle
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ from flask import render_template
|
|||||||
from flask import g # global session-level object
|
from flask import g # global session-level object
|
||||||
from flask import session
|
from flask import session
|
||||||
|
|
||||||
from aslite.db import get_papers_db, get_metas_db, get_tags_db, get_last_active_db
|
from aslite.db import get_papers_db, get_metas_db, get_tags_db, get_last_active_db, get_email_db
|
||||||
from aslite.db import load_features
|
from aslite.db import load_features
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@ -291,6 +292,9 @@ def inspect():
|
|||||||
@app.route('/profile')
|
@app.route('/profile')
|
||||||
def profile():
|
def profile():
|
||||||
context = default_context()
|
context = default_context()
|
||||||
|
with get_email_db() as edb:
|
||||||
|
email = edb.get(g.user, '')
|
||||||
|
context['email'] = email
|
||||||
return render_template('profile.html', **context)
|
return render_template('profile.html', **context)
|
||||||
|
|
||||||
@app.route('/stats')
|
@app.route('/stats')
|
||||||
@ -406,3 +410,20 @@ def login():
|
|||||||
def logout():
|
def logout():
|
||||||
session.pop('user', None)
|
session.pop('user', None)
|
||||||
return redirect(url_for('profile'))
|
return redirect(url_for('profile'))
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# user settings and configurations
|
||||||
|
|
||||||
|
@app.route('/register_email', methods=['POST'])
|
||||||
|
def register_email():
|
||||||
|
email = request.form['email']
|
||||||
|
|
||||||
|
if g.user:
|
||||||
|
# do some basic input validation
|
||||||
|
proper_email = re.match(r'^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$', email, re.IGNORECASE)
|
||||||
|
if email == '' or proper_email: # allow empty email, meaning no email
|
||||||
|
# everything checks out, write to the database
|
||||||
|
with get_email_db(flag='c') as edb:
|
||||||
|
edb[g.user] = email
|
||||||
|
|
||||||
|
return redirect(url_for('profile'))
|
||||||
|
|||||||
@ -242,3 +242,7 @@ body {
|
|||||||
margin: 10px 40px 0 40px;
|
margin: 10px 40px 0 40px;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
#profilewrap {
|
||||||
|
margin: 10px 40px 0 40px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
@ -4,11 +4,28 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="wrap">
|
<div id="profilewrap">
|
||||||
|
|
||||||
{% if user %}
|
{% if user %}
|
||||||
<div>
|
<div>
|
||||||
<div>Logged in user: {{ user }}</div>
|
<div>Logged in user: {{ user }}</div>
|
||||||
|
<br>
|
||||||
|
<div>
|
||||||
|
<b>Email recommendations</b>
|
||||||
|
<div>
|
||||||
|
Users can receive regular new paper recommendations via email based on their tags.
|
||||||
|
(This is still being developed, may not be running or may be unreliable.)
|
||||||
|
Register your email address below to receive these recommendations.
|
||||||
|
To stop the recommendations simply delete your email address.
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<form action="{{ url_for('register_email') }}" method="post">
|
||||||
|
<input type="text" name="email" placeholder="Email address" value="{{ email }}">
|
||||||
|
<input type="submit" value="Set">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
<div>
|
<div>
|
||||||
<a href="{{ url_for('logout') }}">Log out</a>
|
<a href="{{ url_for('logout') }}">Log out</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user