Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit b4f0bd0

Browse files
authored
Merge pull request #83 from nuest/main
2 parents a346ce6 + 1322a52 commit b4f0bd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+702
-325
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,6 @@ geodjango/
134134
tests-ui/screenshots/
135135

136136
static/
137+
138+
139+
static/

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The folder `/fixtures` contains some test data, either as an SQL command to inse
4242
[`jq`](https://stedolan.github.io/jq/) is used for pretty-printing of the output.
4343

4444
```bash
45-
# create dump after running test_data.sql:
45+
# create dump after creating/harvesting test data:
4646
python manage.py dumpdata --exclude=auth --exclude=contenttypes | jq > fixtures/test_data.json
4747

4848
# load:
@@ -70,6 +70,9 @@ docker run --name optimetaPortalDB -p 5432:5432 -e POSTGRES_USER=optimeta -e POS
7070
python manage.py makemigrations
7171
python manage.py migrate
7272

73+
# create cache table
74+
python manage.py createcachetable
75+
7376
# collect static files
7477
python manage.py collectstatic --noinput
7578

@@ -80,7 +83,7 @@ python manage.py runserver
8083
OPTIMAP_CACHE=dummy OPTIMAP_DEBUG=True python manage.py runserver
8184
```
8285

83-
Now open a browser at <http://127.0.0.1:8000/publications/map/> for the map and <http://127.0.0.1:8000/publications/api/> for the API.
86+
Now open a browser at <http://127.0.0.1:8000/>.
8487

8588
### Debug with VS Code
8689

@@ -115,6 +118,17 @@ Configuration for debugging with VS Code:
115118

116119
Add `EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend` to the `.env` file to have emails printed to the console instead of sent via SMTP.
117120

121+
Alternatively, you can run a local STMP server with the following command and configuration:
122+
123+
```bash
124+
python -m smtpd -c DebuggingServer -n localhost:5587
125+
```
126+
127+
```env
128+
OPTIMAP_EMAIL_HOST=localhost
129+
OPTIMAP_EMAIL_PORT=5587
130+
```
131+
118132
### Create superusers/admin
119133

120134
Superusers/admin can be created using the createsuperuser command:
@@ -149,8 +163,6 @@ python -Wa manage.py test
149163
# running UI tests needs either compose configuration or a manage.py runserver in a seperate shell
150164
docker-compose up --build
151165

152-
# TODO insert test data
153-
154166
python -Wa manage.py test tests-ui
155167
```
156168

fixtures/test_data.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
"url": null,
1111
"geometry": "SRID=4326;GEOMETRYCOLLECTION (POINT (7.595730774920725 51.96944097112328), POLYGON ((7.599984296478425 51.984257653537384, 7.5715788777530975 51.97057414651397, 7.570122189613329 51.950602187631205, 7.580319006590855 51.93825551711683, 7.609054957094401 51.93035649564658, 7.659674869951374 51.942256350721436, 7.6833460522228165 51.968514669138415, 7.665137450475669 51.99229098076532, 7.626171042736502 51.98982421450293, 7.599984296478425 51.984257653537384)))",
1212
"creationDate": "2022-10-24T12:10:53.086Z",
13-
"lastUpdate": "2022-10-24T12:10:53.086Z"
13+
"lastUpdate": "2022-10-24T12:10:53.086Z",
14+
"journal": "OPTIMAP Test Journal",
15+
"timeperiod_startdate": "[\"2020-02-02\"]",
16+
"timeperiod_enddate": "[\"2022-02-20\"]"
1417
}
1518
},
1619
{
@@ -24,7 +27,10 @@
2427
"url": "http://paper.url/two",
2528
"geometry": "SRID=4326;GEOMETRYCOLLECTION (LINESTRING (9.754609563397707 52.36630414438588, 9.813062794192035 52.41569645624003, 10.141300167111496 52.36904961184797, 10.518997966087937 52.330597538337116, 10.838242534270051 52.311358956793185, 11.058566250338231 52.220550088821824, 11.535184901427073 52.15714903642342, 12.272594889905236 52.24258143981572, 12.618817872299417 52.35532056817789, 12.911084026269464 52.2976119913985, 13.144896949445211 52.50063147184562, 13.396695482095708 52.517051586549286))",
2629
"creationDate": "2022-10-24T12:10:53.086Z",
27-
"lastUpdate": "2022-10-24T12:10:53.086Z"
30+
"lastUpdate": "2022-10-24T12:10:53.086Z",
31+
"journal": "OPTIMAP Test Journal",
32+
"timeperiod_startdate": "[\"2010-01-01\"]",
33+
"timeperiod_enddate": "[\"2012-12-12\"]"
2834
}
2935
}
3036
]

fixtures/test_data.sql

Lines changed: 0 additions & 48 deletions
This file was deleted.

fly.io.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ curl -L https://fly.io/install.sh | sh
1010

1111
## Create PostGIS
1212

13-
- https://community.fly.io/t/deploying-postgis/3530
14-
- https://fly.io/docs/reference/postgres-on-nomad/
13+
- <https://community.fly.io/t/deploying-postgis/3530>
14+
- <https://fly.io/docs/reference/postgres-on-nomad/>
1515

1616
```bash
1717
flyctl postgres create
@@ -45,9 +45,9 @@ fly launch --dockerfile Dockerfile
4545

4646
Now say YES when asked if you want to create a Postgres DB.
4747

48-
> We recommend using the database_url(pip install dj-database-url) to parse the DATABASE_URL from os.environ['DATABASE_URL']
48+
> We recommend using the database_url (`pip install dj-database-url`) to parse the DATABASE_URL from os.environ['DATABASE_URL']
4949
>
50-
> For detailed documentation, see https://fly.dev/docs/django/
50+
> For detailed documentation, see <https://fly.dev/docs/django/>
5151
5252
Why not - changed configuration style to use `dj-database-uri`.
5353

@@ -142,9 +142,10 @@ and
142142

143143
<https://optimap.science/>
144144

145-
## Update allowed hosts
145+
## Update allowed hosts and configure CSRF
146146

147147
- <https://learndjango.com/tutorials/deploy-django-postgresql-flyio>
148+
- See <https://github.com/ifgi/optimetaPortal/issues/42> for links and issue description around CSRF
148149

149150
Add to `tly.toml`:
150151

@@ -154,7 +155,15 @@ Add to `tly.toml`:
154155

155156
Then `flyctl deploy`.
156157

158+
## Connect to database
159+
160+
```bash
161+
fly proxy 15432:5432 -a optimap-db
162+
```
163+
164+
Connect to database locally at port `15432`, e.g., with pgAdmin.
165+
157166
## Future
158167

159168
- Database backups, see <https://www.joseferben.com/posts/django-on-flyio/>
160-
- Health check endpoint, see <https://www.joseferben.com/posts/django-on-flyio/>
169+
- Health check endpoint, see <https://www.joseferben.com/posts/django-on-flyio/>

fly.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@ processes = []
99
dockerfile = "Dockerfile"
1010

1111
[deploy]
12-
release_command = "python manage.py migrate"
12+
release_command = "sh release_command.sh"
1313

1414
[env]
15-
OPTIMAP_ALLOWED_HOST = "*"
15+
OPTIMAP_ALLOWED_HOST = "optimap.science,optimap.fly.dev"
1616
PORT = "8000"
1717
OPTIMAP_DEBUG = false
1818
OPTIMAP_EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
19-
OPTIMAP_EMAIL_HOST= "smtp.ionos.com"
20-
OPTIMAP_EMAIL_PORT = "587"
19+
OPTIMAP_EMAIL_HOST= "smtp.ionos.de"
20+
OPTIMAP_EMAIL_PORT_SMTP = "587"
2121
OPTIMAP_EMAIL_HOST_USER = "login@optimap.science"
2222
OPTIMAP_EMAIL_USE_TLS= true
23+
OPTIMAP_EMAIL_HOST_IMAP = "imap.ionos.de"
24+
OPTIMAP_EMAIL_PORT_IMAP = "993"
25+
OPTIMAP_EMAIL_IMAP_SENT_FOLDER = "\"Gesendete Objekte\""
2326
CSRF_TRUSTED_ORIGINS = "https://optimap.science"
27+
OPTIMAP_LOGGING_CONSOLE_LEVEL = "DEBUG"
2428

2529
[experimental]
2630
allowed_public_ports = []

optimetaPortal/.env.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ OPTIMAP_DB_PORT=5432
1111

1212
OPTIMAP_EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
1313
OPTIMAP_EMAIL_HOST=smtp.gmail.com
14-
OPTIMAP_EMAIL_PORT=587
14+
OPTIMAP_EMAIL_PORT_SMTP=587
1515
OPTIMAP_EMAIL_HOST_USER=...
1616
OPTIMAP_EMAIL_HOST_PASSWORD=...
17+
OPTIMAP_EMAIL_HOST_IMAP=imap.ionos.de
18+
OPTIMAP_EMAIL_PORT_IMAP=993
1719
OPTIMAP_EMAIL_USE_TLS=True
20+
OPTIMAP_EMAIL_IMAP_SENT_FOLDER=""
21+
22+
OPTIMAP_LOGGING_CONSOLE_LEVEL=INFO

optimetaPortal/settings.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@
3131

3232

3333
# SECURITY WARNING: keep the secret key used in production secret!
34-
SECRET_KEY = env('SECRET_KEY', default='django-insecure-@(y&etxu!n5qkeyim8ineufd*c*0o20k6$q^$89md-i%qcdk57')
34+
SECRET_KEY = env('SECRET_KEY', default='django-insecure')
3535

3636
# SECURITY WARNING: don't run with debug turned on in production!
3737
DEBUG = env('OPTIMAP_DEBUG', default=True)
3838

39-
ALLOWED_HOSTS = env('OPTIMAP_ALLOWED_HOST', default=[])
39+
ALLOWED_HOSTS = [i.strip('[]') for i in env('OPTIMAP_ALLOWED_HOST', default='*').split(',')]
4040

4141
OPTIMAP_SUPERUSER_EMAILS = [i.strip('[]') for i in env('OPTIMAP_SUPERUSER_EMAILS', default='').split(',')]
4242

43+
TEST_HARVESTING_ONLINE = env('OPTIMAP_TEST_HARVESTING_ONLINE', default=False)
44+
4345
ROOT_URLCONF = 'optimetaPortal.urls'
4446

4547
AUTHENTICATION_BACKENDS = [
@@ -61,10 +63,13 @@
6163
'django_q',
6264
'drf_spectacular',
6365
'drf_spectacular_sidecar',
66+
'leaflet' # used in admin site
6467
]
6568

6669
REST_FRAMEWORK = {
6770
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
71+
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
72+
'PAGE_SIZE': 999,
6873
}
6974

7075
# https://github.com/tfranzel/drf-spectacular
@@ -139,10 +144,10 @@
139144
}
140145

