djangosnippets.org: Latest snippets posted by bryanhelmighttp://djangosnippets.org/users/bryanhelmig/2012-02-07T14:33:36.037150-06:00bryanhelmigSASS/SCSS include template tag.
2012-02-07T14:33:36.037150-06:00bryanhelmighttp://djangosnippets.org/snippets/2678/<p>You'll need to <code>pip install pyScss</code> first.</p>
<p>Converts on the fly, so you won't want to use this for much more than just testing.</p>
<p>Usage in a template:</p>
<pre><code>{% load sass %}
{% include_sass "disclosures/css/base.scss" %}
{% include_sass "disclosures/css/grid.scss" %}
</code></pre>
Freely redistributableLoad File From URL Widget
2011-08-21T18:37:33.866375-05:00bryanhelmighttp://djangosnippets.org/snippets/2520/<p>Rather simple usage, modelforms/in the admin:</p>
<pre><code>class CustomAdminForm(forms.ModelForm):
class Meta:
model = Something
widgets = {
'image': URLFileInput(default_exts=[".png", ".gif", ".jpg"]),
}
class SomethingAdmin(admin.ModelAdmin):
form = CustomAdminForm
admin.site.register(Something, SomethingAdmin)
</code></pre>
<p>Basically, this will pull the image from the URL instead of only pulling it from your harddrive for upload.</p>
<p>Also accepts optional …</p>
Freely redistributableMethod Caching
2011-07-01T14:50:31.483559-05:00bryanhelmighttp://djangosnippets.org/snippets/2477/<p>A very simple decorator that caches both on-class and in memcached:</p>
<pre><code>@method_cache(3600)
def some_intensive_method(self):
return # do intensive stuff`
</code></pre>
<p>Alternatively, if you just want to keep it per request and forgo memcaching, just do:</p>
<pre><code>@method_cache()
def some_intensive_method(self):
return # do intensive stuff`
</code></pre>
Freely redistributablePer-Instance On-Model M2M Caching
2010-07-22T02:35:03.313984-05:00bryanhelmighttp://djangosnippets.org/snippets/2119/<p>If you are like me and you find yourself often using M2M fields for tons of other on-model methods, in templates, and views alike, try using this quick and dirty caching. I show the use of a "through" model for the m2m, but that is purely optional. For example, let's …</p>
Freely redistributableDetect iPhone & Switch Template via render_to_response
2010-05-23T22:11:46.093055-05:00bryanhelmighttp://djangosnippets.org/snippets/2035/<p>A fast way to implement an iPhone template switcher, especially if you have a lot of existing views using the render_to_response() shortcut. This checks for the iPhone browser and then modifies the chosen template by adding -mobile to the html's file name.</p>
<p>Check out <a href="http://minidetector.googlecode.com/svn/trunk/minidetector/tests/mobile_useragents.txt">this more complete list of user …</a></p>
Freely redistributableSimple file size from bytes to kb/mb/gb
2010-01-14T14:37:22.935586-06:00bryanhelmighttp://djangosnippets.org/snippets/1866/<p>This template tag is dead simple, if you have a file that is 45.3 kb, don't display it as 46,387 bits, display it as 45.3 kb!</p>
Freely redistributable