Login

Snippets by dnordberg

Snippet List

Updated - Template context debugger with (I)Pdb

Tag to inspect template context, filter to inspect variable. Originally by denis, [http://www.djangosnippets.org/snippets/1550/](http://www.djangosnippets.org/snippets/1550/). This just extracts variables from the context to locals for quicker access and autocompletion (When using ipdb). Additionally, 'vars' holds context keys for quick reference to whats available in the template.

  • template
  • debug
  • context
  • pdb
  • ipdb
Read More

autotranslate po files using google translate

Save to autotranslate.py, run using python autotranslate.py pofile inputlang outputlang, eg. python autotranslate.py path_to_blank_fr_lang.po en fr, to translate to french. Some known bugs: * Doesn't handle some line returns properly * Block translations aren't formated correctly in the translation. If anyone has any issues or fixes please post to the comments. Of course the output shouldn't be used as substitute to a proper translation.

  • translation
Read More

versioned_media templatetag

Best practice based on [YSlow recommendations](http://developer.yahoo.com/yslow/), add the following to your Apache config for your media directory. <Directory /home/.../site_media/> ... FileETag None ExpiresActive on ExpiresDefault "access plus 10 years" AddOutputFilterByType DEFLATE text/css application/x-javascript </Directory` Make sure to enable mod_deflate and mod_expires.

  • templatetag
  • css
  • media
  • js
  • versioned_media
Read More

Modify query string on a url

Modify a query string on a url. The comments in the code should explain sufficiently. String_to_dict, and string_to_list are also useful for templatetags that require variable arguments.

  • url
  • query
Read More

extras.py for management commands

! Note - no longer needed Save this script in the same directory as manage.py and run it through the command line. It picks up project Command class instances. Something that will hopefully be fixed in the Django SVN version soon. Heres an example of a command: #utils/management/commands/sqlallall.py from django.core.management import call_command from django.core.management.base import BaseCommand from django.db import models class Command(BaseCommand): help = "Returns sqlall for all installed apps." def handle(self, *args, **options): """ Returns sqlall for all installed apps. """ for app in models.get_apps(): call_command("sqlall", app.__name__.split(".")[-2])

  • management
  • commands
Read More

dnordberg has posted 7 snippets.