Skip to content

Commit

Permalink
Large batch of updates to responsive redesign, mostly around transcri…
Browse files Browse the repository at this point in the history
…pt pages
  • Loading branch information
michaelmulley committed Mar 23, 2017
1 parent e1cbed7 commit af41014
Show file tree
Hide file tree
Showing 38 changed files with 422 additions and 250 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Expand Up @@ -9,14 +9,13 @@
.idea/
.DS_Store
models.dot
polpics/
autoimg/
local/
design/
settings.py
pip-log.txt
logs/
media/
collected_static/
mediafiles/
staticfiles/
fabfile
*.sublime-*
language_models/
Expand Down
2 changes: 2 additions & 0 deletions bower.json
Expand Up @@ -17,5 +17,7 @@
],
"dependencies": {
"foundation-sites": "^6.3.1",
"jquery-expander": "^1.7.0",
"underscore": "^1.8.3"
}
}
4 changes: 3 additions & 1 deletion parliament/core/models.py
Expand Up @@ -17,6 +17,7 @@
import requests

from parliament.core import parsetools
from parliament.core import thumbnail # importing so it'll register a tag
from parliament.core.utils import memoize_property, ActiveManager, language_property

import logging
Expand Down Expand Up @@ -398,7 +399,8 @@ def url(self):
@property
def parlpage(self):
try:
return "http://www.parl.gc.ca/MembersOfParliament/ProfileMP.aspx?Key=%s&Language=E" % self.info()['parl_id']
return "http://www.parl.gc.ca/Parliamentarians/{}/members/{}({})".format(
settings.LANGUAGE_CODE, self.identifier, self.info()['parl_id'])
except KeyError:
return None

Expand Down
29 changes: 22 additions & 7 deletions parliament/core/thumbnail.py
@@ -1,8 +1,23 @@
from imagekit import ImageSpec, register
from imagekit.processors import ResizeToFill

def crop_first(image, requested_size, opts):
if 'crop_first' in opts:
(t, r, b, l) = (int(x) for x in opts['crop_first'].split(','))
(w, h) = image.size
image = image.crop((l, t, w-r, h-b))
return image
crop_first.valid_options = ['crop_first']
class ExplicitCrop(object):

def __init__(self, top, right, bottom, left):
self.top = top
self.right = right
self.bottom = bottom
self.left = left

def process(self, img):
(w, h) = img.size
return img.crop((self.left, self.top, w - self.right, h - self.bottom))

class StatementPageHeadshot(ImageSpec):
processors = [ExplicitCrop(10, 10, 68, 10), # should give us 122x152
ResizeToFill(100, 125)]
format = 'JPEG'
options = {'quality': 80}


register.generator('op:statement_headshot', StatementPageHeadshot)
2 changes: 1 addition & 1 deletion parliament/default_settings.py
Expand Up @@ -133,6 +133,7 @@
'django_extensions',
'haystack',
'sorl.thumbnail',
'imagekit',
'compressor',
'parliament.core',
'parliament.accounts',
Expand All @@ -151,7 +152,6 @@
THUMBNAIL_PROCESSORS = (
'sorl.thumbnail.processors.colorspace',
'sorl.thumbnail.processors.autocrop',
'parliament.core.thumbnail.crop_first',
'sorl.thumbnail.processors.scale_and_crop',
'sorl.thumbnail.processors.filters',
)
Expand Down
16 changes: 13 additions & 3 deletions parliament/hansards/models.py
Expand Up @@ -307,7 +307,6 @@ class Statement(models.Model):
who_context_en = models.CharField(max_length=300, blank=True)
who_context_fr = models.CharField(max_length=500, blank=True)


content_en = models.TextField()
content_fr = models.TextField(blank=True)
sequence = models.IntegerField(db_index=True)
Expand Down Expand Up @@ -371,8 +370,6 @@ def get_absolute_url(self):
def __unicode__ (self):
return u"%s speaking about %s around %s" % (self.who, self.topic, self.time)

@property
@memoize_property
def content_floor(self):
if not self.content_fr:
return self.content_en
Expand All @@ -389,6 +386,19 @@ def content_floor(self):
r.append(e)
return u"\n".join(r)

