djangosnippets.org: Latest snippets posted by achimnolhttps://djangosnippets.org/users/achimnol/2009-09-01T00:41:47.750462-05:00achimnolA view for downloading attachment
2009-09-01T00:41:47.750462-05:00achimnolhttps://djangosnippets.org/snippets/1710/<p>This view snippet is a helper for implementing file download handlers. There is a standard to encode Unicode filenames properly, but many browsers have different protocols.</p>
<p>The default encoding is assumed to be UTF-8.</p>
Freely redistributablePersistent Params Decorator
2009-08-06T04:27:03.513534-05:00achimnolhttps://djangosnippets.org/snippets/1670/<p>This snippet helps preserving query parameters such as page number when the view perform redirects.</p>
<p>It does not support hooking templates and contexts currently.</p>
Freely redistributableCookieless Session Decorator
2009-08-05T02:14:19.428005-05:00achimnolhttps://djangosnippets.org/snippets/1667/<p>Although many people have already posted cookieless session middlewares and related stuffs, but this one is just for only required views.</p>
<p>You can use this as a view decorator like:</p>
<pre><code>@session_from_http_params
@login_required
def your_view(request):
...
</code></pre>
<p>This is very useful for those who use SWFUpload. Flash has a bug with sending …</p>
Freely redistributableMore readable Enumeration class for Django choices
2009-07-22T21:19:06.612368-05:00achimnolhttps://djangosnippets.org/snippets/1647/<p>We currently use two-level tuples to specify choices of a field in models or forms.</p>
<p>But, because it has only (value, verbose name) pair, the readability is bad whenever we indicate a specific choice value in our Python codes.</p>
<p>So I made a small class that does "magic" for this: …</p>
Freely redistributableAuto-resolving a specific object from key string in url with decorator
2009-07-06T01:39:00.500048-05:00achimnolhttps://djangosnippets.org/snippets/1616/<p>If you use decorators to views, it will greatly improve readability and extensibility of your code. I'm using a couple of decorators like this to reduce complexity and redundancy in my view codes.</p>
<p><code>wraps</code> from Python 2.5's standard library make the attributes (name, docstring, and etc) of the decorated function …</p>
Freely redistributableA tip for preserving GET arguments with pagination
2009-06-24T00:31:22.031915-05:00achimnolhttps://djangosnippets.org/snippets/1592/<p>This snippet shows a way to preserve GET arguments with pagination. Many people make mistakes to omit the query arguments besides page arguments for the pagination, and making sure correct may sphagettize your code.</p>
Freely redistributableTemplatetag for granular permissions
2009-06-24T00:20:16.109065-05:00achimnolhttps://djangosnippets.org/snippets/1591/<p>If you're using <a href="http://code.google.com/p/django-granular-permissions/">Django granular permissions</a>, this templatetag may be useful.</p>
<p>It enables you to check permission in templates, as mentioned in the code:</p>
<pre><code>{% has_row_perm user object "staff" as some_var %}
{% if some_var %}
...
{% endif %}
</code></pre>
<p>To be used in <code>if</code> statements, it always saves …</p>
Freely redistributable