Collab Coursebook is a platform for collaborative learning und knowledge organization. It provides a place to share and re-use notes and other learning materials.
This repository contains a Django project with several apps.
Collab Coursebook has two types of requirements: System requirements are dependent on 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.8+ incl. development tools
- Virtualenv
- poppler
- TeX Distribution (e.g. TeX Live)
- wkhtmltopdf (used for exporting Markdown as PDF)
- For production using uwsgi:
- C compiler e.g. gcc
- uwsgi
- uwsgi Python3 plugin
- For production using Apache (in addition to uwsgi)
- the mod proxy uwsgi plugin for apache2
Python requirements are listed in requirements.txt
. They can be installed with pip using -r requirements.txt
.
- In order to use Nestable2 correctly the dist folder is needed. This folder can be found here: https://github.com/RamonSmit/Nestable2
- The folder must be placed in
frontend/static/vendor/Nestable2
.
- The folder must be placed in
- Create a new directory that should contain the files in the future, e.g.
mkdir collab-coursebook
- Change into that directory
cd collab-coursebook
- Clone this repository
git clone URL .
Docker
For development there is a docker container. It contains only the runtime environment and is not indented for deployment usage! Build the image (may take some time, downloads complete TeXLive >4GB):
docker build -t collab .
Aterwards the container can be started with
docker run --name collab -p 8000:8000 -v "$PWD:/home/collab/collab-coursebook" -u "$(id -u):$(id -g)" -e "DOCKER_USER=$USER" collab
To restart it (for example after it crashed or the host rebooted) run
docker start collab
In your browser, access http://127.0.0.1:8000/
and continue from there.
In case you want to attach your IDE to the container, all file operations will be executed as the outside user. So no ownership problems should happen. Please note that the container does support passwordless sudo!
Automatic Setup
- Execute the setup bash script
utils/setup.sh
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
- 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
- Create the file
collab_coursebook/settings_secrets.py
(copy fromsettings_secrets.py.sample
) and fill in the YouTube API key
Development Server
To start the application for development use python manage.py runserver 0:8000
from the root 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
- Install python magic-bin
pip install python-magic-bin
- 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
- Create the file
collab_coursebook/settings_secrets.py
(copy fromsettings_secrets.py.sample
) and fill in the YouTube API key for development regarding YouTube Videos
Development Server
To start the application for development use python manage.py runserver 0.0.0.0:8000
from the root directory.
Do not use this for deployment!
In your browser, access http://127.0.0.1:8000/
and continue from there.
To be able to run PyLint, go into content/static/yt_api.py, comment out the import from secret settings and set yt_api_key = "". Otherwise PyLint will not run because it tries to import from a file that doesn't exist.
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, and disable DEBUG mode (settings.py
).
Step-by-Step Instructions
-
Log into your system with a sudo user
-
Install system requirements
-
Create a folder, e.g.
mkdir /srv/collab-coursebook/
-
Change to the new directory
cd /srv/collab-coursebook/
-
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 further python requirements
pip install psycopg2-binary uwsgi
-
Create postgres user and database and grant rights
- sudo -u postgres createuser
- sudo -u postgres createdb
- sudo -u postgres psql
- psql=# alter user with encrypted password '';
- psql=# grant all privileges on database to ;
-
Create the file
collab_coursebook/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) -
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-enabled/000-default.conf
within theVirtualHost
tag add:Alias /static /srv/collab-coursebook/static <Directory /srv/collab-coursebook/static> Require all granted </Directory> Alias /media /srv/collab-coursebook/media <Directory /srv/collab-coursebook/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-collab-coursebook.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 with a2ensite collab-coursebook
.
- 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/collab-coursebook
- Copy or symlink the uwsgi config in
uwsgi-collab-coursebook.ini
to/etc/uwsgi/apps-available/
and then symlink it to/etc/uwsgi/apps-enabled/
using e.g.,ln -s /srv/collab-coursebook/uwsgi-collab-coursebook.ini /etc/uwsgi/apps-available/collab-coursebook.ini
andln -s /etc/uwsgi/apps-available/collab-coursebook.ini /etc/uwsgi/apps-enabled/collab-coursebook.ini
- Test your uwsgi configuration file with
uwsgi --ini collab-coursebook.ini
- Restart uwsgi
sudo systemctl restart uwsgi
- Execute the update script
./utils/update.sh --prod
- If not already active on that server, obtain an SSL certificate, e.g., through Let's Encrypt
To update the setup to the current version on the main branch of the repository use the update script utils/update.sh
or utils/update.sh --prod
in production.
Afterwards, you may check your setup by executing utils/check.sh
or utils/check.sh --prod
in production.
This repository contains a Django project called collab_coursebook. The functionality is encapsulated into Django apps:
- base: This app contains the general Django models used to represent courses, contents, etc.
- frontend: This app provides everything the users see when reading or editing the content. It also contains a landing page.
- content: This app provides models, rendering- and export code for the different supported types of contents.
- export: This app contains export functions for the custom content collections (coursebooks).
- 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