labeled hidden input with choices
Useful when you need to show a selected option from a charfield with choices, but don't want that user change this.
- form
- widget
- input
Useful when you need to show a selected option from a charfield with choices, but don't want that user change this.
This displays the short commit id from the current HEAD. Add this to your admin/base_site.html or any other template. {% block userlinks %} / HEAD: <span style="color:yellow">{% git_short_version %}</span> / {{ block.super }} {% endblock %}
Replaces usual spaces in string by non breaking spaces. "some words" --> "some words" Usage in template: {% load nbsp %} .... {{ user.full_name|nbsp }}
This allows for easy generation of HTML5 placeholders based on a form_field's label. Use like so: {% form_placeholder form.username %}
UserAuthCode generates an authentication code for Django user objects. This code can be used to verify the user's email address and to activate his account. Unlike other solutions there's no need add any tables or fields to your database. Current version is hosted on [GitHub](https://github.com/badzong/django-userauthcode). There's also an example how to use it in your Django project.
Based on [Snippet 2558](http://djangosnippets.org/snippets/2558/) but without saving the generated file to disk before downloading. Requires, pyExcelerator Usage: Add the code to your project, e.g. a file called actions.py in the project root. Register the action in your apps admin.py: `from myproject.actions import export_as_xls class MyAdmin(admin.ModelAdmin): actions = [export_as_xls]`
This middleware redirects HTTP requests to HTTPS for some specified URLs, in the same way as [85](http://djangosnippets.org/snippets/85/). It also changes the `url` template tag to use the `https` scheme for the same URLs. For example, if you have the following URL pattern: url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'https': True}) then the template: {% from future import url %} {% url 'django.contrib.auth.views.login' %} will render: https://host.example.com/accounts/login/ and any plain HTTP requests to /accounts/login get redirected to HTTPS. URL patterns not marked with `'https': True` remain unaffected. Notes: * The HttpRequest object must be present in the template context as `request`, so add `django.core.context_processors.request` to `TEMPLATE_CONTEXT_PROCESSORS` and make sure to use `RequestContext`. * This snippet overrides the existing `url` template tag. Remove the last line and register the new `url` function properly, as a separate tag, if this makes you unhappy. You'd then have to change your templates to use it. * It would be nicer to change the way reverse look-ups behave instead of changing only the `url` template tag, but the URL resolver, and the `reverse` function, know nothing about requests, so have no way to find the correct host name.
With this function if you filter using regular admin filters you'll reduce the queryset to the objects in view.
Routes models of each app into the database with same name falling back to "default" database.
This is a 'fixed' version of snippet [1868](http://djangosnippets.org/snippets/1868/) Changes: *Correctly handle the Content-Type, because amazon requieres it to be named with a dash and we can't use dashes in the form attributes declaration. *Also added max_size handling, with the corresponding update to the policy generation. *Added an example usage with some javascript for basic validation. [See the amazon reference](http://aws.amazon.com/articles/1434?_encoding=UTF8&jiveRedirect=1)
AdminImageWidget and AdminImageMixin to use easy_thumbnails in admin site forms for models with ImageField field.
Append span with text, image or other data to any django widget so bootstrap can format it like in [here](http://twitter.github.com/bootstrap/base-css.html#forms) (scroll to "Extending form controls" section) Example usage: ` example_field = CharField( max_length=255, min_length=1, label='Label', required=False, widget=AppendWidget(base_widget=TextInput, data='@') ) `
Prepend span with text, image or other data to any django widget so bootstrap can format it like in [here](http://twitter.github.com/bootstrap/base-css.html#forms) (scroll to "Extending form controls" section) Example usage: ` example_field = CharField( max_length=255, min_length=1, label='Label', required=False, widget=PrependWidget(base_widget=TextInput, data='@') ) `
@cache(60) def heavy_computation(): for x in xrange(10000000): pass # just waste some time` The result of `heavy_computation` calls will be cached for 60 seconds. This cache decorator does not use the Django cache backend and uses the local memory instead.
Use this snippet to list all errors in a form. The message will be shown in a boostrap-type alert which can be 'closed' using a dismiss button. The **field label** and the **error** will be listed. e.g. > * Name: This field is required > * Email: Please enter a valid email