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
class ModelAdmin(admin.ModelAdmin) | |
""" | |
Refrain from prolonged exposure. | |
""" | |
def render_change_form(self, request, context, *args, **kwargs): | |
def get_queryset(original_func): | |
import inspect, itertools | |
def wrapped_func(): | |
if inspect.stack()[1][3] == '__iter__': | |
return itertools.repeat(None) |
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
""" | |
Find Exact M2M - Match | |
========= | |
Find an exact m2m match for a model. | |
Just did for fun in response to a stackoverflow question for a data importing issue.... | |
By Yuji Tomita | |
2/24/2011 |
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
/* | |
Cross Fade Any Element | |
Version 0.01 | |
By Yuji Tomita | |
February 10, 2012. | |
*/ | |
(function( $ ){ | |
$.fn.crossFadeTo = function( fadeToElement, speed, options) { |
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
/* | |
Stick element to top | |
Version 0.01 | |
Usage: | |
$("#product_preview_container").stickyElement({ // apply to element to stick. | |
stopPoint: $("#products_see_more"), // integer or jquery element to stop fading at | |
stopPointOffset: 100, // offset the stop point |
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
""" | |
Sorl Thumbnail Engine that accepts background color | |
--------------------------------------------------- | |
Created on Sunday, February 2012 by Yuji Tomita | |
""" | |
from PIL import Image, ImageColor | |
from sorl.thumbnail.engines.pil_engine import Engine | |
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
""" | |
Sorl Thumbnail Engine that accepts background color | |
--------------------------------------------------- | |
Created on Sunday, February 2012 by Yuji Tomita | |
""" | |
from PIL import Image, ImageColor | |
from sorl.thumbnail.engines.pil_engine import Engine | |
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
""" | |
Resolve lookup based on variable value | |
-------------------------------------- | |
{% resolve foovar foodict %} # does django's Variable(foovar).resolve(foodict) | |
Created on Monday, February 2012 by Yuji Tomita | |
""" | |
from django import template | |
from django.template.base import Variable, VariableDoesNotExist |
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
""" | |
Capture contents of block into context | |
-------------------------------------- | |
Use case: variable accessing based on current variable values. | |
{% capture foo %}{{ foo.value }}-suffix{% endcapture %} | |
{% if foo in bar %}{% endif %} | |
Created on Monday, February 2012 by Yuji Tomita |
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.core.urlresolvers import reverse, reverse_lazy, NoReverseMatch | |
# from django.utils.functional import lazy | |
# CONTEXT_INJECTOR_REVERSE_DEBUG = getattr(settings, 'CONTEXT_INJECTOR_REVERSE_DEBUG', False) | |
class TemplateContextInjectorMiddleware(object): | |
lazy_url_func_pairs = [] |
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 generate_default_sql(app, created_models, verbosity, **kwargs): | |
""" | |
Generate default SQL | |
""" | |
db_fields = filter(lambda x: hasattr(x, 'db_default'), OrderShipLog._meta.fields) | |
modelname = OrderShipLog._meta.object_name | |
sql_dir = os.path.join(os.path.dirname(__file__), '../sql/') | |
sql_filename = os.path.join(sql_dir, '{modelname}.postgresql_psycopg2.sql'.format( | |
modelname=modelname.lower())) |
OlderNewer