Fixed minimal version, works with Django 1.7+, tested on Django 1.9.
Add the following to your settings:
AUTHENTICATION_BACKENDS = [
'project.backends.UserModelEmailBackend', # Login w/ email
'django.contrib.auth.backends.ModelBackend', # Login w/ username
]
The idea here is to wrap the original `delete_selected` functionality in a way that I shouldn't have to reimplement the templates (confirmation/error response) serving, just extend the original.
What this code does, it wraps the queryset's delete function with a closure, so when it really gets called (after the confirmation), it executes the extra functionality you wish to.
After looking at the original code, this seemed to be the most efficient way of doing it.
## required
* `{% load trans%}`before using this snippets
* Add this [template filter](https://djangosnippets.org/snippets/2253/) to your custom templatetags and load it before using this snippets
* Bootstrap framework
Start simple SMTP server on localhost:25 and print to standard output all email headers and the email body. Useful for debugging outgoing mail without configuring SMTP daemon in development enviroment.
Based on [#2369](https://djangosnippets.org/snippets/2369/)
Save the snippet as actions.py within your django app, and then add an action on any model you want in it's ModelAdmin definition.
Example usage:
from actions import export_as_csv_action
class YourModelAdmin(admin.ModelAdmin):
list_display = (...)
list_filter = [...]
actions = [export_as_csv_action("CSV Export", fields=[...])]
Template context processor for delegating other context processors to individual apps.
Useful if all views within an app require common context variables that aren't required by other apps.
**[Improved and Released as Save The Change.](https://github.com/karanlyons/django-save-the-change)**
Django 1.5 added the `update_fields` `kwarg` to `Model.save()`, which allows the developer to specify that only certain fields should actually be committed to the database. However, Django provides no way to automatically commit only changed fields if they're not specified.
This mixin keeps track of which fields have changed from their value in the database, and automatically applies `update_fields` to update only those fields.
The version of [snippet](http://djangosnippets.org/snippets/2397/) that works with Django 1.5. Kudos to [kmike](http://djangosnippets.org/users/kmike/) for the original snippet.
In Django 1.5 url tags require you to pass in the name of the url as a string.
So where you used to be able to do this {% url home_page %} you now have to do this {% url 'home_page' %}
Upgrading an old project can be a pain, so here is a snippet for a py file that will update all your url tags.
Just put it in a py file in your root directory and execute it.
The error you get otherwise is:
'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.
This is a authentication backend for Django, to authenticate via Active Directory. This pulls all group information out of Active Directory and allows for multiple group memberships.
Overridden save() method that adds Gravatar support for a user with a profile photo field (and presumably an email field). Checks to see if user has provided a photo. If not, then query Gravatar for a possible photo. Finally, if Gravatar does not have an appropriate photo for this user, then use whatever default photo is available (in this case, 'users/photos/default_profile_photo.png'... change as necessary).
This decorator will memoize the results of instance methods, similar to `django.util.functional.memoize`, but automatically creates a cache attached to the object (and therefore shares the life span of the object) rather than requiring you to provide your own. Note this is intended for instance methods only, though it may work in some cases with functions and class methods with at least one argument.
This is useful for memozing results of model methods for the life of a request. For example:
class MyModel(models.Model):
#Fields here
@auto_memoize
def some_calculation(self):
#some calculation here
return result
You're looking at the top-rated snippets currently on the site; if you'd like to contribute, sign up for an account and you'll be able to rate any snippet you see.