Skip to content

Commit

Permalink
Clean up the layout of the legislation detail; add facebook and twitt…
Browse files Browse the repository at this point in the history
…er share widgets
  • Loading branch information
mjumbewu committed Sep 14, 2011
1 parent 70fe0fb commit 3995904
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 31 deletions.
10 changes: 10 additions & 0 deletions DIARY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,13 @@ So, finally, I was free to return to my 8-bit problem. Or so I thought! While
I wasn't looking, the problem fixed itself. I don't know which bit of tinkering
made it go away, but it's gone. And, while I'd prefer to know why, I won't
complain for now.


User Interaction
================

I'm going to focus on the user interaction/experience elements until launch; no
more legislation stuff for now. I spent some time today getting the
``sendfeedupdates`` command working. Still needs some love (and some tests).
Now I'm working on getting a tweet-this button. I might as well put that
facebook share button on as well.
25 changes: 23 additions & 2 deletions councilmatic/phillyleg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class LegFile(models.Model):
class Meta:
ordering = ['-key']


def __unicode__(self):
return "%s %s: %s%s" % (self.type, self.id, self.title[:100],
'...' if len(self.title) > 100 else '')
Expand All @@ -48,6 +47,28 @@ def __unicode__(self):
def get_absolute_url(self):
return ('legislation_detail', [str(self.pk)])

@property
def last_action_date(self):
"""
Gets the date of the latest action
"""
actions = self.actions.all()

if len(actions) == 0:
return None

return max([action.date_taken for action in actions])

@property
def timeline(self):
"""
Gets a timeline object that represents the legfile actions grouped by
``date_taken``.
"""
class Timeline (object):
pass

