An application to manage niceties delivered by recursers at the end of their batch.
This application is pretty simple. It stores niceties as text and some metadata associated with a unique (author, recipient, batch) tuple. This is stored in a Postgres database. Faculty can view and edit all the niceties. Recursers can see all the nice things said about them, and all the things they have said in the past.
The backend is in Flask, and is just a REST API. The DB is Postgres, with SQLAlchemy as an ORM and Alembic to manage schema migrations. The frontend is in react, because it's 2016 and that's the current hotness.
I built this using Python 3.6.13, node.js 14.15.5 and Postgres 12.6.
-
Clone the repository into an appropriate location.
-
Set up your Python virtual environment by running
pyvenv venv
in that directory and runningsource venv/bin/activate
to active it. -
Install Python requirements with
pip install -r requirements.txt
. You may need to install some build prerequisites; on Debian-like systems, they include the packagespython3-dev
andlibpq-dev
. -
Install the frontend requirements with
npm install
. -
Install PostgreSQL and create an empty database, e.g.
createdb rcniceties
-
Set the following environment variables, noting that the application will not run if any of these is not set:
FLASK_APP
- the location of the app, e.g.backend:app
FLASK_SECRET_KEY_B64
- a base64-encoded random secret string, for example generated by running:from base64 import b64encode from os import urandom print(b64encode(urandom(24)))
DATABASE_URL
- the database connection URLe.g. postgres://localhost/rcniceties
RC_OAUTH_ID
- your Recurse Center OAuth application IDRC_OAUTH_SECRET
- your Recurse Center OAuth application secretDEV
- set to eitherTRUE
orFALSE
, depending on if this is a development or production environmentDEBUG_SHOW_ALL
(optional) - set toTRUE
to show every nicety in the DB on the Niceties For Me page (useful for debugging) orFALSE
(default) for normal behavior
A common way of setting up these environment variables is with a
.env
file in your project directory, containingexport ENV_VAR=value
on each line. This can be loaded by runningsource .env
and will be automatically loaded byheroku local
. -
Optionally mock out the RC API by setting
MOCK_OUT_RC_API = True
inbackend/__init__.py
. This means you do not have to setRC_OAUTH_ID
orRC_OAUTH_SECRET
, but you'll only get sample data (contained in themock/fixtures
folder, and with request -> filename mapping inmock/rc.py
). Alternatively, you'll need to set up an RC application with a redirect URI pointing to your local server (e.g.http://localhost:8000/login/authorized
) or with the special valueurn:ietf:wg:oauth:2.0:oob
. -
At the command prompt, run
flask db upgrade
to create the DB tables. -
Run
python
, and inside it run:from backend import config config.set_to_default()
To run:
-
Compile the frontend static files by running
npm run build
. -
Run the Flask application with
gunicorn backend:app --log-file -
.
This is designed to be deployed to Heroku. To do this:
-
Enable the Python and node.js buildpacks for the application.
-
Set up a Postgres database for the application and run
heroku pg:push [database-name] DATABASE_URL
to copy your local database to Heroku.