diff --git a/Makefile b/Makefile
index c848c6d..04c445c 100644
--- a/Makefile
+++ b/Makefile
@@ -69,14 +69,18 @@ django-shell:
logs:
docker-compose logs -f --tail=500
-backup:
- docker-compose start postgres
+backup-data:
docker-compose exec web ./manage.py dumpdata --natural-foreign -e auth.permission -e contenttypes -e wagtailcore.GroupCollectionPermission -e wagtailimages.rendition -e sessions -e feedler.feedlysettings > ~/publichealth.home.json
zip ~/publichealth.home.json.`date +"%d%m%Y-%H%M"`.zip ~/publichealth.home.json
rm ~/publichealth.home.json
+
+backup-images:
echo "Backing up images ..."
+ sudo chown -R ansible media
zip -ruq ~/media.zip media
+backup: backup-data backup-images
+
django-loaddata:
gunzip ~/publichealth.home.json.gz
docker-compose exec web ./manage.py loaddata ~/publichealth.home.json
diff --git a/ansible/inventories/production/group_vars/webservers/vars.yaml b/ansible/inventories/production/group_vars/webservers/vars.yaml
index 9bb422c..ef08c51 100644
--- a/ansible/inventories/production/group_vars/webservers/vars.yaml
+++ b/ansible/inventories/production/group_vars/webservers/vars.yaml
@@ -21,3 +21,9 @@ django_secret_key: "{{ vault_django_secret_key }}"
# Default: postgres://postgres:@postgres:5432/postgres
django_postgres_url: "{{ vault_django_postgres_url }}"
+
+# Default: http://elasticsearch:9200
+django_elasticsearch_url: "{{ vault_django_elasticsearch_url }}"
+
+# Default: redis://redis:6379
+django_redis_url: "{{ vault_django_redis_url }}"
diff --git a/ansible/inventories/production/group_vars/webservers/vault.yaml b/ansible/inventories/production/group_vars/webservers/vault.yaml
index aa7ab1e..a7a353e 100644
--- a/ansible/inventories/production/group_vars/webservers/vault.yaml
+++ b/ansible/inventories/production/group_vars/webservers/vault.yaml
@@ -1,32 +1,46 @@
$ANSIBLE_VAULT;1.1;AES256
-39613133383630663164333437633037383936663266623861313565663964346232643666653332
-6165666665373661643663323337656163373631366135620a663164653335333166333865383139
-34633364623536663564363536333737316638353266316261393530386330633963336233346336
-6336383237646233630a656337626566373165313264386438636230646438353131623663666236
-62633739623431656535383166343862646133396630306264636563643536373562363163316135
-38373966323162653330316135333333643637323732663530336432383066316636303231653534
-37333765313830646662663761376266386262323437373230333231616162393961396162383732
-62633431343062316365316361343432373261623439656533393331383735646639646662653133
-36303039383339353961336664343436653066626561393761383733656664663939333233396134
-63393361396334666330376362643732326266336263393730623464333436336436313639613635
-64646237333739373137356262373666356631356632323466383363356366366366666330646230
-63386232663430386139393864626333326331323031313231346630326133353137373565326538
-36633032653637316531353131653235613331333436316365316661313835373563646534353239
-38623338373365623066613832623836626135326235623538396538366663306365666135633264
-34306464663230616538343539653663326339333437303762323066343933326634633530653565
-34663963353562363132396338623435646165393431303364623834636266373164663933633339
-32346536363330303539373461376631613863656366646437343165633464623064396231346137
-30643261346465303137306161613036336339326530306162393165363766353839316262363263
-38303236633436323830356461653234666534646363336463313064386230663763323632313563
-35396233363933333463326333633737333962353830336135386339613564343237363932306362
-31333535376630363739653433663865366566356132633032666562653234373938633031323139
-61306539376464666664316461303966613231646136623937643965326139303461616366333631
-39323638633661623064623334333864633235646131353237663361343839303537306261656131
-66656331316264636261643165643861376330633035386165626166313133376538656166353136
-31303433633134323532646132386130616431383065363832326533653535663763623733353764
-63383061653062353263383739643366363763363635663165353761623832366139643065396565
-31363435613761623538383237346431613335346437616538643462316665656337343832633937
-33663266663163306461626462626132613961626238333538666233613934346631346231363833
-36633138656563643262393764663331333237386164626230383562396663336564663134356632
-39386137343662666166326131363633353536326130396361376138363132363861313832303262
-326364356331366330393435346330373561
+31623061306338643731643236656264313365323238383734373466653131336263653365396337
+3864346638623236343833646264393366666230396662300a623038333531393836356163623731
+38633239636431653935633763316639383562366332346531316632616666346532326239313933
+6135323639373465300a343438306338653633633465363938363865333530343663383838653738
+62663439333565343565666434646438346566633933333863303361373166616339626630623930
+66646162353034623439653262386130656564613962373234633234346138386132323362323839
+66656533333537303165336634346666306436626236343561343336343135346665666539643232
+65613166373464373035373666646533316365383931623966353939393765343062306230363963
+34306538383064336137313034633764316130653536353035323030326533633431633866646463
+39376234373437313334386465623837613362666337326562396364626332356463313165653661
+32333266396261306565333061323138646531376639666264353366633033646366396634623863
+61653030353061656666326561613736356461363032333937623362363734656466323032303661
+35633635353638613632653639643232313932353232386531353737663436396531396334313837
+63633333393632356166656266643165373238333237363930333132643962636263346466366130
+62343731353939336330316363613238363136366436343732353762626263663736383863356365
+61343361303933346239323165353365626431623938326464396438316332633563663465653337
+63323862393063633965383932393930326266323237643839366231666166636265623637346264
+66326662363735373638343561643239626265643630356239653536623930313564316636303130
+65383661633130323138323330633161386138646564306636643835666333316535636665626464
+37663531646130376564346261363064323434373864663939353835376262346130393338303833
+63626539633332383930373862316237363966363566383735383162396165363662363764366530
+34646135353534306237393233383764376330313234323364363834623438363537386331343934
+63343464353862616339326565626134353661353134306431326666643635383165633964353936
+30646437616436363539346433646463666535303530653533653062376633306332366237373434
+32303964633532336430343662373731356365326366383431616631373132636136653539323037
+64366334386637623436316161613535636130363162363264663033623531633932623462343331
+31343232333064623063326666323038663839643439353166346366663934353565653433366362
+33363432383533663263663761633762366633363563623237636636386337626338653238386533
+33326632646562386134343138663937346464643733616339316162653566323865643633376537
+36343636396263353037316631333933313739316135343766666432373633363166373866333632
+62623734653863303566643331303462363137346233636130333830323333323863356538356139
+37303231663966623034323138666664326236626439383638666664363531303433636662666561
+39626265323136313037383164646636653265373832663931356237343138396638376135346636
+66666536616135386666666464303539616135333064636135346430383431303037393036353435
+65306131333532663038306136303930636661373764343736383364303266356330333661386635
+34666539636239656637353131333330346563386334306535643230353439623762343932303361
+65353163346535396563383862653963326261386531363934356266653461313437633661313035
+33643766613366643065663637663733363563663633393238623633653664386630376637643464
+61316135633961636337303735656365356437653730373965343933333433386132633061363064
+37376337356262613136633431343461333237333063623834616165643637366362393137373339
+37363430393939663734303364343064666533653363656633303966613334356363316436326438
+30336236343731656566656631323737346630363538663361303734613738303462366238386563
+31623135633062666566346561386438663031383232376562623533656437333665376439653932
+66373134303762356238323962343339386161333038353038393936306434643739396464323532
+3236
diff --git a/ansible/roles/web/templates/docker-compose.j2 b/ansible/roles/web/templates/docker-compose.j2
index 20600bf..cc637a9 100644
--- a/ansible/roles/web/templates/docker-compose.j2
+++ b/ansible/roles/web/templates/docker-compose.j2
@@ -5,39 +5,39 @@ web:
volumes:
- ./:/usr/src/app
- {{ django_log_dir }}:/var/log/wagtail
- links:
- - redis
- - postgres
- - elasticsearch
+ #links:
+ # - redis
+ # - postgres
+ # - elasticsearch
ports:
- "5000:5000"
environment:
- DJANGO_SETTINGS_MODULE={{ django_project_name }}.settings.production
- - ALLOWED_HOSTS=www.{{ allowed_domains|join(',www.') }},{{ allowed_domains }},{{ ipv4_addresses|join(':5000,') }}
+ - ALLOWED_HOSTS=www.{{ allowed_domains|join(',www.') }},{{ allowed_domains|join(',') }},{{ ipv4_addresses|join(':5000,') }}
- SECRET_KEY={{ django_secret_key }}
- MAILGUN_KEY={{ django_email_key }}
- MAILGUN_DOMAIN={{ django_email_domain }}
- MAILGUN_FROM={{ django_email_from }}
- DATABASE_URL={{ django_postgres_url }}
- - ELASTICSEARCH_URL=http://elasticsearch:9200
- - REDIS_URL=redis://redis:6379
+ - REDIS_URL={{ django_redis_url }}
+ - ELASTICSEARCH_URL={{ django_elasticsearch_url }}
- LOG_DIR=/var/log/wagtail
-redis:
- image: redis
- command: ["redis-server", "--appendonly", "yes"]
- restart: on-failure
- volumes:
- - {{ redis_data_dir }}:/data
- ports:
- - "6379:6379"
-postgres:
- image: postgres
- ports:
- - "5432:5432"
-elasticsearch:
- image: elasticsearch:5
- ports:
- - "9200:9200"
- environment:
- - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- mem_limit: 1g
+# elasticsearch:
+# image: elasticsearch:5
+# ports:
+# - "9200:9200"
+# environment:
+# - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
+# mem_limit: 1g
+# redis:
+# image: redis
+# command: ["redis-server", "--appendonly", "yes"]
+# restart: on-failure
+# volumes:
+# - {{ redis_data_dir }}:/data
+# ports:
+# - "6379:6379"
+# postgres:
+# image: postgres
+# ports:
+# - "5432:5432"
diff --git a/ansible/roles/web/templates/nginx.conf.j2 b/ansible/roles/web/templates/nginx.conf.j2
index 1533fc7..4493a4e 100644
--- a/ansible/roles/web/templates/nginx.conf.j2
+++ b/ansible/roles/web/templates/nginx.conf.j2
@@ -6,21 +6,14 @@ upstream wagtail-site {
server localhost:5000;
}
server {
- listen 80 default_server;
server_name _;
-
- location / {
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header Host $http_host;
- proxy_redirect off;
- proxy_pass http://wagtail-site;
- }
+ listen 80 default_server;
+ return 301 https://$host$request_uri;
}
server {
- listen 443 ssl default_server;
server_name _;
-
+ listen 443 ssl default_server;
+
ssl on;
ssl_certificate /etc/certs/public-health.ch/cloudflare.pem;
ssl_certificate_key /etc/certs/public-health.ch/cloudflare.key;
@@ -39,7 +32,7 @@ server {
access_log off; expires 36000;
alias {{ release_dir }}/static/;
add_header Cache-Control "public";
- add_header Access-Control-Allow-Origin https://{{ domain }};
+ add_header Access-Control-Allow-Origin *; #https://{{ domain }};
}
# Set a longer expiry for CACHE/, because the filenames are unique.
@@ -54,18 +47,30 @@ server {
alias {{ release_dir }}/static/images/favicon.ico;
}
- # Only serve /media/images by default, not e.g. original_images/.
- location /media/images {
- alias {{ release_dir }}/media/images;
- access_log off; expires max;
+ # Directly serve media with max caching
+ location /media {
+ root {{ release_dir }};
+ autoindex off;
+ access_log off;
+ expires max;
add_header Cache-Control "public";
}
+ # Only serve media by default, not e.g. original_images/.
+ #location ~* ^/media {
+ # alias {{ release_dir }}/media;
+ #}
+
# Disable English home page (for now)
- if ($host = 'public-health.ch') {
+ if ($host !~* 'sphc.ch') {
rewrite ^/en/$ $scheme://$host/de/;
}
+ # Redirect French home page as appropriate
+ if ($host = 'manifestesante.ch') {
+ rewrite ^/$ $scheme://$host/fr/;
+ }
+
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
diff --git a/feedler/management/commands/invalidpage.py b/feedler/management/commands/invalidpage.py
new file mode 100644
index 0000000..474df36
--- /dev/null
+++ b/feedler/management/commands/invalidpage.py
@@ -0,0 +1,31 @@
+from django.core.management.base import BaseCommand
+from django.contrib.auth.models import User
+from django.test import Client
+
+from wagtail.core.models import Page
+from wagtail.admin.views.pages import edit
+
+# Scans for broken editors, via
+# https://github.com/wagtail/wagtail/issues/4602
+
+class Command(BaseCommand):
+
+ def handle(self, **options):
+ invalid_page_ids = []
+ pages = Page.objects.all()
+ client = Client()
+ # use any existing super user account
+ user = User.objects.get(username='oleg')
+ client.force_login(user)
+
+ for page in pages:
+ id = page.id
+ # print statement to assure the script is running
+ print(id)
+ url = f'/cms/pages/{id}/edit/'
+ try:
+ response = client.get(url)
+ except:
+ invalid_pages.append(id)
+
+ print(invalid_page_ids)
diff --git a/publichealth/home/migrations/0027_auto_20191017_1715.py b/publichealth/home/migrations/0027_auto_20191017_1715.py
new file mode 100644
index 0000000..dc6e4e2
--- /dev/null
+++ b/publichealth/home/migrations/0027_auto_20191017_1715.py
@@ -0,0 +1,25 @@
+# Generated by Django 2.1.12 on 2019-10-17 15:15
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('wagtailimages', '0001_squashed_0021'),
+ ('home', '0026_auto_20190625_1521'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='contact',
+ name='color',
+ field=models.CharField(blank=True, default='', max_length=40),
+ ),
+ migrations.AddField(
+ model_name='contact',
+ name='logo',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+ ),
+ ]
diff --git a/publichealth/home/migrations/0028_contact_style.py b/publichealth/home/migrations/0028_contact_style.py
new file mode 100644
index 0000000..58512c3
--- /dev/null
+++ b/publichealth/home/migrations/0028_contact_style.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.1.13 on 2019-10-21 18:09
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('home', '0027_auto_20191017_1715'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='contact',
+ name='style',
+ field=models.TextField(blank=True, default=''),
+ ),
+ ]
diff --git a/publichealth/home/models/snippets.py b/publichealth/home/models/snippets.py
index 1cb0037..a18f9ca 100644
--- a/publichealth/home/models/snippets.py
+++ b/publichealth/home/models/snippets.py
@@ -7,6 +7,7 @@ from django.db import models
from wagtail.snippets.models import register_snippet
from wagtail.core.models import Page
+from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.admin.edit_handlers import FieldPanel, PageChooserPanel
from .forms import ContactForm
@@ -63,11 +64,21 @@ class Contact(models.Model):
'title_fr',
'title_en',
)
+
address = models.TextField(default="", blank=True)
phone = models.CharField(max_length=40, blank=True, default="")
email = models.EmailField(max_length=100, blank=True, default="")
www = models.URLField(null=True, blank=True)
+ style = models.TextField(default="", blank=True)
+ color = models.CharField(max_length=40, blank=True, default="")
+ logo = models.ForeignKey(
+ 'wagtailimages.Image',
+ null=True, blank=True,
+ on_delete=models.SET_NULL,
+ related_name='+'
+ )
+
map_url = models.URLField(null=True, blank=True,
help_text="Optional link of address to mapping provider")
analytics = models.CharField(max_length=60, default="", blank=True,
@@ -95,6 +106,9 @@ class Contact(models.Model):
FieldPanel('phone'),
FieldPanel('email'),
FieldPanel('www'),
+ ImageChooserPanel('logo'),
+ FieldPanel('color'),
+ FieldPanel('style'),
FieldPanel('map_url'),
FieldPanel('analytics'),
PageChooserPanel('contact_form', 'home.ContactForm'),
diff --git a/publichealth/home/templates/puput/blog_page.html b/publichealth/home/templates/puput/blog_page.html
index a7cfd8a..2966d1a 100644
--- a/publichealth/home/templates/puput/blog_page.html
+++ b/publichealth/home/templates/puput/blog_page.html
@@ -24,9 +24,17 @@
+
+
+
{% endblock social_share %}
{% block blog_content %}
+{{ entry.title }}
- {% if entry.excerpt %}
- {{ entry.excerpt|richtext }}
- {% else %}
- {{ entry.body|richtext|truncatewords_html:70 }}
- {% endif %}
-
-
-
+{{ self.excerpt|safe }} +
+ {% if self.header_image %}{% if contact.map_url %} @@ -19,6 +21,25 @@ {% endfor %}