A backend for the CSUA interblags.
A Django web app that:
See issues for a list of TODOs.
python3 -m venv venv
venv/bin/pip3 install -r requirements.txt
venv/bin/pre-commit install
.env
file by copying .env.dev
, e.g. cp .env.dev .env
venv/bin/python3 manage.py migrate
venv/bin/python3 manage.py runserver
venv/bin/python3 manage.py runserver 0.0.0.0:$PORT
where $PORT
is between 8000 and 8999, and connect by going to http://soda.berkeley.edu:$PORT
venv/bin/python3 manage.py createsuperuser
If you're using GNU/Linux or OSX, use bootstrap.sh
.
pre-commit is a tool that picks up formatting and other issues before making a commit. It will automatically format your python code with black. This is so that the code is clean and consistent, making it easier to review.
Additionally, I recommend you set up autoformatting with black on-save. If you use vim, you can add this to your .vimrc:
autocmd BufWritePost *.py silent exec "!black <afile>" | exec "redraw!"
db_data/models.py
venv/bin/python3 manage.py makemigrations
on your development machinevenv/bin/python3 manage.py migrate
to apply new migrations to your local dbmodels.py
as well as generated migrations/
python3 manage.py migrate
on remote machine to update database with latest modelssudo systemctl reload csua-backend-gunicorn
on the remote machine so the changes take effectGo to https://www.csua.berkeley.edu/admin/ to edit data!
Django's online documentation has more detail on a project's structure
apps/
main_page/
, db_data/
, etc.)csua_backend/
holds the projects's configurationsmigrations/
lists the changes that have been made to the database models__init__.py
just tells python the app is a python moduleadmin.py
details how db models should be viewed in the admin interfaceapps.py
probably says that this directory is an appmodels.py
contains the database models of the apptests.py
has unit tests to test the apps functionalityurls.py
says what URLs route to which viewsviews.py
has functions that serve a "view" (webpage)fixtures/
contains database fixtures to record and bootstrap content and various database datamedia_root/
is where user-uploaded files are served fromrequirements.txt
lists the required python packages for this project.static_root/
is where static files are served from (many of which come from ./static/
and are moved here by manage.py
's collectstatic
)templates/
holds the html templates that are populated and served by viewsmanage.py
is a command-line script for performing actions on the projectAs of 2024 we no longer use Travis CI (our repo was formerly located here). Please manually deploy from Tap instead:
ssh
into tap.csua.berkeley.edu
/webserver/csua-backend/
sudo -u www-data git pull
sudo -u www-data venv/bin/python manage.py collectstatic
to update static filessudo -u www-data venv/bin/python manage.py migrate
to migrate dbsudo -u www-data venv/bin/python manage.py test
to make sure tests passsudo systemctl restart csua-backend-gunicorn
to restart servergunicorn
server on tap
.gunicorn
process is managed by systemd
and the service file is located at /etc/systemd/system/csua-backend-gunicorn.service
systemctl
sudo systemctl reload csua-backend-gunicorn
tap
runs debian 9.8 (stretch), we are using Python 3.9./etc/nginx/sites-available/www.csua.berkeley.edu
mysqlclient
is installed and necessary for deployment on tap
These changes are here so that the newuser script and deployment script run properly.
If the change, /etc/sudoers
may also need to be changed.
www-data ALL = (root) NOPASSWD: /webserver/csua-backend/apps/newuser/config_newuser
www-data ALL = NOPASSWD: /bin/systemctl restart csua-backend-gunicorn
tap
runs an OpenLDAP server. It is accessible from anywhere over TLS on port 636.
For an LDAP client to connect, it must accept our self-signed certificate.
Usually this is done by adding this line to /etc/ldap/ldap.conf
:
TLS_REQCERT allow
python3 manage.py dumpdata db_data > fixtures/$(date +db_data-%m%d%y.json)