FileField that checks that the file is a valid CSV and if specified in `expected_fieldnames` checks that the fields match exactly.
The widget's `accept` parameter is set to accept csv, text and excel files.
**TODO**: Validate the entirety of the CSV file, not just the headers. But this should be enough for most use cases, as checking the whole file could be computationally expensive for huge files.
Example usage:
people = CSVField(expected_fieldnames=['First Name', 'Last Name'])
This snippets is inspired from [#2995](https://djangosnippets.org/snippets/2995/) but add the following:
* get rid of `singledispatch` so we can use it with python2 without pip installing anything
* streaming capabilities
* the configuration params (header, fields, exclude...) are passed to the action function so we don't pollute the ModelAdmin class
* fix utf8 issue in header
Implements necessary permission checks on a user model to be compatible with django admin, but just return true on all permissions without actually checking it against anything. Useful when you have a user model that should always be allowed to use django admin, and you don't care about using django's own PermissionsMixin and don't want to have those models added to your database.
Say you want to keep your API secure and thus it has authentication, but there's this one View action in a ViewSet which unlike the rest of the ViewSet's actions needs to allow free access without authentication.
This solution applies the good old `IsAuthenticated` permission to all ViewSet actions except those defined in a `login_exempt_actions` list. That's a list of the ViewSet action's names.
This is a simple solution for this particular problem, which I imagine could be quite common.
Any case where the requirements are more complex should implement one of the DRF permissions extensions which allow for the use of logical operators.
**NOTE**: Remember that `request.user` will be an `AnonymousUser` instance, so be careful with any code which assumes it'll be a `User` instance. This could be the case with, say, a custom `get_queryset` implementation.
This is a modificated version of `CachedPaginator` by **daniellindsley** [https://djangosnippets.org/snippets/1173/](https://djangosnippets.org/snippets/1173/) ([web-arhive-link](https://web.archive.org/web/20150927100427/https://djangosnippets.org/snippets/1173/)). Which not only cache `result_objects`, but the `total_count` of the `queryset` too (usefull if computating the count is an expensive operation too).
Rough check for unused methods in our apps. Scans models, views, utils, api, forms and signals
files for what look like methods calls, then looks at all of our classes' methods to ensure each
is called. Do not trust this blindly but it's a good way to get leads on what may be dead code. Assumes a setting called `LOCAL_APPS` so it only bothers to look at the code you've written rather than everything in `INSTALLED_APPS`.
Filter to remove words at the end of a string
Example:
Myvar: "My name is Arthur and django si awesome"
{{myvar|wordend:4}}
Output: "My name is Arthur"
Filter to remove words at the beginning of a string
Example:
Myvar: "My name is Arthur and django si awesome"
{{myvar|wordremoveb:5}}
Output: "django is awesome"
This is useful when you don't want to put any `{% verbatim %}` tag in the file(s) you're including within template(s) (because you want it/them completely raw) and when you want to load such file(s) from static dir(s), as native `{% include %}` tag can't achieve that (still).
Put the provided code in *templatetags/rawinclude.py* in your Django app, and then use it in your template(s) like this:
`{% load rawinclude %}{% raw_include 'file.html' %}`