Skip to content

Commit

Permalink
Show representative website and social media links
Browse files Browse the repository at this point in the history
On the page to call U.S. representatives, show links to their
website and social media accounts.  This may be useful for looking
up alternative contact information if you can't contact the rep
via the given phone number.

Closes #4
#4
  • Loading branch information
ghing committed Feb 16, 2017
1 parent b408740 commit 2fec00e
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 4 deletions.
16 changes: 15 additions & 1 deletion meetings/models.py
Expand Up @@ -92,19 +92,33 @@ class SocialMediaChannel(models.Model):
"""Social media channel for an official"""

CHANNEL_TYPE_CHOICES = (
('GooglePlus', 'Google +'),
('GooglePlus', 'Google+'),
('YouTube', 'YouTube'),
('Facebook', 'Facebook'),
('Twitter', 'Twitter'),
)

CHANNEL_TYPE_LOOKUP = {k: v for k, v in CHANNEL_TYPE_CHOICES}

channel_id = models.CharField(max_length=254)
channel_type = models.CharField(max_length=20, choices=CHANNEL_TYPE_CHOICES)
official = models.ForeignKey('Official', related_name='channels')

def __str__(self):
return self.channel_id

def get_url(self):
url_templates = {
'Facebook': "https://www.facebook.com/{channel_id}",
'Twitter': "https://twitter.com/{channel_id}",
'YouTube': "https://www.youtube.com/user/{channel_id}",
'GooglePlus': "https://plus.google.com/u/0/+{channel_id}",
}
return url_templates[self.channel_type].format(**vars(self))

def get_service_name(self):
return self.CHANNEL_TYPE_LOOKUP[self.channel_type]


class Email(models.Model):
"""Email address for an official"""
Expand Down
8 changes: 8 additions & 0 deletions meetings/templates/meetings/call_us_rep.html
Expand Up @@ -25,6 +25,14 @@ <h2>Contact information</h2>
<dt>Email</dt>
<dd><a href="mailto:{{ email.address }}">{{ email.address }}</a></dd>
{% endfor %}
{% for url in representative.urls.all %}
<dt>Website</dt>
<dd><a href="{{ url.url }}">{{ url.url }}</a></dd>
{% endfor %}
{% for channel in representative.channels.all %}
<dt>{{ channel.get_service_name }}</dt>
<dd><a href="{{ channel.get_url }}">{{ channel.channel_id }}</a></dd>
{% endfor %}
</dl>

<form action="" method="post">{% csrf_token %}
Expand Down
89 changes: 88 additions & 1 deletion meetings/tests.py
@@ -1,3 +1,90 @@
from django.test import TestCase

# Create your tests here.
from meetings.models import Division, Office, Official, SocialMediaChannel

class SocialMediaChannelTestCase(TestCase):
def setUp(self):
division = Division.objects.create(
ocd_id="ocd-division/country:us/state:ky/cd:5",
name="Kentucky's 5th congressional district",
)
office = Office.objects.create(
name="United States House of Representatives KY-05",
division=division,
)
self.official = Official.objects.create(
name="Harold Rogers",
office=office)

def test_get_url_facebook(self):
channel = SocialMediaChannel(
official=self.official,
channel_type="Facebook",
channel_id="CongressmanHalRogers",
)
self.assertEqual(channel.get_url(),
"https://www.facebook.com/CongressmanHalRogers")

def test_get_url_twitter(self):
channel = SocialMediaChannel(
official=self.official,
channel_type="Twitter",
channel_id="RepHalRogers",
)
self.assertEqual(channel.get_url(),
"https://twitter.com/RepHalRogers")

def test_get_url_youtube(self):
channel = SocialMediaChannel(
official=self.official,
channel_type="YouTube",
channel_id="RepHalRogers",
)
self.assertEqual(channel.get_url(),
"https://www.youtube.com/user/RepHalRogers")


def test_get_url_google_plus(self):
channel = SocialMediaChannel(
official=self.official,
channel_type="GooglePlus",
channel_id="RepHalRogers",
)
self.assertEqual(channel.get_url(),
"https://plus.google.com/u/0/+RepHalRogers")

def test_get_service_name_facebook(self):
channel = SocialMediaChannel(
official=self.official,
channel_type="Facebook",
channel_id="CongressmanHalRogers",
)
self.assertEqual(channel.get_service_name(),
"Facebook")

def test_get_service_name_twitter(self):
channel = SocialMediaChannel(
official=self.official,
channel_type="Twitter",
channel_id="RepHalRogers",
)
self.assertEqual(channel.get_service_name(),
"Twitter")

def test_get_service_name_youtube(self):
channel = SocialMediaChannel(
official=self.official,
channel_type="YouTube",
channel_id="RepHalRogers",
)
self.assertEqual(channel.get_service_name(),
"YouTube")

def test_get_service_name_google_plus(self):
channel = SocialMediaChannel(
official=self.official,
channel_type="GooglePlus",
channel_id="RepHalRogers",
)
self.assertEqual(channel.get_service_name(),
"Google+")
12 changes: 10 additions & 2 deletions publicmeetings/templates/meetings/call_us_rep.html
Expand Up @@ -29,14 +29,22 @@ <h2>Contact information</h2>
<dt>Email</dt>
<dd><a href="mailto:{{ email.address }}">{{ email.address }}</a></dd>
{% endfor %}
{% for url in representative.urls.all %}
<dt>Website</dt>
<dd><a href="{{ url.url }}">{{ url.url }}</a></dd>
{% endfor %}
{% for channel in representative.channels.all %}
<dt>{{ channel.get_service_name }}</dt>
<dd><a href="{{ channel.get_url }}">{{ channel.channel_id }}</a></dd>
{% endfor %}
</dl>

<form action="" method="post">{% csrf_token %}
<h2>Were you able to contact the representative?</h2>
<div class="form-check-label">
<label class="form-check-label">
{{ forms.contact_attempt.contacted }}
I was able to contact this representative
I was able to contact this representative
</label>
</div>

Expand Down Expand Up @@ -67,7 +75,7 @@ <h2>What's the best way for constituents to learn about upcoming public meetings
</form>

{% if contact_attempts %}
<h2>Previous contact attempts</h2>
<h2>Previous contact attempts</h2>
<table class="table">
<thead>
<tr>
Expand Down

0 comments on commit 2fec00e

Please sign in to comment.