HTML5 Placeholder from FormField label
This allows for easy generation of HTML5 placeholders based on a form_field's label. Use like so: {% form_placeholder form.username %}
- forms
- html5
- form_field
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
If you have long words (no spaces) that are so long that it's messing up your design, add a 0-width space in the word every X chars. Usage: Step 1. Inside your app's directory, create dir called 'templatetags'. In that directory, create a .py file (say 'app_extras.py'). Make sure you make this a python module, make an empty the init .py (with the 2 underscores on each side). Step 2. Inside template (make sure app is on INSTALLED_APPS list in settings.py): {% load app_extras %} Step 3. Enjoy! {{ some_long_word_with_no_breaks|zerowidthspace_separator:25 }}
This function, meant to be used with the pre_save signal, will convert any markdown from a text field to it's corresponding html field.
This snippit is meant to be used with the pre_delete signal to delete any files associated with a model instance before the instance is deleted. It will search the model instance for fields that are subclasses of FieldFile, and then delete the corresponding files. As such, it will work with any model field that is a subclass of FileField.
3110 snippets posted so far.