Login

All snippets

Snippet List

Form and ModelForm inheritance DRY

Modelform cant inhertit from forms. To solve this issue, split thing you wanto to inherit into filed definition and functionality definition. For modelform use the base_fields.update method as mentioned in the code.

  • form
  • inheritance
Read More

Instructions and code to use drupal 7 passwords

This is another fork of http://djangosnippets.org/snippets/2729/ that fixes the issue. Unlike those other versions i give you instructions so it works for you, this is modified a little. Instructions: If you want to import the passwords from drupal you need to prepend to each of them the word drupal so it looks like this: drupal$S$DQjyXl0F7gupCqleCuraCkQJTzC3qAourXB7LvpOHKx0YAfihiPC Then add this snippet to someapp/hashers/DrupalPasswordHasher.py And then in your settings add this: PASSWORD_HASHERS = ( 'django.contrib.auth.hashers.PBKDF2PasswordHasher', 'someapp.hashers.DrupalPasswordHasher', 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', 'django.contrib.auth.hashers.BCryptPasswordHasher', 'django.contrib.auth.hashers.SHA1PasswordHasher', 'django.contrib.auth.hashers.MD5PasswordHasher', 'django.contrib.auth.hashers.CryptPasswordHasher', ) So, what did i modify First i added the attribute algorithm to the class, django uses this word to identify wich hasher to use, so the passwords beggining with drupal should be verified with the hasher.algorithm == 'drupal' Ok so know django knows to use our class, but now our passwords won't validate because we changed them by adding the word drupal, so what do we do? we modify the verify method to remove the word drupal before verification :P Hope it helps

  • django
  • password
  • drupal
Read More

ReST google-map directive.

Use this directive to show google-map if you don't want to use 'raw' directive. default location is my favorite place. Of course you can change it :)

  • restructuredtext
  • google-map
  • directive
  • docutils
Read More

Django Admin Filter __in query string

A hack to add __in ability to links generated in the Django Admin Filter which will add and remove values instead of only allowing to filter a single value per field. Example ?age_group__in=under25%2C25-35

  • filter
  • Admin
  • ChangeList
  • query_string
Read More

Validate request params without custom form

When work at site api for android client, I found use form to validate user input is too complex, so I write this. usage: @param('param_name', 'default_value', validate_func) def api_func(request): # access cleaned data. param_name = request.DATA['param_name'] JsonResponse is my class. replace with HttpResponse or whatever

  • request-validate
Read More

3109 snippets posted so far.