def unique_words(self):
"""
Expand Down Expand Up @@ -117,7 +138,7 @@ def save(self, *args, **kwargs):


class LegFileAttachment(models.Model):
file = models.ForeignKey(LegFile)
file = models.ForeignKey(LegFile, related_name='attachments')
description = models.CharField(max_length=1000)
url = models.URLField()
fulltext = models.TextField()
Expand Down
38 changes: 33 additions & 5 deletions councilmatic/phillyleg/static/phillyleg/legislation.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,44 @@
margin-bottom: 1em;
}

/* ====================================
* Lay out the main section
*/

.legfile_detail {
padding: 1em;
margin-left: 62px;
}

#main .block .content .legfile_detail h1 {
margin-bottom: 0em;
}

#main .block .content .legfile_detail h2 {
margin-left: 0px;
margin-top: 0em;
font-size: 1.2em;
font-weight: normal;
}

.legfile_overview_bar {
clear: both;
margin: 1em 0em;
margin-left: -62px;
border: 1px solid #ccc;
border-width: 1px 0px;
padding: 5px 0px;
}

.legfile_overview_bar > span {
margin-left: 20px;
}

.legfile_header .legfile_type_value:after {
content: ' ';
.legfile_overview_bar > span:first-child {
margin-left: 0px;
}

.legfile_header .legfile_id_value:after {
content: ': ';
.legfile_original_url {
text-align: right;
}

/* ====================================
Expand Down
52 changes: 37 additions & 15 deletions councilmatic/phillyleg/tests/models_tests.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,57 @@
from unittest import TestCase
from nose.tools import *

import os
import datetime as dt
import mock
from StringIO import StringIO

from phillyleg.models import *

class Tests_describing_LegFileTests (TestCase):

def setUp(self):
pass


def test_FindsUniqueWordsCorrectly(self):
class Test_LegFile_uniqueWords (TestCase):

@istest
def FindsUniqueWordsCorrectly(self):
legfile = LegFile()
legfile.title = "Word1 word2 hyphen-word1 word1. Word2 hyphen-word2... Word3..."

words = legfile.unique_words()
self.assertEqual(words, set(['word1', 'word2', 'word3', 'hyphen-word1', 'hyphen-word2']))


def test_FindsMentionedLegfilesCorrectly(self):
assert_equal(words, set(['word1', 'word2', 'word3', 'hyphen-word1', 'hyphen-word2']))


class Test__LegFile_mentionedLegfiles (TestCase):

@istest
def FindsMentionedLegfilesCorrectly(self):
l123456 = LegFile(id='123456', key=1)
l123456.save()

l123456a = LegFile(id='123456-A', key=2)
l123456a.save()

l123456aa = LegFile(id='123456-AA', key=3)
l123456aa.save()

legfile = LegFile(title='This legfile mentions files 123456, 123457, and 123456-AA.')

files = set(legfile.mentioned_legfiles())
self.assertEqual(files, set([l123456, l123456aa]))



class Test__LegFile_lastActionDate:

@istest
def is_none_when_legfile_has_no_actions (self):
legfile = LegFile()

assert_is_none(legfile.last_action_date)

@istest
def is_last_action_dateTaken (self):
legfile = LegFile(id='123456', key=1)
legfile.save()
legfile.actions.add(LegAction(date_taken=dt.datetime(2011, 8, 11)))
legfile.actions.add(LegAction(date_taken=dt.datetime(2011, 8, 19)))
legfile.actions.add(LegAction(date_taken=dt.datetime(2011, 8, 12)))

assert_equal(legfile.last_action_date, dt.datetime(2011, 8, 19))
14 changes: 14 additions & 0 deletions councilmatic/static/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@
letter-spacing: normal;
line-height: 1.45em;
}


/* ==== Share widgets ==== */

.share_bar {
float: right;
}

.share_twitter,
.share_facebook {
/* float: left;
clear: left;*/
display: inline-block;
}
4 changes: 0 additions & 4 deletions councilmatic/subscriptions/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@ def get_internal_type(self):

@classmethod
def get_prep_value(cls, value):
# if callable(value):
# value = value()
return pickle.dumps(value)

def to_python(self, value):
try:
print 'unpickled:', pickle.loads(str(value))
return pickle.loads(str(value))

# Assume that, if we get an error either in the string conversion or in
# the unpickling of that string, we mean that this is the exact value we
# want.
except:
print 'verbatim:', repr(value)
return value

#
Expand Down
64 changes: 59 additions & 5 deletions councilmatic/templates/phillyleg/legfile_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,58 @@
{% endif %}
{% endif %}

{% with phillyleg_legfile_exclude="date_scraped, last_scraped, legfileattachment_set, legaction_set, metadata, type, contact" %}
{% with phillyleg_legfile_fields="intro_date, final_date, status, controlling_body, sponsors, contact, title, url" %}
{% detail_block object %}
{% endwith %}
{% endwith %}
<div class="share_bar">
<div class="share share_twitter">
<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
<a href="http://twitter.com/share" class="twitter-share-button">Tweet</a>
</div>

<div class="share share_facebook">
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#appId=175088115901901&xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-like" data-send="true" data-layout="button_count" data-width="100" data-show-faces="true"></div>
</div>
</div>

<section class="instance instance_detail legfile_detail">
<header class="instance_header legfile_header">
<h1>{{ object.type }} {{ object.id }}</h1>
<h2>Controlled by <span class="legfile_controlling_body">{{ object.controlling_body }}</span></h2>
</header>

<div class="overview_bar legfile_overview_bar">
<span>Introduced on {{ object.intro_date }}</span>

{% if object.last_action_date %}
<span>Last action on {{ object.last_action_date }}</span>
{% endif %}

<span>Status: {{ object.status }}</span>
</div>

<div class="legfile_text">
<p>{{ object.title }}</p>
</div>

<div class="legfile_attachments">
{% for attachment in object.attachments.all %}
<a href="{{ attachment.url }}">{{ attachment.description }}</a>
{% empty %}
<p>(No attachments)</p>
{% endfor %}
</div>
</section>

<div class="legfile_original_url">
<a href="{{ legfile.url }}">Source</a>
</div>

{% comment %}
<!--
Expand Down Expand Up @@ -75,6 +122,13 @@
<div class="content">
<div class="inner">

<header class="list_header legfile_attachments_header">
<h1>Timeline</h1>
</header>

{% for action in object.actions.all %}
{% endfor %}

{% with title="Actions" %}
{% with phillyleg_legaction_fields="date_taken, description, motion, notes, minutes" %}
{% list_block object.actions.all %}
Expand Down

0 comments on commit 3995904

Please sign in to comment.