djangosnippets.org: Latest snippets posted by Batistehttps://djangosnippets.org/users/Batiste/2009-03-31T12:11:31.719502-05:00BatisteSmart i18n date diff (twitter like)
2009-03-31T12:11:31.719502-05:00Batistehttps://djangosnippets.org/snippets/1409/<p>This snippet display a human readable date diff. You give it the your date in parameter and the diff with datetime.datetime.now() is returned. The diff must be positive to be more accurate (future dates are not supported)</p>
<p>Usage:</p>
<pre><code>{{ status.created_at|date_diff }}
</code></pre>
<p>Will give something like:</p>
<pre><code>less than 1 minute ago …</code></pre>
Freely redistributableA dict template tag
2008-04-21T05:02:13.819455-05:00Batistehttps://djangosnippets.org/snippets/713/<p>When you need to include a specific javascript file/code snippet in your page, it's always better to do it at the bottom of your page to avoid to block the rendering too soon. This tag provide you a nice way to include and launch only what is needed:</p>
<p>Example in …</p>
Freely redistributableA action decorator for URLs
2008-03-28T08:22:10.950526-05:00Batistehttps://djangosnippets.org/snippets/672/<p>This decorator handle a extra "action" parameter from an url and call this desired action in the provided views module.</p>
<p>Example:</p>
<pre><code>from posts import views
urlpatterns = patterns('posts.views',
...
url(r'^(?P<id>\d+)/(?P<action>delete|publish|edit)/$', action(views), name="posts-action"),
...
)
</code></pre>
<p>In templates:</p>
<pre><code>{% url posts-action id=post.id,action="delete" %}
</code></pre>
Freely redistributableAuto rendering decorator with options
2008-01-22T10:21:09.404358-06:00Batistehttps://djangosnippets.org/snippets/559/<p>This view decorator renders automaticaly the template with the context provided both by the view "return" statement. For example:</p>
<pre><code>@auto_render
def my_view(request):
...
return 'base.html', locals()
</code></pre>
<p>You can still return HttpResponse and HttpResponseRedirect objects without any problems. If you use Ajax requests, this decorator is even more useful. Imagine this …</p>
Freely redistributablePaginator template tag using ObjectPaginator
2007-05-11T02:31:52.229333-05:00Batistehttps://djangosnippets.org/snippets/226/<p>This template inclusion tag provide a way to have multiple pagination blocks in the same page. Aditionnal parameters in "request.GET" are also automaticaly keeped in pagination links.</p>
<p>Usage :</p>
<p><strong>{% show_pagination users_paginator request "page_members" %}</strong></p>
<p>The expected result : </p>
<p><strong>[1] 2 3 … 14</strong></p>
<p>Or :</p>
<p><strong>1 … 5 6 …</strong></p>
Freely redistributableNew forms signup validation
2007-04-19T05:21:24.425960-05:00Batistehttps://djangosnippets.org/snippets/191/<p>This snippets provide username availability, double email and password validation. You can use it this way :</p>
<pre><code>f = SignupForm(request.POST)
f.is_valid()
</code></pre>
Freely redistributable