csmberkeley / csm_web

Web applications for CS Mentors.
https://scheduler.csmentors.org/
MIT License
15 stars 10 forks source link
berkeley computer-science-education csm edtech education educational-software educational-technology scheduler uc-berkeley

CSM Web Applications

This repository contains webapps that help support the infrastructure of CSM. Currently, it only holds Scheduler (our section signup and attendance system), but more are on the way.

If you're unfamiliar with CSM and/or its web applications, check out this repository's releases for a peek at what our web applications look like and what we've been working on lately.

Installing

Requirements

We don't know what specific minimum version you would need for any of the following software, but the most recent version of any of the below should work.

Other miscellaneous requirements will be installed by the commands below.

Setup

To ensure package version consistency and avoid polluting your global package installations, we highly recommend running the server with a virtual environment. Python's standard library includes venv, so you do not need to install anything new here.

Firstly, make sure you have the right python version (see runtime.txt for the expected python version to install). If you're using pyenv to manage python versions (this is recommended), you can install the specified python version with pyenv install <version>.

Next, make sure that your current python version is correct (i.e. as specified in the previous section); if it is different, then change to the correct python version. That is, with pyenv, run pyenv local <version>; with asdf, run asdf local python <version>.

Finally, run ./setup.sh. This will install additional requirements needed by the server, and set up some necessary environment variables. In particular, the setup script installs all dependencies locally and builds the Docker images.

Note that generally, you should not need to run setup.sh after first setting up the repository.

Running

To start the Django server and other services, make sure Docker is up and run docker compose up -d. This will start Django, automatically compile and watch frontend files, and start a development database. (The -d puts the process in the background.)

To generate test data, run docker compose exec django python3 csm_web/manage.py createtestdata. In general, if you'd like to run any commands in the Django docker container, run docker compose exec django <command>. (You can make an alias in your shell if you'd like to avoid typing all of this each time.)

If all of the above has worked, visit http://localhost:8000 in your browser and you should see a log in screen; don't actually use this to actually log in locally. Visit http://localhost:8000/admin/ to log in instead.

Any changes will automatically reload the server in the docker containers, but you will usually need to force refresh (ctrl + shift + R or cmd + shift + R on most browsers) for frontend changes to be reflected (this clears the browser cache for the page).

During development, you should use the virtual environment as much as possible---while Docker makes this less necessary, your choice of editor may require the dependencies in the virtual environment. To activate the virtual environment, you can use poetry shell (this will start a new nested shell instance), or you can use source .venv/bin/activate (more generally, source $(poetry env info --path)/bin/activate).

Troubleshooting

setup.sh Errors

Error: pg_config executable not found.

    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:
./setup.sh:41: no such file or directory: /Users/jhshi/Documents/csm/csm_web/venv/.project_dir
./setup.sh:44: no such file or directory: /Users/jhshi/Documents/csm/csm_web/venv/bin/activate
./setup.sh:47: no such file or directory: /Users/jhshi/Documents/csm/csm_web/venv/bin/activate

How do I access the /admin page?

from scheduler.models import *
# replace "my_username" with the prefix of your Berkeley email, as in "my_username@berkeley.edu"
user = User.objects.get(username="my_username")
user.is_staff = True
user.is_superuser = True
user.save()

Miscellaneous

OSX: error on running pip

Try replacing pip with pip3 instead.

OAuth errors when trying to sign in locally

Error 401: invalid_client
The OAuth client was not found.

OAuth secrets are sourced from the heroku repository: you'll need to log in to heroku, add the appropriate remote, rerun setup.sh, and then reactivate your virtualenv.

On runserver, long stack trace ending with this:

django.db.utils.OperationalError: could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

Your PostgreSQL server is likely not running. On MacOS, run brew services start postgres before invoking runserver again; on Unix, run sudo service postgresql restart before invoking runserver again.