Diese Django-Webanwendung wurde im Rahmen des Bachelor Praktikums 2021/22 entwickelt.
PPSV is a platform for students to select and manage their topics in courses like seminars or practica. Additionally, students are able to do this alone or in selfmade groups.
This repository contains a Django project with several apps.
PPSV has two types of requirements: System requirements are dependent on the operating system and need to be installed manually beforehand. Python requirements will be installed inside a virtual environment (strongly recommended) during a setup.
- Python 3.7+ incl. development tools
- Virtualenv
Python requirements are listed in requirements.txt
. They can be installed with pip using -r requirements.txt
- Create a new directory that should contain the files in the future, e.g.
mkdir seminarplatzvergabe
- Change into that directory
cd seminarplatzvergabe
- Clone this repository
git clone URL .
Manual Setup
- Set up a virtual environment using the proper python version
virtualenv venv -p python3
- Activate virtualenv
source venv/bin/activate
- Install python requirements
pip install -r requirements.txt
- Set up necessary database tables etc.
python manage.py migrate
- Setup initial revision for all registered models for versioning
python manage.py createinitialrevisions
- Compile translations
python manage.py compilemessages
- Create a privileged user, credentials are entered interactively on CLI
python manage.py createsuperuser
- Deactivate virtualenv
deactivate
Development Server
To start the application for development use python manage.py runserver
from the project directory.
Do not use this for deployment!
In your browser, access http://127.0.0.1:8000/
and continue from there.
Manual Setup
- Set up a virtual environment using the proper python version virtualenv venv -p python3`
- Activate virtualenv
.\venv\Scripts\activate
- Install python requirements
pip install -r requirements.txt
- Set up necessary database tables etc.
python manage.py migrate
- Setup initial revision for all registered models for versioning
python manage.py createinitialrevisions
- Prepare static files (can be omitted for dev setups)
python manage.py collectstatic
- Compile translations
python manage.py compilemessages
- Create a privileged user, credentials are entered interactively on CLI
python manage.py createsuperuser
- Deactivate virtualenv
deactivate
Development Server
To start the application for development use python manage.py runserver
from the project directory.
Do not use this for deployment!
In your browser, access http://127.0.0.1:8000/
and continue from there.
This application can be deployed using a web server as any other Django application.
Remember to use a secret key that is not stored in any repository or similar. It should not be necessary to disable
DEBUG mode in settings.py
when using settings_production.py
as later described in this tutorial.
Step-by-Step Instructions
-
Log into your system with a sudo user
-
Install system requirements
-
Create a folder, e.g.
mkdir /srv/seminarplatzvergabe/
-
Change to the new directory
cd /srv/seminarplatzvergabe/
-
Clone this repository
git clone URL .
-
Set up a virtual environment using the proper python version
virtualenv venv -p python3
-
Activate virtualenv
source venv/bin/activate
-
Update tools
pip install --upgrade setuptools pip wheel
-
Install python requirements
pip install -r requirements.txt
-
Install postgres
-
Create postgres user and database and grant rights (insert suitable names for username and dbname)
- sudo -u postgres createuser username
- sudo -u postgres createdb dbname
- sudo -u postgres psql
- psql=# alter user with encrypted password '';
- psql=# grant all privileges on database to ;
-
Create the file
ppsv/settings_secrets.py
(copy fromsettings_secrets.py.sample
) and fill it with the necessary secrets (e.g. generated bytr -dc 'a-z0-9!@#$%^&*(-_=+)' < /dev/urandom | head -c50
) (it is a good idea to restrict read permissions from others) Set the host in the file asHOSTS = ['*']
If necessary enable uwsgi proxy plugin for Apache e.g.a2enmod proxy_uwsgi
-
Edit the apache config to serve the application and the static and media files, e.g. on a dedicated system in
/etc/apache2/sites-available/000-default.conf
within theVirtualHost
tag add:Alias /static /srv/seminarplatzvergabe/ppsv/static <Directory /srv/seminarplatzvergabe/ppsv/static> Require all granted </Directory> Alias /media /srv/seminarplatzvergabe/ppsv/media <Directory /srv/seminarplatzvergabe/ppsv/media> Require all granted </Directory> ProxyPassMatch ^/media/ ! ProxyPassMatch ^/static/ ! ProxyPass / uwsgi://127.0.0.1:3035/
or create a new config (.conf) file (similar to
apache-seminarplatzvergabe.conf
) replacing $SUBDOMAIN with the subdomain the system should be available under, and $MAILADDRESS with the e-mail address of your administrator and $PATHTO with the appropriate paths. Copy or symlink it to/etc/apache2/sites-available
. Then activate it witha2ensite apache-seminarplatzvergabe
. -
Restart Apache
sudo apachectl restart
-
Create a dedicated user, e.g.
adduser django --disabled-login
-
Transfer ownership of the folder to the new user
chown -R django:django /srv/seminarplatzvergabe
-
Make sure your
wsgi.py
looks like thisimport os, sys from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings_production") sys.path.append('srv/seminarplatzvergabe/ppsv/ppsv') application = get_wsgi_application()
-
Copy or symlink the uwsgi config in
uwsgi-seminarplatzvergabe.ini
to/etc/uwsgi/apps-available/
and then symlink it to/etc/uwsgi/apps-enabled/
using e.g.,ln -s /srv/seminarplatzvergabe/uwsgi-collab-coursebook.ini /etc/uwsgi/apps-available/seminarplatzvergabe.ini
and
ln -s /etc/uwsgi/apps-available/seminarplatzvergabe.ini /etc/uwsgi/apps-enabled/seminarplatzvergabe.ini
-
Test your uwsgi configuration file with
uwsgi --ini uwsgi-seminarplatzvergabe.ini
It should contain the following lines:chdir = /srv/seminarplatzvergabe/ppsv wsgi-file = ppsv/wsgi.py env = DJANGO_SETTINGS_MODULE=ppsv.settings_production
-
Restart uwsgi
sudo systemctl restart uwsgi
-
Prepare static files
python manage.py collectstatic
-
Execute the update script
bash update_prod.sh
or./update_prod.sh
-
If not already active on that server, obtain an SSL certificate, e.g., through Let's Encrypt
This repository contains a Django project called seminarplatzvergabe. The functionality is encapsulated into Django apps:
- course: This app contains the general Django models used to represent courses, students, etc.
- frontend: This app provides everything the users see when interacting with the platform
- ppsv: This directory contains basic settings.
- to regenerate translations use
python manage.py makemessages -l de_DE --ignore venv
- to create a data backup use
python manage.py dumpdata --indent=2 > db.json --traceback