Skip to content
UWA Masters of Pharmacy Case Study Management Application written for Dr. Kenneth Lee using the Django Framework
Python HTML JavaScript CSS
Branch: master
Clone or download
This branch is even with 320011:master.

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
core
.gitignore
LICENSE
README.md
integration-test.side
requirements.txt
sass.sh

README.md

Case · Django 2.2.4 Python 3.7.2

Case is a web application written using the Django Framework for Dr. Kenneth Lee and students studying Pharmacy at the University of Western Australia.

The purpose of the application is to allow students to populate a database with case studies that they have experienced, so that other users can attempt the case. Additionally it gives students an opportunity to try more cases, than currently available in the course.

Authors

License

This project is licensed under the MIT License.

Deployment

Database Server

  1. Install postgres 9.5 or greater

  2. Set up postgres database for case with associated user

  3. Allow postgres connections to the app server

App Server:

Distribution: Red Hat Enterprise 7

  1. Install EPEL repo
yum install epel-release
  1. Install required packages
yum install python-pip python-devel gcc nginx
  1. Clone the project
git clone https://github.com/320011/case
  1. Set up and activate a virtualenv inside case root
pip install virtualenv
virtualenv venv
. venv/bin/activate
  1. Install pip requirements (including production specific)
pip install -r requirements.txt
pip install gunicorn psycopg2-binary
  1. Create local_settings.py file in the same directory as settings.py and populate it with required data
import os

ALLOWED_HOSTS = ["example.com"]

DEBUG = False

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

STATIC_ROOT = "/path/to/static/for/nginx"

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'db_name',
        'USER': 'db_user',
        'PASSWORD': 'db_pass',
        'HOST': 'db_host',
    }
}

EMAIL_USE_TLS = True
EMAIL_HOST = 'my.smtp.server'
EMAIL_HOST_USER = "case@example.com"
EMAIL_HOST_PASSWORD = "email_app_password"
EMAIL_PORT = 587
  1. Collect static files for Nginx to serve
python manage.py collectstatic
  1. Create systemd daemon for gunicorn
vim /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=case_linux_user
Group=nginx
WorkingDirectory=/path/to/repo/core
ExecStart=/path/to/repo/venv/bin/gunicorn --workers 3 --bind unix:/path/to/repo/case.sock core.wsgi:application

[Install]
WantedBy=multi-user.target
  1. Create an Nginx server block inside http {...} (or use SSL here)
vim /etc/nginx/nginx.conf
http {
    ...
    
    server {
        listen 80;
        server_name example.com;

        location = /favicon.ico {
            alias /path/to/staticfiles/favicon.ico;
        }
        location /static/ {
            alias /path/to/staticfiles/;
        }

        location / {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass http://unix:/path/to/repo/case.sock;
        }
    }
    
    ...
}
  1. Allow port 80 through the firewall

  2. Grant nginx file permissions to execute (important) your staticfiles directory

  3. Compile scss files into css. Follow the instructions here to download sass and compile

  4. Once the database is running, migrate our django models to it

python manage.py makemigrations
python manage.py migrate
  1. Start and enable systemd daemons
systemctl start gunicorn
systemctl enable gunicorn
systemctl start nginx
systemctl enable nginx
You can’t perform that action at this time.