You'll need to `pip install pyScss` first.
Converts on the fly, so you won't want to use this for much more than just testing.
Usage in a template:
{% load sass %}
{% include_sass "disclosures/css/base.scss" %}
{% include_sass "disclosures/css/grid.scss" %}
This snippet is an improved version of the [ifusergroup](http://djangosnippets.org/snippets/1576/) tag that allows spaces in any of the group names. It also fixes a small bug where if a group didn't exist none of the subsequent groups would be checked.
This code allows you to upload a mp3 to the Admin Frontend. The ID3 tags are automatically read out and filled in to the according fields.
This should work for other filetypes as well. As long as they have an id3 tag.
I needed to display formset into table and I didn“t like solution I have found. So I have written this simple tag you can use it in templates like this:
`
{% for row in formset|square_it:6 %}
<tr>
<td>
</td>
{% for form in row %}
<td>
{% for field in form %}
{{ field }}
{% endfor %}
</td>
{% endfor %}
`
Get any value from settings.py as a template variable. The variable can then be used in conditional tags.
E.g. to show a link to a help page only if it the help page url is defined in settings.py
{% load get_setting %}
{% get_setting MY_HELP_URL as help_url %}
{% if help_url %}<a href="{% help_url|safe %}">Help</a>{% endif %}
Save the code as app_name/templatetags/urlbuilder.py. Supply your view with a dictionary of "default" query params, likely taken from the request. Then, in the template:
`{% load urlbuilder %}
{% url some-url as base_url %}`
That sets you up. Then you can make links. For example:
<th><a href="{% build_url base_url query_params sort=name %}">Name</a></th>
Say query_params has:
page: 2,
filter: active,
sort: id
The above tag would spit out /base/url?page=2&filter=active&sort=name
The tag also has support for using a variable as the replacement key. Say "filter_key" is a variable available to the template with the value "filter":
{% build_url base_url query_params filter_key default %}
Using the above example, that would output /base/url?page=2&filter=default&sort=id
A custom templatetag for inlining image in the browser.
The principe is to base64 encode the image and avoid a http request.
There is a cache handling, you just have to specify a writable directory.
An example of the utilisation (template part): [http://djangosnippets.org/snippets/2267/](http://djangosnippets.org/snippets/2267/)
The explication on [http://raphaelbeck.wordpress.com/2010/11/14/make-inline-images-to-improve-performance-with-django-template-tags/](http://raphaelbeck.wordpress.com/2010/11/14/make-inline-images-to-improve-performance-with-django-template-tags/)
The example of the Image inlining template tag lib which inline images in the browser instead of making an Http request.
The lib is available at : [http://djangosnippets.org/snippets/2268/](http://djangosnippets.org/snippets/2268/)
Enhanced version of snippet [1113](http://djangosnippets.org/snippets/1113/)
Usage example (not self-contained):
@register.tag
def groupurl(parser, token):
'''
Syntax::
{% groupurl view_name group [key=val, [key=val, ...]] [as varname] %}
Example::
<a href="{% groupurl blog_detail group slug=blog.slug %}">{{ blog.name }}</a>
'''
bits = token.contents.split()
tag_name = bits[0]
if len(bits) < 3:
raise template.TemplateSyntaxError("'%s' takes tag at least 2 arguments (path to a view and a group)" % (tag_name,)
bits_iter = iter(bits[1:])
# view_name + group and url kwargs
args, kwargs = parse_args_and_kwargs(parser, bits_iter, stop_test='as', tagname=tag_name)
if len(args) != 2:
raise template.TemplateSyntaxError("'%s' takes exactly two non-kwargs (path to a view and a group)" % (tag_name,))
view_name, group = args
# as var
asvar = None
for bit in bits_iter:
asvar = bit
return GroupURLNode(view_name, group, kwargs, asvar)
These are template tags meant to support the construction of text in a random or seeded random (reproducible) way. Two tags are provided: `seed_randomization` and `any`.
Only seed the randomization if you wish to have the options generated the same way each time. Only necessary once per request, if done early enough in the rendering process.
Example without seeding:
<p>
{% any %}
One day
Once upon a time
In a galaxy far, far away
{% endany %}
a young foolish {% any %}programmer|lawyer|Jedi{% endany %}
{% any %}
set out
began his quest
ran screaming
{% endany %}
to pay his stupid tax.
</p>
# Possible outcomes:
<p>In a galaxy far, far away a young foolish lawyer set out to pay his stupid tax.</p>
<p>One day a young foolish programmer ran screaming to pay his stupid tax.</p>
Be sure to read the documentation in the code.
This is custom tag I wrote for myself for solving situations when you have filter form and page
numbers in the same page. You want to change ?page=.. or add it if it doesn't exist to save
filter form data while moving through pages.
Usage: place this code in your application_dir/templatetags/add_url_parameter.py
In template:
{% load add_get_parameter %}
<a href="{% add_get_paramater param1='const_value',param2=variable_in_context %}">
Link with modified params
</a>
It's required that you have 'django.core.context_processors.request' in TEMPLATE_CONTEXT_PROCESSORS
URL: [http://django.mar.lt/2010/07/add-get-parameter-tag.html](http://django.mar.lt/2010/07/add-get-parameter-tag.html)
There's a whole range of examples online for resizing images in Django some of which are incredibly comprehensive with a wide variety of options. Here's my take on the task that serves as a simple drop in for when you don't want to include a separate app.
- Only generates the resized image when first requested.
- Handles maintaining proportions when specifying only a width or a height.
- Makes use of PIL.ImageOps.fit for cropping without reinventing the wheel.