Source code for the UPE website at UC Berkeley.
- Simpler models are better
- Commit all of your migration scripts
- Don't commit unnecessary stuff (settings.py...)
- Do not store things like passwords and auth in code/on git
- Use "_" for filenames
- Use "-" for class names
- Use Font Awesome for icons
- Don't use JS if it's doable using CSS3
- Use good markup: Make things extensible, use classes and IDs efficiently, use the right semantics
- snake_case for variables and functions, CamelCase for objects and models
- 4 spaces per tab, spaces only
Setup (for devs)
- Docker Compose lets us run the two services (web and database) with their own sub network
- Clone this repo if you haven't already
docker-compose up -dto build and start the containers (run this command in the same directory as the
- Now we need to run
docker-compose run web python3 /opt/website/manage.py syncdband create an admin account
- Restart our web container so things work well.
docker-compose restart web
- You should be able to access the website now from your machine on port 8001 (i.e. go to your web browser and go to 127.0.0.1:8001). Isn't that simple?
Notes on the Docker Setup
- We defined our Django web application to be part of the "web" service and the MySQL database to be part of the "database" service in the
- Any edits you make in the should be reflected in your Docker Container - if you look at the compose file, we mounted
.(current directory containing the website files) to
/opt/websitein the container
- When you make changes, you may need to restart the container for those changes to be reflected. To do this, use the command
docker-compose restart webto restart the web service.
- When you need to run Django commands (e.g.
makemigrations), just use docker-compose:
docker-compose run web python3 /opt/website/manage.py <command>
- If things don't seem to be working, just try restarting the web service again
- Database volume should persist since we created a volume through Docker
Installation (For Mac -- skip if windows)
- Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Have Python 3 installed (
brew install python3)
pip3installed (Should come with step 2)
pip3 install virtualenv
- Clone this git repo
- In the git repo, create a virtual env
virtualenv --python=/path/to/python3 venvYou probably can get away with
virtualenv venv, but if you see python2.7 somewhere in the command log. Use the command
which python3to figure out where python3 is installed.
--pythonlets you choose which Python installation to use. If you have something like Anaconda-Python, perhaps you want to use the Homebrew Python3 instead
- Start the virtual env:
- Install mysql 5.5 (Google mysql 5.5. install; on Debian/Ubuntu, should need to use apt to install
libmysqlclient-devand its dependencies)
- You should get a config asking you to set a root password when installing
mysql-server. Set this to something you'll remember.
- Install requirements
sudo pip3 install -r requirements.txt
Setting up mysql
- Ensure your mysql server is running
- Enter the shell with the command
mysql -u root -pto login as root. Enter the password you made earlier.
- Create the
upedatabse by running the command
CREATE DATABASE upe;my
- Also run
CREATE USER admin IDENTIFIED BY 'littlewhale';. Then grant your user permissions:
GRANT ALL PRIVILEGES ON upe.* TO 'admin';
\qto quit the mysql server shell.
Final Stretch: Getting Django to run
- Rename the template
settings.py. Never commit this!
- Now you are ready to do
python3 manage.py syncdb
- If successful, Django should ask you to install superusers. Say yes, and use a one-character username/password for ease.
- Now you can run
python3 manage.py runserver. This will be your go-to command when you develop.
localhost:8000in your server. You should now see the UPE website locally!
- Wrapping up: you can do Ctrl-C to stop the server, and then run
deactivatein the terminal to stop the virtualenv.
Loading old data into database
You can load some of the old data into the database for testing purposes. Here's how
20. Get the database dump json file from your lovely committee chairs
21. Run the following command:
python3 manage.py loaddata /path/to/json/file and your data will be loaded!
To change your local django admin username/password
- To change the password: follow the instructions here
- To change the username:
python3 manage.py runserver, then go to
localhost:8000/admin>Users and modify the user.
Server Deployment Checklist
- Make sure models are good to go:
python3 manage.py migrate. (
makemigrationsshould be done locally and then committed to Git)
- If any static files are changed, update them on the server:
python3 manage.py collectstatic
Mailing List Documentation
To make sure that the update script (
update.sh) runs, the owner of all the postfix-related files must be
- e.g. if edits to
virtualchanges the owner, do
chown postfix virtual.