Skip to content

Commit 03844fc

Browse files
authored
Merge pull request #75 from GeoinformationSystems/fix/setup-management-and-structure-53
Set up dependency management and package/app structure
2 parents 1b46557 + 031fb29 commit 03844fc

File tree

1 file changed

+115
-30
lines changed

1 file changed

+115
-30
lines changed

README.md

Lines changed: 115 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,75 +27,124 @@ A complete list of existing parameters is provided in the file `optimap/.env.exa
2727

2828
## Run with Docker
2929

30+
The project is containerized using Docker, with services defined in `docker-compose.yml`. To start all services, run:
31+
3032
```bash
3133
docker-compose up
34+
```
35+
36+
### Initial Setup
37+
38+
After starting the containers, apply database migrations:
3239

40+
```bash
3341
# run migrations, in the directory where docker-compose is to resolve the name "web"
3442
docker-compose run web python manage.py makemigrations
3543
docker-compose run web python manage.py migrate
3644
```
3745

38-
Now open a browser at <http://localhost:8000/>.
46+
Now open a browser at <http://localhost:8001/>.
47+
48+
#### Services Overview
49+
50+
- db: Runs a PostgreSQL database with PostGIS extensions. Data is persisted in a Docker volume named db_data.
51+
- app: Python-based app serving HTTP requests.
52+
- web: Our primary Django web application.
53+
- webserver: An Nginx server for serving static files and test files.
54+
55+
#### Ports
56+
57+
- 5434: Database (PostgreSQL/PostGIS)
58+
- 8002: App (Python HTTP server)
59+
- 8001: Web application (Django server)
60+
- 8080: Webserver (Nginx)
3961

4062
## Development
4163

42-
### Test data
64+
### Test Data
65+
66+
The folder `/fixtures` contains some test data, which can be used to populate the database during development. These data are provided either as SQL commands for insertion into the database or as database dumps that can be loaded using [`django-admin`](https://docs.djangoproject.com/en/dev/ref/django-admin/).
67+
68+
### Managing Test Data
4369

44-
The folder `/fixtures` contains some test data, either as an SQL command to insert into the database, or as a database dump that was created and can be loaded with [`django-admin`](https://docs.djangoproject.com/en/dev/ref/django-admin/).
45-
[`jq`](https://stedolan.github.io/jq/) is used for pretty-printing of the output.
70+
#### Creating Test Data Dumps
71+
72+
To create a data dump after generating or harvesting test data, use the following command:
4673

4774
```bash
48-
# create dump after creating/harvesting test data:
4975
python manage.py dumpdata --exclude=auth --exclude=contenttypes | jq > fixtures/test_data.json
76+
```
77+
78+
#### Loading Test Data
5079

51-
# load:
80+
To load the test data into your database, run:
81+
82+
```bash
5283
python manage.py loaddata fixtures/test_data.json
5384
```
5485

55-
If you want to create more testdata manually, copy and paste the existing records or add more records in the admin backend (preferred).
56-
A useful tool for creating sensible geometries is <https://wktmap.com/>.
86+
#### Adding New Test Data
87+
88+
If additional test data is required, you can:
89+
90+
- Copy and paste existing records.
91+
- Add new records via the Django admin interface (preferred method).
92+
- Manually modify the test data JSON file.
5793

58-
### Run locally
94+
Tools for Geometries
95+
For creating or editing geometries, consider using the tool [WKTMap](https://wktmap.com/), which provides an easy way to generate Well-Known Text (WKT) representations of spatial data.
5996

60-
1. Create a `.env` file based on `.env.example` in the same directory where `settings.py` resides and fill in the configuration settings as needed.
61-
2. Run the commands below, which use the built-in Python [`venv`](https://docs.python.org/3/library/venv.html), see [this tutorial](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments) for details
97+
### Run Locally
98+
99+
1. Create a `.env` file based on `.env.example` in the same directory where `settings.py` resides, and fill in the configuration settings as needed.
100+
2. Run the commands below to set up and run the project locally. This setup uses the built-in Python [`venv`](https://docs.python.org/3/library/venv.html). Refer to [this tutorial](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments) for more details.
62101

63102
```bash
64-
# once only: create virtual environment
65-
# python -m venv .venv
103+
# Create a virtual environment (once only)
104+
python -m venv .venv
105+
106+
# Activate the virtual environment
66107
source .venv/bin/activate
108+
109+
# Confirm Python path
67110
which python
68111

112+
# Install required dependencies
69113
pip install -r requirements.txt
70114

71-
# create local DB container (once)
72-
# docker run --name optimapDB -p 5432:5432 -e POSTGRES_USER=optimap -e POSTGRES_PASSWORD=optimap -e POSTGRES_DB=optimap -d postgis/postgis:14-3.3
115+
# Create a local database container (once only)
116+
docker run --name optimapDB -p 5432:5432 -e POSTGRES_USER=optimap -e POSTGRES_PASSWORD=optimap -e POSTGRES_DB=optimap -d postgis/postgis:15-3.4
73117

74-
# start DB
118+
# Start the database container
75119
docker start optimapDB
76120

