Login

Tag "cookies"

Snippet List

Extend generic view object_list to support paginate_by via cookies

You can use this view to have a possibility to use ?paginate_by=x on your generic lists. Example usage in urls.py: `url('^list/', object_list_with_paginate_by, {'queryset': Invoice.objects.all(), 'template_name': 'invoices/list.html', 'paginate_by': 10}, 'invoices.list')` 10 is the default objects count per page. For the first time parameter paginate_by is set in URL, we have to get it straight from there. If the parameter is set, then also set the cookie for later requests without the parameter If the parameter is not set, then we try the cookie or default value

  • object_list
  • cookies
  • paginate_by
Read More

Sign a string using SHA1, then shrink it using url-safe base65

Sometimes it's useful to sign data to ensure the user does not tamper with it - for example, cookies or hidden form variables. SHA1 is cryptographically secure but weighs in at 40 characters, which is pretty long if you're going to be passing the data around in a URL or a cookie. These functions knock an SHA1 hash down to just 27 characters, thanks to a base65 encoding that only uses URL-safe characters (defined as characters which are unmodified by Python's urllib.urlencode function). This compressed hash can then be passed around in cookies or URLs, and uncompressed again when the signature needs to be checked. UPDATE: You probably shouldn't use this; see [http://fi.am/entry/urlsafe-base64-encodingdecoding-in-two-lines/](http://fi.am/entry/urlsafe-base64-encodingdecoding-in-two-lines/) for a smarter approach based on Python's built-in base64 module.

  • security
  • base65
  • signing
  • cookies
  • hashlib
  • hashes
  • sha1
Read More

2 snippets posted so far.