Here is a short piece of code to help write a simple pager (or paginator) in django.
Its main function is to insert ellipses at the right places. (Of course! What's hard about a pager anyway). The result is like the one you see on stackoverflow.com.
Examples:
The code (See the original post for the code, if you are using a feed reader such as Google Reader):
Friday, September 23, 2011
Wednesday, September 7, 2011
python get relative time
Here is a little piece of python code to get the "age" of a timestamp (in other words, how much time has elapsed since then). Like what you see on Hacker News or reddit, "8 hours ago", "1 day ago", etc.
The job of this code is to figure out the "8 hours" and "1 day" part.
Here is the code (hosted as a gist on github).
I think I got some inspiration from someone's blog on the internet, but I can't find it now. Anyway the codes don't look alike IIRC and it's short, and I put it in the public domain. Do whatever you want.
The function is simple and it's not very robust, e.g. it doesn't handle the case when you pass in a date in the future. But it should be easy to extend.
And it only works for English. For something that can do i18n, you may need gettext.
The job of this code is to figure out the "8 hours" and "1 day" part.
Here is the code (hosted as a gist on github).
I think I got some inspiration from someone's blog on the internet, but I can't find it now. Anyway the codes don't look alike IIRC and it's short, and I put it in the public domain. Do whatever you want.
The function is simple and it's not very robust, e.g. it doesn't handle the case when you pass in a date in the future. But it should be easy to extend.
And it only works for English. For something that can do i18n, you may need gettext.
Subscribe to:
Posts (Atom)

