Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation cleanup #31

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
include .env
export $(shell sed 's/=.*//' .env)

test:
env

up-develop:
# sleep 5 && sudo docker-compose exec web /bin/sh -c "python3 manage.py migrate" &
docker compose run web /bin/sh -c "python3 manage.py compilemessages -l en"
Expand Down
84 changes: 45 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Table of Contents
The DTEK portal. Originally written by Chalmers IT, then Viktor downloaded the
HTML and changed the colors, turning it into a simple static web page. However,
maintaining it became difficult, especially when an English version was
introduced, which was accomplished by copying the Swedish html file and changing
all the Swedish strings into English. Therefore, BS decided to rewrite the thing
in Django.
introduced, which was accomplished by copying the Swedish html file and
changing all the Swedish strings into English. Therefore, BS decided to rewrite
the thing in Django.

# Setup

Expand All @@ -32,44 +32,38 @@ The service can either be run as a self-contained service as exemplified by the
compose file or hosted by an external nginx instance. Refer to site.conf for an
example of an nginx server configuration.

Note that each `server_name` must also be added to `ALLOWED_HOSTS` in
`settings.py`.

## Starting the site

Before starting the site, you must add a few variables to the project directory
that are not checked in to Git:

* Django's secret key
* Which port to expose from the container
* Database password

There is a file in the root directory of this repo called
`.env.template`. This file should be copied into a file called
`.env`, where you define these variables according to your liking.
Django's secret key should be a "large, unpredictable value". Just google
"[Django Secret Key Generator](https://www.miniwebtool.com/django-secret-key-generator/)" and you should find something.

Once this is done and nginx is set up properly, it should be possible to start the site. First of
all, you need to build the container using `make build`.

To start the site in a development environment, (meaning DEBUG is set to TRUE in
django among other things) run `make up-develop` and the site should be
accessible at `localhost:8000` or whatever port your docker container exposes.
If django complains about having unapplied migrations, you might have to run
`(sudo) docker-compose run web python3 manage.py migrate`, then restart the
container by running `make down` followed by `make up-develop`.

To start the site in a production environment, instead run `make up-prod` after
building the container. The site should now be accessible at the domains
specified in `server_name` in the nginx config (provided that the domains in
question are pointed at the correct IP). If you want to try running the
production environment locally without pointing a domain to your IP, you can
just add that domain to your `host` file (Google is your friend).
There is a file in the root directory of this repo called `.env.template`.
This file should be copied into a file called `.env`, where you define these
variables according to your liking. Django's secret key should be a "large,
unpredictable value". Just google "[Django Secret Key
Generator](https://www.miniwebtool.com/django-secret-key-generator/)" and you
should find something.

Once this is done, it should be possible to start the site. First of all, you
need to build the container using `make build`.

To start the site in a development environment, run `make up-develop` and the
site should be accessible at `localhost:8000`. If django complains about having
unapplied migrations, you might have to run `docker compose run web python3
manage.py migrate`, then restart the container by running `make down` followed
by `make up-develop`.

## Creating a superuser

If you're starting the site for the first time, it's probably a good idea to create a superuser for the admin interface. (For now, the site is just static content, meaning the admin interface is unused and creating a superuser might not be necessary. It feels like it might be a good idea to do it anyway, though). To do this, start up the container and run `(sudo) docker-compose exec web /bin/sh -c "python3 manage.py createsuperuser`.
If you're starting the site for the first time, it's probably a good idea to
create a superuser for the admin interface. (For now, the site is just static
content, meaning the admin interface is unused and creating a superuser might
not be necessary. It feels like it might be a good idea to do it anyway,
though). To do this, start up the container and run `docker compose exec web
/bin/sh -c "python3 manage.py createsuperuser`.

# How the site works

Expand Down Expand Up @@ -102,8 +96,8 @@ Content that is specific to certain pages, such as the index page or the
newsletter page, are placed inside the `homepage` app, i.e. inside
`dtekportal/homepage/templates` or `dtekportal/homepage/static/`.

If some dynamic feature is added in the future, such as a "committee pages" feature,
this should be put in a new app.
If some dynamic feature is added in the future, such as a "committee pages"
feature, this should be put in a new app.

### URL

Expand Down Expand Up @@ -142,8 +136,9 @@ urlpatterns = [

## Creating links to internal urls

If you want to create a link to another page on the website, DON'T hardcode the url!
Instead, use django's url functions. For instance, to link to the index page in a template:
If you want to create a link to another page on the website, DON'T hardcode the
url! Instead, use django's url functions. For instance, to link to the index
page in a template:

```python
{% load static %}
Expand All @@ -160,8 +155,19 @@ parameter in the url as defined in `urls.py`.

## Translations

The website is written with Swedish as its original language. In order to make a string translatable, it must be wrapped in a function. For details on how to do this in pyton code and template code respectively, see the [Django docs on translation](https://docs.djangoproject.com/en/2.1/topics/i18n/translation/).

The mapping from Swedish to English lives in `locale/en/LC_MESSAGES/django.po`. When you have edited a file and added strings that need to be created, run `make makemessages`. This will update the .po file to contain the new strings, whose translations can now be filled in. Any translation strings that have been marked as "fuzzy" will be ignored by Django, so make sure to clean those up before finishing.

For the website to update, you need to compile the .po file. This can be done by running `make compilemessages`. If this does not work, try stopping the container using `make down` and starting it up again; the makefile is configured to compile the messages as the container starts.
The website is written with Swedish as its original language. In order to make
a string translatable, it must be wrapped in a function. For details on how to
do this in pyton code and template code respectively, see the [Django docs on
translation](https://docs.djangoproject.com/en/2.1/topics/i18n/translation/).

The mapping from Swedish to English lives in `locale/en/LC_MESSAGES/django.po`.
When you have edited a file and added strings that need to be created, run
`make makemessages`. This will update the .po file to contain the new strings,
whose translations can now be filled in. Any translation strings that have been
marked as "fuzzy" will be ignored by Django, so make sure to clean those up
before finishing.

For the website to update, you need to compile the .po file. This can be done
by running `make compilemessages`. If this does not work, try stopping the
container using `make down` and starting it up again; the makefile is
configured to compile the messages as the container starts.
2 changes: 0 additions & 2 deletions dtekportal/dtekportal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '0.0.0.0']
ALLOWED_HOSTS.extend(os.environ.get('DJANGO_ALLOWED_HOSTS', '').split(','))

#ALLOWED_HOSTS = ['localhost', 'dtek.se', 'www.dtek.se', 'local.dtek.se', 'sagge.dtek.se', 'flan2.dtek.se']


# Application definition

Expand Down
Loading