A backend for the CSUA interblags.
Current Maintainer: Robert Quitt [email protected]
- Create a fork of this repo
- Clone your fork to your local/development machine
- Install dependencies locally
- Make changes locally, test, repeat
- Commit those changes
- Push commits to your fork
- Make a pull request
- Install Python 3
- Install Django and dependencies with
pip3 install --user -r requirements.txt
- Create your
.env
file by copying.env.dev
, e.g.cp .env.dev .env
- Set up local db with
python3 manage.py migrate
- Visit the admin page at http://127.0.0.1:8000/admin/ to add a semester object
- Run server with
python3 manage.py runserver
- Navigate web browser to http://127.0.0.1:8000/
- Create admin user with
python3 manage.py createsuperuser
- Make changes to
db_data/models.py
python3 manage.py makemigrations
on your development machinepython3 manage.py migrate
to apply new migrations to your local db- Commit and push your changes to
models.py
as well as generatedmigrations/
- Pull latest changes on remote machine
python3 manage.py migrate
on remote machine to update database with latest models- Run
sudo systemctl reload csua-backend-gunicorn
on the remote machine so the changes take effect
Go to https://www.csua.berkeley.edu/admin/ to edit data!
Django's online documentation has more detail on a project's structure
apps/
- This Django project is divided into "apps" (i.e.
main_page/
,db_data/
, etc.) csua_backend/
holds the projects's configurations- Each app is divided into:
migrations/
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)
- This Django project is divided into "apps" (i.e.
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 bymanage.py
'scollectstatic
)templates/
holds the html templates that are populated and served by viewsmanage.py
is a command-line script for performing actions on the project
python3 manage.py dumpdata db_data > fixtures/$(date +db_data-%m%d%y.json)
ssh
intotap.csua.berkeley.edu
- Change directory to the project directory
git pull
python3 manage.py collectstatic
to update static images- If you're making changes to the db models, follow those instructions too
fab -H <user>@tap.csua.berkeley.edu deploy
- Profit
- This Django app runs as on a
gunicorn
server ontap
. - The
gunicorn
process is managed bysystemd
and the service file is located at/etc/systemd/system/csua-backend-gunicorn.service
- This service can be manipulated with
systemctl
- To reload the wsgi app, run
sudo systemctl reload csua-backend-gunicorn
- To reload the wsgi app, run
- This service can be manipulated with
tap
runs debian 9.8 (stretch), we are using Python 3.5. This may change in the near future, as I (Robert) just installed Python 3.6 from source. This means you cannot use any Python 3.6+ features such as:- formatted string literals (f-strings) (e.g.
print(f"Oh yea yea {globals()}")
) - Underscores in numeric literals (e.g.
69_420_000
) - Typing hints (e.g.
primes: List[int] = []
)
- formatted string literals (f-strings) (e.g.
- The app is behind an Nginx proxy.
- Nginx serves the static and media files, homedirs, and forwards all other requests to the app.
- https://github.com/CSUA/services-nginx/blob/master/sites-available/www.csua.berkeley.edu
/etc/nginx/sites-available/www.csua.berkeley.edu
mysqlclient
is installed and necessary for deployment ontap
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