def content_floor_if_necessary(self):
"""Returns text spoken in the original language(s), but only if that would
be different than the content in the default language."""
if not self.content_en and self.content_fr:
return ''

lang_matches = re.finditer(r'data-originallang="(\w\w)"',
getattr(self, 'content_' + settings.LANGUAGE_CODE))
if any(m.group(1) != settings.LANGUAGE_CODE for m in lang_matches):
return self.content_floor()

return ''

def text_html(self, language=settings.LANGUAGE_CODE):
return mark_safe(getattr(self, 'content_' + language))

Expand Down
4 changes: 2 additions & 2 deletions parliament/hansards/views.py
Expand Up @@ -75,7 +75,7 @@ def document_redirect(request, document_id, slug=None):
@vary_on_headers('X-Requested-With')
def document_view(request, document, meeting=None, slug=None):

per_page = 15
per_page = 25
if 'singlepage' in request.GET:
per_page = 50000

Expand Down Expand Up @@ -129,7 +129,7 @@ def document_view(request, document, meeting=None, slug=None):
})

if request.is_ajax():
t = loader.get_template("hansards/statement_page_responsive.inc")
t = loader.get_template("hansards/statement_page.inc")
else:
if document.document_type == Document.DEBATE:
t = loader.get_template("hansards/hansard_detail.html")
Expand Down
4 changes: 3 additions & 1 deletion parliament/imports/represent.py
Expand Up @@ -14,7 +14,7 @@
import logging
logger = logging.getLogger(__name__)

def update_mps_from_represent(download_headshots=False):
def update_mps_from_represent(download_headshots=False, update_all_headshots=False):

resp = requests.get('https://represent.opennorth.ca/representatives/house-of-commons/?limit=500')
resp.raise_for_status()
Expand Down Expand Up @@ -63,6 +63,8 @@ def _update(fieldname, value):
pol.download_headshot(mp_info['photo_url'])
else:
warnings.append("Photo available: %s for %s" % (mp_info.get('photo_url'), pol))
elif mp_info.get('photo_url') and update_all_headshots:
pol.download_headshot(mp_info['photo_url'])

if mp_info.get('extra') and mp_info['extra'].get('twitter'):
screen_name = mp_info['extra']['twitter'].split('/')[-1]
Expand Down
18 changes: 17 additions & 1 deletion parliament/static/jsnew/core.js
Expand Up @@ -8,7 +8,23 @@ OP.utils = {
else if (cc >= 48 && cc <= 57) cc = 48 + ((cc - 43) % 10);
return String.fromCharCode(cc);
});
}
},

getQueryParam: function(name, qs) {

if (!qs) {
qs = window.location.search;
}
else {
qs = '?' + qs.split('?')[1];
}

var match = RegExp('[?&]' + name + '=([^&]*)')
.exec(qs);

return match && decodeURIComponent(match[1].replace(/\+/g, ' '));

},

};

Expand Down
6 changes: 3 additions & 3 deletions parliament/static/jsnew/pagination.js
Expand Up @@ -10,12 +10,12 @@ $(function() {
$(this).html('Loading...');
}
$('#paginated').find('.pagination').addClass('loading');
navigateTo(this.href);
window.OP.AJAXNavigate(this.href);
}
});

$(window).on('popstate', function(e) {
navigateTo(document.location.href);
window.OP.AJAXNavigate(document.location.href);
});

