Skip to content

Instantly share code, notes, and snippets.

@cacheleocode
cacheleocode / models.py
Last active August 29, 2015 14:17
series and article link
#serieses = Series.objects.filter(reduce(operator.and_, filter_list)).exclude(reduce(operator.or_, exclude_list)).annotate(latest_article_publish_date=Max('article__publish_date')).extra(select={'selected_language': "articles_series.title_%s <> ''" % (lang)}).order_by('-selected_language', order_by)[:limit]
#serieses = Series.objects.filter(reduce(operator.and_, filter_list)).exclude(reduce(operator.or_, exclude_list)).annotate(latest_article_publish_date=Max('article__publish_date')).extra(select={'article_selected_language': "articles_article.title_%s <> ''" % (lang)}).distinct().order_by('-article_selected_language', order_by)[:limit]
#serieses = Series.objects.filter(reduce(operator.and_, filter_list)).exclude(reduce(operator.or_, exclude_list))[:limit]
#serieses = Series.objects.filter(published__exact=True).extra(select={'selected_language': "articles_series.title_%s <> ''" % (lang)}).extra(select={'latest_article_publish_date': 'SELECT articles_article.publish_date FR
@cacheleocode
cacheleocode / article.html
Created January 29, 2015 21:40
Pinterest article code
{% if LANG == 'en' or LANG == 'ja' %} {# pinterest only translates to english and japanese #}
<script type="text/javascript" async defer data-pin-lang="{{ LANG }}" data-pin-color="red" data-pin-height="28" data-pin-hover="true" src="//assets.pinterest.com/js/pinit.js"></script>
{% else %} {# pinterest without the need to translate #}
<script type="text/javascript" async defer data-pin-shape="round" data-pin-height="32" data-pin-hover="true" src="//assets.pinterest.com/js/pinit.js"></script>
{% endif %}
<script type="text/javascript">
$(document).ready(function() {
// disable pinterest hover on all images
$("img").attr("data-pin-no-hover", true);
@cacheleocode
cacheleocode / models.py
Created January 27, 2015 19:16
determine if image is in top half of article
def selected_image(self, lang='en', user_langs=None):
"""
For display at the top of an article, show the largest selected image, as long as it's not near the top of the article body
"""
# attachments
if self.image_attachments():
# sort by size descending
attachments = sorted(self.image_attachments(), key=lambda x: x.file.size, reverse=True)
@cacheleocode
cacheleocode / cover_image.html
Created January 10, 2015 03:51
author's cover image
{% for article in author.articles|slice:":1" %}
{% if not article.series.is_legacy and not article.is_legacy %}
{% thumbnail article.signature_image2 490x100 upscale autocrop crop="0," as thumb %}
{% if thumb.source_height > thumb.source_width %}
<div class="cover" style="background-image: url('{% thumbnail article.signature_image2 490x100 upscale crop=",0" %}');"></div>
{% else %}
<div class="cover" style="background-image: url('{{ thumb }}');"></div>
{% endif %}
{% else %}
<div class="cover"></div>
@cacheleocode
cacheleocode / signature_image2.py
Created December 20, 2014 21:12
determine signature image
def signature_image2(self):
# image or attachment
if self.image:
if self.image.height == self.image.width or self.image.size <= 50000: # legacy pre-cropped, pre-sized square image, smaller than about 50KB
if self.image_attachments():
attachments = sorted(self.image_attachments(), key=lambda x: x.file.size, reverse=True)
for attachment in attachments:
if attachment.selected:
return attachment.file
@cacheleocode
cacheleocode / model.py
Created December 17, 2014 20:31
determine if article is legacy
def is_legacy(self):
is_legacy = False
temp = []
if not self.image_attachments():
if not self.image:
temp.append(False)
else:
temp.append(True)
else:
@cacheleocode
cacheleocode / voting_badge_logic.html
Last active August 29, 2015 14:11
voting badge logic
{% if article.series %}
{% if article.is_current_series %}
{% likes article %}
{% if user.is_authenticated %}
{% if likes_enabled %}
{% if can_vote %} {# logged in and can vote #}
<div class="rating_badge">
<img src="{{ MEDIA_URL }}nima_star_icon.png" alt="" />
@cacheleocode
cacheleocode / authors.html
Created December 2, 2014 22:38
Django template that shows one author as simple HTML or multiple authors as tiles
{% if authors %}
{% if authors|length == 1 %}
{% for author in authors %}
<div class="article-author">
<h5>{% blocktrans %}Author{% endblocktrans %}</h5>
<h4><a href="{{ author.get_absolute_url }}">{% ifequal LANG 'ja' %}{{ author.display_name_ja }}{% else %}{{ author.display_name_en }}{% endifequal %}</a></h4>
<a href="{{ author.get_absolute_url }}"><img src="{% thumbnail author.image 120x180 upscale autocrop crop=",0" %}" alt="" class="thumbnail" /></a>
@cacheleocode
cacheleocode / views.py
Created November 21, 2014 21:20
automated push
# automated push
today = datetime.date.today()
magic = datetime.date(2014, 11, 01)
if today < magic:
closed = False
else:
closed = True
var JI = JI || {};
JI.getJSON = function(options){
if(options['callback'] == null){
options['callback'] = function(data){
return true;
}
}
this.cb = 'jsonp_request_' + Math.floor(Math.random()*1000);
window[this.cb] = function(data){