Qucik Render Template Decorator with Contexts
see comment block for example.
- template
- decorator
- context
- render_template
see comment block for example.
These snippets together give you the ability to view all Django SQL queries executed across all incoming requests by visiting a particular URL (`/profiling` in the example). This is useful when developing with the Django test server. This is useful if most of the incoming requests are AJAX requests, because in such cases the debug toolbar will not be able to show which queries got executed. The `SqlProfilingMiddleware` class is the key one. At the end of every incoming request it appends the executed SQL queries to a static class member list. Any information request profiling information can be added in this way. The snippet does not add any security around viewing such information. This was done just to keep the code simple. But when implementing this you will definitely want to restrict access to this URL to only people allowed to view such information.
Improved for BootStrap details: http://twitter.github.com/bootstrap/ Using: class AnyForm(forms.Form, CustomForm): pass Template: <form> {{ form.render_errors }} {{ form.as_div }} </form>
Add this to your admin change_list.html template to replace the actions drop-down with buttons. This is a rewritten version of snippet [1931](http://djangosnippets.org/snippets/1931/) with Django 1.3 compatibility and cleaner code. Thanks to [andybak](http://djangosnippets.org/users/andybak/) for the idea.
An Image says more than 100 words: [readonlytabularinline.png](http://img39.imageshack.us/img39/6555/readonlytabularinline.png) Use `editable_fields` to exclude some fields from being readonly.
Staff can log in as a user, from a url to help with customer support or debugging.
This snippet is greatly inspired by [@jlorich](http://djangosnippets.org/users/jlorich/)'s useful [#2436](http://djangosnippets.org/snippets/2436/). The main difference is that I wanted to choose the names of my URL params instead of being forced into naming them "value1", "value2", etc. When reversing the URL you have to remember that the kwargs aren't friendly. By using the same names in the `filters` list, you don't have to change the way your otherwise write the URL pattern. Also it's clear throughout how you'll be filtering the QuerySet. The other change I made was "erroring early". This avoids running the QuerySet all over again inside `object_detail()` just to have it raise an exception we could have caught the first time.
TemplateZipFile is a class for creating ZipFiles out of Django templates. Usage example: from zipfile import ZIP_DEFLATED from django_zipfile import TemplateZipFile def myview(request, object_id): obj = get_object_or_404(MyModel, pk=object_id) context = { 'object': obj } response = HttpResponse(mimetype='application/octet-stream') response['Content-Disposition'] = 'attachment; filename=myfile.zip' container = TemplateZipFile(response, mode='w', compression=ZIP_DEFLATED, template_root='myapp/myzipskeleton/') container.add_template('mimetype') container.add_template('META-INF/container.xml') container.add_template('chapter1.html', context=context) container.close() return response
Simple logging middleware that captures the following: * remote address (whether proxied or direct) * if authenticated, then user email address * request method (GET/POST etc) * request full path * response status code (200, 404 etc) * content length * request process time * If DEBUG=True, also logs SQL query information - number of queries and how long they took
Class based view returns json serialized saved data or form errors.
This is a ModelChoiceField where the choices are rendered in optiongroups (this is already posible with a normal Choicefield) For this to work properly the queryset you supply should already be ordered the way you want (i.e. by the group_by_field first, then any sub-ordering)
Basically the idea is to import/update model instances from a json data that closely matches the model structure (i.e. identical field names) From my answer to this question: [http://stackoverflow.com/a/8377382/202168](http://stackoverflow.com/a/8377382/202168) See the original question for sample data format.
Check a condition (in this example only equality) on every queryset item in a django form
Counter tag. Can be used to output and increment a counter. For usage, see docstring in the code. This is the first complete tag that I've implemented, I hope that there are no bugs and that it's thread safe.
Template tag to convert number of seconds into mm:ss format
3110 snippets posted so far.