77-
# run migrations
121+
# Apply database migrations
78122
python manage.py makemigrations
79123
python manage.py migrate
80124

81-
# create cache table
125+
# Create a cache table
82126
python manage.py createcachetable
83127

84-
# collect static files
128+
# Collect static files
85129
python manage.py collectstatic --noinput
86130

87-
# start app
131+
# Start the Django development server
88132
python manage.py runserver
89133

90-
# start app with configuration for development
134+
# Start the app with specific configurations for development
91135
OPTIMAP_CACHE=dummy OPTIMAP_DEBUG=True python manage.py runserver
92136
```
93137

94138
Now open a browser at <http://127.0.0.1:8000/>.
95139

96-
See instructions below for creating a superuser and above for loading test data.
140+
#### Additional Setup
97141

98-
When you are done, deactivate the virtual environment and stop the DB with:
142+
- Creating a Superuser: Refer to the instructions below to create a superuser for accessing the admin interface.
143+
- Loading Test Data: Refer to the instructions above to load test data into the database.
144+
145+
#### Shutting Down
146+
147+
When finished, deactivate the virtual environment and stop the database container:
99148

100149
```bash
101150
deactivate
@@ -119,6 +168,8 @@ OPTIMAP_DEBUG=True
119168

120169
Select the Python interpreter created above (`optimap` environment), see instructions at <https://code.visualstudio.com/docs/python/tutorial-django> and <https://code.visualstudio.com/docs/python/environments>.
121170

171+
**Note:** The `docker-compose.yml` file is intended for **development**, not deployment.
172+
122173
Configuration for debugging with VS Code:
123174

124175
```json
@@ -139,6 +190,22 @@ Configuration for debugging with VS Code:
139190
"justMyCode": true
140191
}
141192
]
193+
"version": "0.2.0",
194+
"configurations": [
195+
{
196+
"name": "Python: Django Run",
197+
"type": "python",
198+
"request": "launch",
199+
"program": "${workspaceFolder}/manage.py",
200+
"args": ["runserver"],
201+
"env": {
202+
"OPTIMAP_DEBUG": "True",
203+
"OPTIMAP_CACHE": "dummy"
204+
},
205+
"django": true,
206+
"justMyCode": true
207+
}
208+
]
142209
}
143210
```
144211

@@ -157,20 +224,27 @@ OPTIMAP_EMAIL_HOST=localhost
157224
OPTIMAP_EMAIL_PORT=5587
158225
```
159226

160-
### Create superusers/admin
227+
### Create Superusers/Admin
161228

162-
Superusers/admin can be created using the createsuperuser command:
229+
Superusers or administrators can be created using the `createsuperuser` command. This user will have access to the Django admin interface.
163230

164231
```bash
165232
python manage.py createsuperuser --username=optimap --email=nomail@optimap.science
166233
```
167234

168-
You will be prompted for a password.
169-
After you enter one, the user will be created immediately. If you leave off the --username or --email options, it will prompt you for those values.
235+
You will be prompted for a password. After entering one, the superuser will be created immediately. If you omit the --username or --email options, the command will prompt you for those values interactively.
236+
237+
Access the admin interface at http://127.0.0.1:8000/admin/.
238+
239+
#### Running in a Dockerized App
170240

171-
You can acess the admin page at <http://127.0.0.1:8000/admin/>.
241+
To create a superuser within the containerized application, use the following command:
172242

173-
You can also run the command in a containerised app with `docker-compose run web python manage.py ...`.
243+
```bash
244+
docker-compose run web python manage.py createsuperuser
245+
```
246+
247+
This will run the same process as above but within the Docker environment. Ensure the container is running and accessible before executing this command
174248

175249
## Block Emails/Domains
176250

@@ -232,6 +306,17 @@ A configuration to debug the test code and also print deprecation warnings:
232306
},
233307
"django": true,
234308
"justMyCode": true
309+
"name": "Python: Django Test",
310+
"type": "python",
311+
"request": "launch",
312+
"pythonArgs": ["-Wa"],
313+
"program": "${workspaceFolder}/manage.py",
314+
"args": ["test", "tests"],
315+
"env": {
316+
"OPTIMAP_DEBUG": "True"
317+
},
318+
"django": true,
319+
"justMyCode": true
235320
}
236321
```
237322

@@ -241,7 +326,7 @@ See also documentation at <https://code.visualstudio.com/docs/python/tutorial-dj
241326

242327
### Issues during development
243328

244-
* If you get a message during login that there is an issue with the CSRF token, e.g. `WARNING:django.security.csrf:Forbidden (CSRF token from POST incorrect.): /loginres/` in the log and also i nthe UI, then switch to using `localhost:8000` as the domain, not the localhost IP used in the examples in this README file.
329+
- If you get a message during login that there is an issue with the CSRF token, e.g. `WARNING:django.security.csrf:Forbidden (CSRF token from POST incorrect.): /loginres/` in the log and also i nthe UI, then switch to using `localhost:8000` as the domain, not the localhost IP used in the examples in this README file.
245330

246331
## Deploy
247332

0 commit comments

Comments
 (0)