djangosnippets.org: Latest snippets posted by menendezhttps://djangosnippets.org/users/menendez/2010-03-21T18:40:20-05:00menendezBetter Static Image Serving With Fallback2010-03-21T18:40:20-05:00menendezhttps://djangosnippets.org/snippets/1967/<p>Serves images from a local directory, but if it doesn't find it locally, then go look for it on a server. This is useful for sites with very large amounts of static content.
</p>
<p>Instead of copying all your prod images to dev every time you update the database, simply ...</p>
Freely redistributableDynamically maintain local_constants.py from South migration2010-03-14T18:38:22-05:00menendezhttps://djangosnippets.org/snippets/1957/<p>Allows you to dynamically maintain a local_constants.py file from a migration tool like South. Example of usage:</p>
<p>set_constant('/home/projects/sample/local_constants.py', 'STAMP_MW_ID', 42, 'Set from sample.0007_add_constants.py')</p>
<p>More more information, see [Allows you to dynamically maintain a local_constants.py file from a migration tool like South ...</p>
Freely redistributableProfanity Check2009-07-16T08:47:22-05:00menendezhttps://djangosnippets.org/snippets/1634/<p>Simple Python snippet to detect if any word in a list of words is inside your string. Use for profanity checking (my use case), auto tag detection, scoring, etc.</p>
<p>This will return an empty list if the word is not in the list. Assumes everything in words_to_find is lower case ...</p>
Freely redistributablemini_render_to_response2009-04-19T14:02:38-05:00menendezhttps://djangosnippets.org/snippets/1451/<p>You need the mini-detector middleware installed <a href="http://www.iterasi.net/openviewer.aspx?sqrlitid=-e2dfig9w0yrclxaigp-uw">http://www.iterasi.net/openviewer.aspx?sqrlitid=-e2dfig9w0yrclxaigp-uw</a>.</p>
<p>This is a drop in replacement to render_to_response. When using mini_render_to_response it will try to load a version of your template with &amp;#157;mini at the end. For example "home_mini.html" instead of "home.html". If ...</p>
Freely redistributableLoad a local settings file for dev/test environments2008-07-27T18:52:44-05:00menendezhttps://djangosnippets.org/snippets/922/<p>Add the snippet to your settings.py. If you have a settings_local.py it will load that one. Can be used in development environments where you might have different settings for your dev sandbox. You should exclude settings_local.py from SVN.
</p>
<p>By Rudy and Ed Menendez
</p>
Freely redistributableCreate breakpoints to time code at2008-06-04T10:54:04-05:00menendezhttps://djangosnippets.org/snippets/783/<p>Include in your code like this:</p>
<p>t=Timer()</p>
<p>Then use it like this:</p>
<p>t.tick('Some optional description')</p>
<p>It will output the time spent between the tick and the previous tick (or inception) and the total time spent since it began tracking time. Can be placed multiple times in a ...</p>
Freely redistributableget_cache_or_query - Shortcut to common cache signature2008-05-05T15:06:04-05:00menendezhttps://djangosnippets.org/snippets/738/<p>Replaces something like this:
cache_key = 'game1'
the_game = cache.get(cache_key)
if not the_game:
the_game = Game.objects.get(id=1)
cache.set(cache_key, the_game, 60<em>24</em>5)
</p>
<p>With this:
the_game = get_cache_or_query('game1', Game, seconds_to_cache=60<em>24</em>5, id=1)
</p>
Freely redistributableChoices datatype for model2008-03-26T19:19:05-05:00menendezhttps://djangosnippets.org/snippets/667/<p>This class will automatically create a django choices tuple like this:</p>
<p>STATUS_CHOICES = django_choices(Draft=1, Public=2, Closed=3)</p>
<p>Additionally, it includes a method that converts the choices tuple to a dictionary. Like this:</p>
<p>STATUS = STATUS_CHOICES.to_dict()</p>
<p>Those types can come in handy when you need to use those magic ...</p>
Freely redistributable