public-health-ch/publichealth/home/models/snippets.py

47 lines
1.4 KiB
Python
Raw Normal View History

2017-04-08 12:57:00 +00:00
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from wagtail.wagtailsnippets.models import register_snippet
from wagtail.wagtailcore.models import Page
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from ..util import TranslatedField
@register_snippet
class Contact(models.Model):
title = models.CharField(max_length=255, default="")
title_fr = models.CharField(max_length=255, default="")
trans_title = TranslatedField(
'title',
'title_fr',
)
address = models.TextField(default="", blank=True)
phone = models.CharField(max_length=40, default="")
2017-04-21 12:36:21 +00:00
email = models.EmailField(max_length=100, default="")
2017-04-08 12:57:00 +00:00
www = models.URLField(null=True, blank=True)
panels = Page.content_panels + [
FieldPanel('title_fr'),
FieldPanel('address'),
FieldPanel('phone'),
FieldPanel('email'),
FieldPanel('www'),
]
def phone_link(self):
return 'tel:%s' % self.phone.replace(' ', '')
def email_link(self):
return 'mailto:%s' % self.email
def www_domain(self):
return self.www.replace('http://', '').replace('https://', '')
2017-04-11 15:32:31 +00:00
def trans_title_styled(self):
2017-04-11 21:38:59 +00:00
v = self.trans_title.split(' ')
2017-04-11 15:32:31 +00:00
if len(v) != 3: return v
return "<strong>%s %s</strong> %s" % tuple(v)
2017-04-08 12:57:00 +00:00
def __str__(self):
return self.trans_title