Mimsy Were the Borogoves

Hacks: Articles about programming in Python, Perl, PHP, and whatever else I happen to feel like hacking at.

Two search bookmarklets for Django

Jerry Stratton, August 19, 2014

I run this site through a Django CMS. I often find myself looking for the most recent pages. Now, by default, the most recently edited pages show up at the top, and of course I can link a URL that specifically orders by when pages were added, but there is no way to limit it just to, say, the pages I’ve created this month. Even when I create only a few pages a month, which is normal, those views will still show, in my case, the hundred most recent pages. I’m not aware of a query parameter that will limit the number of results, nor of a query parameter that will only show within the last x days of a date field.

It is possible to show only a single month, but not to show only the current month. Any such bookmark will be out of date once the next month comes around. A JavaScript bookmarklet, however, can do this:

  • javascript:today=new%20Date();recentURL='https://django.localhost/admin/cms/page/?created__month='+(today.getMonth()+1)+'&created__year='+today.getFullYear();window.location=recentURL;

I also find myself going to the main list of pages and then doing a search. A bookmarklet can go directly to the search:

  • javascript:searchTerm=window.prompt('Search%20for?');searchURL='https://django.localhost/admin/cms/page/?q='+searchTerm;window.location=searchURL;

This will prompt for the search term and then construct a search URL with that term. It does not specifically encode the term, but I’ve tested it in Safari, Firefox, and Chrome and it works.

  1. <- Deciphering BASIC
  2. Automator filenames ->