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 Banana(models.Model): | |
name = models.CharField(max_length=255) | |
father = models.ForeignKey('self', null=True) | |
def __unicode__(self): | |
return self.name |
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
define([ 'jquery' ], function($) { | |
var Tooltip = function(element, options) { | |
this.$element = $(element); | |
var tooltip = this, | |
title = this.$element.attr('title'); | |
this.options = $.extend({}, $.fn.tooltip.defaults, options); | |
this.text = this.$element.removeAttr('title') && title || this.options.text; |
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 | |
register = template.Library() | |
@register.filter | |
def truncatewords_by_chars(value, arg): | |
""" | |
Truncate words based on the number of characters | |
based on original truncatewords filter code | |
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
@yellow: yellow; | |
@green: green; | |
.pie { | |
behavior: url(PIE.htc); | |
} | |
@import "css/mixins"; | |
@import "css/base"; | |
@import "css/tables"; |
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
define([ 'jquery' ], function($) { | |
$.fn.notification = function(msg_type, msg, options) { | |
var container = this; | |
var defaults = { | |
autoHide: true, | |
hideSpeed: 3000, | |
fadeInSpeed: 'fast', | |
hideOthers: true | |
}; |
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 alternate_ssr_template(ssr_template, default_args_pos): | |
""" | |
Decorator which changes the template and context for non-ajax | |
server-side requests. | |
This decorator MUST be first because it uses func_defaults. | |
`ssr_template`: Replacement template. | |
`default_args_pos`: The position of the 'template' argument that will | |
be replaced in the list of default arguments | |
for the function. |
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
(r'^articles/(?P<year>\d{4}/?$, 'main.views.year'), | |
# When a use case comes up that a month needs to be involved as | |
# well, you add an argument in your regex: | |
(r'^articles/(?P<year>\d{4}/(?P<month>\d{2})/?$, 'main.views.year_month'), | |
# That works fine, unless of course you want to show something | |
# different for just the year, in which case the following case can be | |
# used, making separate views based on the arguments as djangoproject |
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 get_first_or_none(qs): | |
""" | |
Gets first item of queryset or None, | |
queryset can be QuerySet, RelatedManager, | |
Model, or object/Model instance. | |
Examples: | |
class Pizza(models.Model): | |
name = models.CharField(max_length=50) | |
toppings = models.ForeignKey('test.Topping') |
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
#tag('ul',''.join([tag('li',i) for i in xrange(1,6)]),{'class':'required'}) | |
#>>>'<ul class="required"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul>' | |
def tag(tag_name='div', content='', attrs_dict={}): | |
""" | |
Makes an html tag. | |
""" | |
template = '<%s>' % ('%s>%s</%s' % ('%s' % (tag_name + '%s'),'%s','%s' % tag_name)) | |
return template % (' '.join([' %s="%s"' %(k,v) for k,v in attrs_dict.iteritems()]), content) |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" type="text/css" href="style.css" /> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script> | |
<script type="text/javascript" src="script.js"></script> | |
<script type="text/javascript" src="jquery-ui-1.8.12.custom.min.js"></script> | |
</head> | |
<body> | |
<header> |