diff --git a/publichealth/home/migrations/0017_auto_20170510_1627.py b/publichealth/home/migrations/0017_auto_20170510_1627.py new file mode 100644 index 0000000..2b6af9a --- /dev/null +++ b/publichealth/home/migrations/0017_auto_20170510_1627.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-05-10 14:27 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0016_socialcontact'), + ] + + operations = [ + migrations.AddField( + model_name='contact', + name='analytics', + field=models.CharField(blank=True, default='', help_text='Optional web analytics property code', max_length=60), + ), + migrations.AddField( + model_name='contact', + name='map_url', + field=models.URLField(blank=True, help_text='Optional link of address to mapping provider', null=True), + ), + migrations.AlterField( + model_name='socialcontact', + name='profile', + field=models.CharField(default='', help_text='Name of the account, e.g. @myaccount, or full URL', max_length=255), + ), + ] diff --git a/publichealth/home/models/snippets.py b/publichealth/home/models/snippets.py index f8b261b..319e5e9 100644 --- a/publichealth/home/models/snippets.py +++ b/publichealth/home/models/snippets.py @@ -59,6 +59,10 @@ class Contact(models.Model): phone = models.CharField(max_length=40, default="") email = models.EmailField(max_length=100, default="") www = models.URLField(null=True, blank=True) + 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, + help_text="Optional web analytics property code") panels = Page.content_panels + [ FieldPanel('title_fr'), @@ -66,6 +70,8 @@ class Contact(models.Model): FieldPanel('phone'), FieldPanel('email'), FieldPanel('www'), + FieldPanel('map_url'), + FieldPanel('analytics'), ] def phone_link(self): @@ -74,6 +80,13 @@ class Contact(models.Model): return 'mailto:%s' % self.email def www_domain(self): return self.www.replace('http://', '').replace('https://', '') + def is_google_analytics(self): + return self.analytics.startswith('UA-') + def get_piwik_analytics(self): + # When formatted as "server|site_id", assume Piwik + if not '|' in self.analytics: return False + sa = self.analytics.split('|') + return { 'server': sa[0], 'site': sa[1] } def trans_title_styled(self): v = self.trans_title.split(' ') if len(v) != 3: return v diff --git a/publichealth/home/templates/tags/contact_info.html b/publichealth/home/templates/tags/contact_info.html index 48af078..6bb9838 100644 --- a/publichealth/home/templates/tags/contact_info.html +++ b/publichealth/home/templates/tags/contact_info.html @@ -1,6 +1,10 @@
{{ contact.trans_title }}
- {{ contact.address }}
+ {% if contact.map_url %}
+ {{ contact.address }}
+ {% else %}
+ {{ contact.address }}
+ {% endif %}
Tel. {{ contact.phone }}
{{ contact.email }}
@@ -14,3 +18,30 @@
{{ sc.network_title }}
{% endfor %}
+
+{% if contact.is_google_analytics %}
+
+{% elif contact.get_piwik_analytics %}
+
+{% endif %}