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.
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)
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='@')
)
`
Simple tag to check which page we are on, based on resolve: useful to add an 'active' css class in menu items that needs to be aware when they are selected.
Typical usage is like:
`
<ul>
<li class="{% active request "myapp:myview1" %}">My View 1</li>
<li class="{% active request "myapp:myview2" %}">My View 2</li>
</ul>
`
@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 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.