This middleware uses Django's Geoip support (https://docs.djangoproject.com/fr/2.2/ref/contrib/gis/geoip2/), as well as axes's package helper to retrieve IP address (since Django's REMOTE_ADDR might be wrong when behind a reverse proxy).
Ensure your geolite DB files are up to date (eg. with https://djangosnippets.org/snippets/10674/).
The checker is optional, but ensures that security is not broken due to a misspelled/missing GEOIP_COUNTRY_WHITELIST.
This management command updates country and city Geolite databases from Maxmind (binary databases, not CSV ones), for use with Django's builtin Geoip utilities.
Requires to install "basicauth" package, which does basic-auth header encoding/decoding cleanly according to RFCs.
Could be improved to return a "realm" in case of http401, like in https://djangosnippets.org/snippets/1720/, although I'm not sure it's really useful in django usecases.
Small fix to make https://www.djangosnippets.org/snippets/1779/ compatible with Django 1.11
To use this you'll also need the javascript from https://www.djangosnippets.org/snippets/1780/
I added an overridden optgroups method that can handle the additional tuple and a couple minor things I gathered while investigating for a fix (a default level_indicator of "+--" and changed paths for the JS files.
All credits goes to @anentropic :-)
Django's CharField requires a max_length, and TextField displays a multi-
line widget, but in Postgres there's no reason to add an arbitrary max
thanks to the `varlena` storage format. So this is a TextField that
displays as a single line instead of a multiline TextArea.
Use nginx sendfile (X-Accel-Redirect) function to serve files but pass traffic through django. Can be used to serve media files only to logged-in users.
Takes a tweet url, requests the json from Twitter oEmbed, parses the json for the html element and returns it to your template. The html returned is ready to go and will be shown as a tweet on your web page. This uses the Requests library for Python. A full example can be found on GitHub https://github.com/z3ke1r/django-tweet-embed.
**Success Message has object properties**
Success Message can have an object name or the properties of the object model to collide with the message see code below
If you have a model instance you want to merge into another, it's handy to hand over all the relations into the model you want to merge into, so the deletion won't trigger cascading deletions from other tables.
You can pass an `Iterable` of the same objects (a.k.a `QuerySet`) to the model, and then process it with the new model's `pk`.
This decorator is based on user_passes_test, but when a user is logged in and fails the test, it will render a 403 error instead of redirecting to login - only anonymous users will be asked to login. Version working with Django 1.11, based on version found on [https://djangosnippets.org/snippets/254/] , which is deprecated.
You're looking at the most-bookmarked snippets on the site; if you'd like to help useful snippets show up here, sign up for an account and you'll get your own bookmarks list.