var getURLParts = function(url) {
Expand All @@ -34,7 +34,7 @@ $(function() {
};
};

var navigateTo = function(url) {
window.OP.AJAXNavigate = function(url) {
last_navigated_url = url;
var $paginated = $('#paginated');
$paginated.find('.pagination').addClass('loading');
Expand Down
77 changes: 75 additions & 2 deletions parliament/static/jsnew/statementbrowser.js
Expand Up @@ -12,15 +12,88 @@

$(document).bind('contentLoad', function() {
if ($('.statement_browser').length && !$('.disable_more_links').length) {
$('.statement .main-col:not(.truncated)').each(function() {
$('.statement .text-col:not(.truncated)').each(function() {
if (this.clientHeight < this.scrollHeight) {
$(this).addClass('truncated');
var $morelink = $(document.createElement('div')).html('&darr;').addClass('morelink').click(revealStatement);
// var $fadeout = $(document.createElement('div')).addClass('fadeout');
$(this).prepend($morelink);
}
});
}

$('.statement_browser.statement').each(function() { displayLanguageStatus(this); });
});

var LANG_STATUSES = {
PARTIALLY_TRANSLATED: 'Partially translated',
FLOOR: 'As spoken',
TRANSLATED: 'Translated'
};

var _determineLanguageStatus = function(statement) {
var paragraphs = $(statement).find('p[data-originallang]').get();
var langs = _.uniq(_.map(paragraphs, function(p) { return p.getAttribute('data-originallang'); }));
if (langs.length == 0)
return 'NONE';
if (langs.length == 2)
return 'PARTIALLY_TRANSLATED';
if (langs.length == 1) {
if (langs[0] === OP.LANG)
return 'FLOOR';
return 'TRANSLATED'
}
};

var getLanguageStatus = function(statement) {
var lang_status = statement.getAttribute('data-languagestatus');
if (!lang_status) {
lang_status = _determineLanguageStatus(statement);
statement.setAttribute('data-languagestatus', lang_status);
if (statement.getAttribute('data-floor'))
$(statement).addClass('lang-switchable');
}
return lang_status;
};

var displayLanguageStatus = function(statement) {
var lang_status = getLanguageStatus(statement);
if (lang_status && lang_status !== 'NONE') {
$(statement).find('.lang-control').text(LANG_STATUSES[lang_status]);
}
}

var switchLanguage = function(statement) {
if (statement.getAttribute('data-languagestatus') === 'FLOOR') {
if (!$(statement).data('original_lang_status'))
throw(new Error("original data attributes not available in switchLanguage"));
switchLanguageContent(statement, $(statement).data('original_paragraphs'),
$(statement).data('original_lang_status'));
}
else {
switchLanguageToFloor(statement);
}
};

var switchLanguageToFloor = function(statement) {
var paragraphs = $(statement).find('.text p').get();
$(statement).data('original_paragraphs', paragraphs);
$(statement).data('original_lang_status', statement.getAttribute('data-languagestatus'));
var paragraphs_floor = $(statement.getAttribute('data-floor')).get();
switchLanguageContent(statement, paragraphs_floor, 'FLOOR');
}

var switchLanguageContent = function(statement, new_content, new_status) {
var $text = $(statement).find('div.text');
$text.children().remove();
$text.append(new_content);
statement.setAttribute('data-languagestatus', new_status);
displayLanguageStatus(statement);
}

$('body').on('click', '.lang-switchable .lang-control', function(e) {
e.preventDefault();
var statement = $(e.target).closest('.statement').get()[0];
switchLanguage(statement);
});

})();
6 changes: 3 additions & 3 deletions parliament/static/scss/_foundation-settings.scss
Expand Up @@ -46,7 +46,7 @@
// 1. Global
// ---------

$global-font-size: 100%;
$global-font-size: 95%;
$global-width: rem-calc(1100);
$global-lineheight: 1.5;
$foundation-palette: (
Expand Down Expand Up @@ -132,7 +132,7 @@ $header-styles: (
$header-text-rendering: optimizeLegibility;
$small-font-size: 80%;
$header-small-font-color: $medium-gray;
$paragraph-lineheight: 1.6;
$paragraph-lineheight: $global-lineheight;
$paragraph-margin-bottom: 1rem;
$paragraph-text-rendering: optimizeLegibility;
$code-color: $black;
Expand All @@ -157,7 +157,7 @@ $list-nested-side-margin: 1.25rem;
$defnlist-margin-bottom: 1rem;
$defnlist-term-weight: $global-weight-bold;
$defnlist-term-margin-bottom: 0.3rem;
$blockquote-color: $dark-gray;
$blockquote-color: #666666;
$blockquote-padding: rem-calc(9 20 0 19);
$blockquote-border: 1px solid $medium-gray;
$cite-font-size: rem-calc(13);
Expand Down

0 comments on commit af41014

Please sign in to comment.