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.core.exceptions import ValidationError
from django.utils.functional import cached_property
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.conf import settings
from modelcluster.fields import ParentalKey
from wagtail.wagtailcore.models import Orderable
from wagtail.wagtailcore.fields import StreamField
from wagtail.wagtailadmin.edit_handlers import (
FieldPanel,
FieldRowPanel,
InlinePanel,
MultiFieldPanel,
StreamFieldPanel
......@@ -25,7 +28,7 @@ class SocialMediaProfile(models.Model):
)
site_titles = (
('twitter', "Twitter"),
('linkedin', "LinkedIn")
('linkedin', "LinkedIn"),
)
site_urls = (
('twitter', 'https://twitter.com/'),
......@@ -68,14 +71,44 @@ class PersonPagePersonType(models.Model):
return self.person_type.title
class PersonPagePhoneNumber(models.Model):
page = ParentalKey('PersonPage', related_name='phone_numbers')
phone_number = models.CharField(max_length=255)
class PersonContactInfomation(Orderable):
methods = (
('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 = [
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):
subpage_types = []
......@@ -107,7 +140,7 @@ class PersonPage(BasePage):
FieldPanel('website'),
MultiFieldPanel([
FieldPanel('email'),
InlinePanel('phone_numbers', label='Phone numbers'),
InlinePanel('contact_details', label='Other Contact Methods'),
], heading='Contact information'),
InlinePanel('person_types', label='Person types'),
FieldPanel('introduction'),
......
......@@ -23,11 +23,11 @@
<p>{{ page.email }}</p>
{% endif %}
{% with phone_numbers=page.phone_numbers.all %}
{% if phone_numbers %}
{% with contact_details=page.contact_details.all %}
{% if contact_details %}
{% for related_phone_number in phone_numbers %}
<p>{{ related_phone_number.phone_number }}</p>
{% for contact in contact_details %}
<p>{{ contact.method_display }}: {{ contact.contact_detail }}</p>
{% endfor %}
{% 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