141146
CACHES = {
142-
# defaults to local-memory caching, see https://docs.djangoproject.com/en/4.1/topics/cache/#local-memory-caching
147+
# defaults to database caching to persist across processes, see https://docs.djangoproject.com/en/4.1/topics/cache/#local-memory-caching
143148
'default': {
144-
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
145-
'LOCATION': 'unique-snowflake',
149+
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
150+
'LOCATION': 'cache',
146151
},
147152

148153
# use for development
@@ -166,11 +171,15 @@
166171

167172
# for testing email sending EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
168173
EMAIL_BACKEND = env('OPTIMAP_EMAIL_BACKEND', default='django.core.mail.backends.console.EmailBackend')
169-
EMAIL_HOST = env('OPTIMAP_EMAIL_HOST', default='smtp.gmail.com')
170-
EMAIL_PORT = env('OPTIMAP_EMAIL_PORT', default=587)
171-
EMAIL_HOST_USER = env('OPTIMAP_EMAIL_HOST_USER', default=False)
172-
EMAIL_HOST_PASSWORD = env('OPTIMAP_EMAIL_HOST_PASSWORD', default=False)
173-
EMAIL_USE_TLS = env('OPTIMAP_EMAIL_USE_TLS', default=True)
174+
EMAIL_HOST = env('OPTIMAP_EMAIL_HOST', default='optimeta.dev')
175+
EMAIL_PORT = env('OPTIMAP_EMAIL_PORT_SMTP', default=587)
176+
EMAIL_HOST_IMAP = env('OPTIMAP_EMAIL_HOST_IMAP', default='optimeta.imap')
177+
EMAIL_PORT_IMAP = env('OPTIMAP_EMAIL_PORT_IMAP', default=993)
178+
EMAIL_HOST_USER = env('OPTIMAP_EMAIL_HOST_USER', default='optimap@dev')
179+
EMAIL_HOST_PASSWORD = env('OPTIMAP_EMAIL_HOST_PASSWORD', default='')
180+
EMAIL_USE_TLS = env('OPTIMAP_EMAIL_USE_TLS', default=False)
181+
EMAIL_USE_SSL = env('OPTIMAP_EMAIL_USE_SSL', default=False)
182+
EMAIL_IMAP_SENT_FOLDER = env('OPTIMAP_EMAIL_IMAP_SENT_FOLDER', default='')
174183

175184
MIDDLEWARE = [
176185
'django.middleware.cache.UpdateCacheMiddleware',
@@ -273,7 +282,7 @@
273282
},
274283
'handlers': {
275284
'console': {
276-
'level': 'INFO',
285+
'level': 'DEBUG',
277286
'filters': ['require_debug_true'],
278287
'class': 'logging.StreamHandler',
279288
'formatter': 'simple'
@@ -290,12 +299,18 @@
290299
'handlers': ['console', 'mail_admins'],
291300
'level': 'INFO',
292301
},
302+
'publications': {
303+
'handlers': ['console', 'mail_admins'],
304+
'level': env('OPTIMAP_LOGGING_CONSOLE_LEVEL', default='INFO'),
305+
},
293306
'django.request': {
294307
'handlers': ['mail_admins'],
295308
'level': 'WARNING',
296309
'propagate': False,
297-
},
310+
}
298311
}
299312
}
300313

314+
CSRF_TRUSTED_ORIGINS = [i.strip('[]') for i in env('CSRF_TRUSTED_ORIGINS', default='https://localhost:8000').split(',')]
315+
301316
ADMINS = [('OPTIMAP', 'login@optimap.science')]

publications/admin.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
from django.contrib import admin
2-
"""Markers admin."""
3-
4-
from django.contrib.gis import admin
5-
2+
from leaflet.admin import LeafletGeoAdmin
63
from publications.models import Publication
74

8-
95
@admin.register(Publication)
10-
class PublicationAdmin(admin.OSMGeoAdmin):
6+
class PublicationAdmin(LeafletGeoAdmin):
117
"""Publication Admin."""
128

139
list_display = ("title", "publicationDate", "creationDate", "lastUpdate")
14-
# Register your models here.

publications/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from rest_framework import routers
44

5-
from publications.viewsets import PublicationViewSet,SubscriptionViewset
5+
from publications.viewsets import PublicationViewSet, SubscriptionViewset
66

77
router = routers.DefaultRouter()
88
router.register(r"publications", PublicationViewSet)
9-
router.register(r"subscriptions",SubscriptionViewset,basename='Subscription')
9+
router.register(r"subscriptions", SubscriptionViewset, basename='Subscription')
1010
urlpatterns = router.urls

0 commit comments

Comments
 (0)