This repository contains pet project - fastapi application designed for saving person's favourite color :)
Link to the working site here - color.zirochka.me (currently turned off).
-
Setup and activate your local python environment. Here are few guides on how to do it.
-
Install requirements:
pip install -r requirements-ci.txt
-
Create
.env
file:cp app/.env.template app/.env
-
Setup PostgreSQL. You have few options:
4.1. you can use any already existing PostgreSQL (in docker, in any cloud provider, etc.):
- create new database;
- update
DATABASE_URL
in.env
file;
4.2. you can setup PostgreSQL locally:
- for example, you can use this guide or any other guide;
- after setting up PostgreSQL locally create new database:
psql postgres -c 'create database save_favourite_color;'
-
Apply migrations to your database:
flask db upgrade
-
Run application:
gunicorn -c gunicorn_config.py "app:create_app()"
-
Go to 127.0.0.1:8080 in your web browser.
To run tests use following command:
python -m pytest
Note: tests will be run using DATABASE_URL_TEST
, so you need to create new database and update DATABASE_URL_TEST
.
If you want to check code coverage use following command:
python -m pytest --cov=app
Right now the site offers following features:
- Register new users.
- Login into user's account.
- Logout from user's account.
- For unknown urls show 404 page.
- Admin accounts:
- Admins can see a list of all colors with their info on appropriate separate page.
- Admins can add new colors to database from appropriate separate page.
- Admins can see a list of all users with their info on appropriate separate page.
- Admins can deactivate users from appropriate separate page.
- Share link to user's favourite color.
Below is a list of what needs to be done:
- Migrate from SQLite to PostgreSQL.
- Let users edit their favourite color.
- Cover project with tests.
- Run tests on GitHub.
- Use
werkzeug.security
for passwords instead of plain text. - Use flask-debugtoolbar.
- Migrate from PostgreSQL to MongoDB.
- Add admin accounts:
- Add
is_admin
field tousers
tableor create completely different table for admins. - All pages for admin user should look the same as the ones for regular user.
- Allow admin to see a list of all colors with their info (link to appropriate page should be in admin panel).
- Allow admin to add colors to
colors
table (link to appropriate page should be in admin panel). - Allow admin to see a list of all users with their info (link to appropriate page should be in admin panel).
- Allow admin to deactivate users (link to appropriate page should be in admin panel).
- Add
- Let users share link to their favourite color. This page should:
- have the following text at the center oh the screen - "{color} is the favourite color of {username}.";
- have a block with color filling;
- show headers like
404 page
meaning that some headers should be shown for logged-in user (likeSetting
,Log out
, etc.) and some other headers should be shown for not logged-in user (likeLog in
,Sign up
, etc.).