Skip to content
Snippets Groups Projects
Commit d6d30839 authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Update the contact information to be more flexible

parent 07b05d2d
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-01-05 17:34
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields
class Migration(migrations.Migration):
dependencies = [
('people', '0002_add_header_image'),
]
operations = [
migrations.CreateModel(
name='PersonContactInfomation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
('contact_method', models.CharField(blank=True, choices=[('irc', 'IRC'), ('im_jabber_xmpp', 'IM/Jabber/XMPP'), ('phone', 'Phone'), ('pgp', 'PGP fingerprint'), ('otr', 'OTR fingerprint')], max_length=255)),
('other_method', models.CharField(blank=True, max_length=255, verbose_name='Other')),
('contact_detail', models.CharField(max_length=255)),
('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='contact_details', to='people.PersonPage')),
],
options={
'ordering': ['sort_order'],
'abstract': False,
},
),
migrations.RemoveField(
model_name='personpagephonenumber',
name='page',
),
migrations.DeleteModel(
name='PersonPagePhoneNumber',
),
]
from django.db import models from django.db import models
from django.core.exceptions import ValidationError
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.conf import settings from django.conf import settings
from modelcluster.fields import ParentalKey from modelcluster.fields import ParentalKey
from wagtail.wagtailcore.models import Orderable
from wagtail.wagtailcore.fields import StreamField from wagtail.wagtailcore.fields import StreamField
from wagtail.wagtailadmin.edit_handlers import ( from wagtail.wagtailadmin.edit_handlers import (
FieldPanel, FieldPanel,
FieldRowPanel,
InlinePanel, InlinePanel,
MultiFieldPanel, MultiFieldPanel,
StreamFieldPanel StreamFieldPanel
...@@ -25,7 +28,7 @@ class SocialMediaProfile(models.Model): ...@@ -25,7 +28,7 @@ class SocialMediaProfile(models.Model):
) )
site_titles = ( site_titles = (
('twitter', "Twitter"), ('twitter', "Twitter"),
('linkedin', "LinkedIn") ('linkedin', "LinkedIn"),
) )
site_urls = ( site_urls = (
('twitter', 'https://twitter.com/'), ('twitter', 'https://twitter.com/'),
...@@ -68,14 +71,44 @@ class PersonPagePersonType(models.Model): ...@@ -68,14 +71,44 @@ class PersonPagePersonType(models.Model):
return self.person_type.title return self.person_type.title
class PersonPagePhoneNumber(models.Model): class PersonContactInfomation(Orderable):
page = ParentalKey('PersonPage', related_name='phone_numbers') methods = (
phone_number = models.CharField(max_length=255) ('irc', 'IRC'),
('im_jabber_xmpp', 'IM/Jabber/XMPP'),
('phone', 'Phone'),
('pgp', 'PGP fingerprint'),
('otr', 'OTR fingerprint'),
)
page = ParentalKey('PersonPage', related_name='contact_details')
contact_method = models.CharField(max_length=255, choices=methods, blank=True)
other_method = models.CharField(max_length=255, blank=True, verbose_name='Other')
contact_detail = models.CharField(max_length=255)
panels = [ panels = [
FieldPanel('phone_number') FieldRowPanel([
FieldPanel('contact_method'),
FieldPanel('other_method'),
]),
FieldPanel('contact_detail'),
] ]
@property
def method_display(self):
return self.other_method or self.get_contact_method_display()
def clean(self):
if not (self.contact_method or self.other_method):
raise ValidationError({
'contact_method': 'Please select or type at least one contact method.',
'other_method': '',
})
if self.contact_method and self.other_method:
raise ValidationError({
'contact_method': 'Please only select or type one contact method.',
'other_method': '',
})
class PersonPage(BasePage): class PersonPage(BasePage):
subpage_types = [] subpage_types = []
...@@ -107,7 +140,7 @@ class PersonPage(BasePage): ...@@ -107,7 +140,7 @@ class PersonPage(BasePage):
FieldPanel('website'), FieldPanel('website'),
MultiFieldPanel([ MultiFieldPanel([
FieldPanel('email'), FieldPanel('email'),
InlinePanel('phone_numbers', label='Phone numbers'), InlinePanel('contact_details', label='Other Contact Methods'),
], heading='Contact information'), ], heading='Contact information'),
InlinePanel('person_types', label='Person types'), InlinePanel('person_types', label='Person types'),
FieldPanel('introduction'), FieldPanel('introduction'),
......
...@@ -23,11 +23,11 @@ ...@@ -23,11 +23,11 @@
<p>{{ page.email }}</p> <p>{{ page.email }}</p>
{% endif %} {% endif %}
{% with phone_numbers=page.phone_numbers.all %} {% with contact_details=page.contact_details.all %}
{% if phone_numbers %} {% if contact_details %}
{% for related_phone_number in phone_numbers %} {% for contact in contact_details %}
<p>{{ related_phone_number.phone_number }}</p> <p>{{ contact.method_display }}: {{ contact.contact_detail }}</p>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment