django-constance generic view
For several projects I am using generic views instead of django-admin, I needed a generic view for constance instead of using their django-admin based app.
- django-constance
For several projects I am using generic views instead of django-admin, I needed a generic view for constance instead of using their django-admin based app.
Obfuscate javascript strings. * Convert * `{{'Pita Hummus'|js_obfuscate_string}}` * to something like * `'P4itzga Hnumg7mubs'.replace(/[4zgn7b]/g,'')` Making it hard to text-search for strings in your code.
I've reimplemented the code I found somewhere on the web within my models file. The earlier version was incapable of converting all formats to JPG while this code converts all formats and compresses all of them successfully. You need to have PILLOW installed for this to work.
I've reimplemented the code I found somewhere on the web within my models file. The earlier version was incapable of converting all formats to JPG while this code converts all formats and compresses all of them successfully.
## 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
## 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
This code based on Basic Auth Middleware by joshsharp. URL : https://djangosnippets.org/snippets/2468/
Decorating a whole view involves overriding the dispatch method so you can decorate it, even if all you do is a passthrough. This creates a class decorator for decorating CBVs. For example, if you want to make a view require a login: @decorate_dispatch(login_required) class MyCBV(TemplateView): ...
-
A "fake" model field which is an alias to another underlying database field. Mirrors everything including queryset lookups, instance attributes, even if the field has been used on the model already (this isn't possible just by using db_column).
This is for situations where a ModelForm is needed on an existing object, but we want to disable ForeignKey widgets, and only use them as a display. Usage: save the code in the top half of the example above into a file somewhere in your django project, in this example we will call it customwidget.py The second half shows an example usage, but setting the widget and queryset in the __init__ method of the form. If the queryset returned by the ForeignKey model (Example.objects.all() ) is small, you can omit the __init__ code.
Consistency check on file fields between database and filesystem
GEOSGeometry.buffer() accepts a distance argument which is in the unit of the coordinate reference system of the geometry. It is often necessary, however, to specify the buffer size in a more down-to-earth coordinate system, for example meters. with_metric_buffer(geom, buf_size) implements this functionality.
1. Add this decorator to whatever function: @profile('/tmp/0123test.prof') def test_function(): pass 2. If it's a django view function, let it run once. 3. Use "runsnake" to open the ".prof" file. Sweet.
**preview_template.py** allows you to test a Django template located in the current working directory (first argument). The template is rendered with the given context (second argument, *optional*), and the result is immediately piped into the browser with the [bcat](http://rtomayko.github.io/bcat/) utility. **Usage:** python preview_template.py [template name] [context] **Example:** python preview_template.py template.html "{'username': 'Његош'}"
3109 snippets posted so far.