This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
from django.contrib.staticfiles.finders import find as find_static_file | |
from django.conf import settings | |
register = template.Library() | |
@register.simple_tag | |
def encode_static(path, encoding='base64', file_type='image'): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load i18n %} | |
<div class="row"> | |
<div class="col-xs-12"> | |
<section class="paginator text-center"> | |
<nav> | |
<ul class="pagination"> | |
<li> | |
{% if page.has_previous %} | |
<a href="?page={{ page.previous_page_number }}" aria-label="Previous"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Person(models.Model): | |
name = models.CharField(max_length=200) | |
groups = models.ManyToManyField('Group', through='GroupMember', related_name='people') | |
class Meta: | |
ordering = ['name'] | |
def __unicode__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
jQuery templates use constructs like: | |
{{if condition}} print something{{/if}} | |
This, of course, completely screws up Django templates, | |
because Django thinks {{ and }} mean something. | |
Wrap {% verbatim %} and {% endverbatim %} around those | |
blocks of jQuery templates and this will try its best |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find(key, dictionary): | |
for k, v in dictionary.iteritems(): | |
if k == key: | |
yield v | |
elif isinstance(v, dict): | |
for result in find(key, v): | |
yield result | |
elif isinstance(v, list): | |
for d in v: | |
for result in find(key, d): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = new EntityFieldQuery(); | |
$query->entityCondition('entity_type', 'node') | |
->entityCondition('bundle', 'article') | |
->propertyCondition('status', 1) | |
->fieldCondition('field_image', 'fid', 'NULL', '!=') | |
->range(0, 1); | |
$result = $query->execute(); | |
if (isset($result['node'])) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def render_to_response(self, context, **response_kwargs): | |
from django.conf import settings | |
STATIC_URL = settings.STATIC_URL | |
if 'http' not in STATIC_URL: | |
# wkhtmltopdf requires full uri to load css | |
from urlparse import urlparse | |
parsed = urlparse(self.request.META.get('HTTP_REFERER')) | |
parsed = '{uri.scheme}://{uri.netloc}'.format(uri=parsed) | |
context["STATIC_URL"] = "{}{}".format(parsed, settings.STATIC_URL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import android.content.Context; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.support.v4.app.FragmentManager; | |
import android.support.v4.app.FragmentPagerAdapter; | |
public class MyFragmentPageAdapter extends FragmentPagerAdapter { |
OlderNewer