A filter to resize a ImageField on demand, a use case could be:
`
<img src="object.get_image_url" alt="original image">
<img src="object.image|thumbnail" alt="image resized to default 200x200 format">
<img src="object.image|thumbnail:"200x300" alt="image resized to 200x300">
`
The filter is applied to a image field (not the image url get from *get_image_url* method of the model), supposing the image filename is "image.jpg", it checks if there is a file called "image_200x200.jpg" or "image_200x300.jpg" on the second case, if the file isn't there, it resizes the original image, finally it returns the proper url to the resized image.
There is a **TODO**: the filter isn't checking if the original filename is newer than the cached resized image, it should check it and resize the image again in this case.
- filter
- models
- thumbnail
- resize
- imagefield
Cheers to limodou for getting me thinking about this. The only problem with his implementation is that it doesn't support Django's "." syntax for accessing array/dict elements. In the Django style of allowing simple syntax for designers while allowing for greater flexibility, and less template duplication for conditionals that were previously impossible to represent in templates, I modified Django's built-in If tag.
This is an adaptation/enhancement to Django's built in IfNode {% if ... %} that combines if ifequal ifnotequal into one and then adds even more. This
Supports
1. ==, !=
2. not ....
3. v in (1,"y",z)
4. <=, <, >=, >
5. nesting (True and (False or (True or False)))
How to use it:
{% pyif i == 1 or (5 >= i and i != 7) and user.first_name in ('John', 'Jacob') %}
'Tis true.
{% else %}
'Tis false.
{% endif %}
I hope you like it.
- template
- tag
- templatetag
- if
- conditional
- ifequal
- ifnotequal
Makes a call to Google's geocoder and returns the latitude and longitude as a string or returns an empty string. Called by the save method to save the lat and long to the db to be used when rendering maps on the frontend. Reduces the number of calls to geocoder by calling only when saving, not on every viewing of the object.
Be sure to import *urllib* and the project's *settings*, and to define GOOGLE_API_KEY in settings.py.
**Example:**
def save(self):
location = "%s+%s+%s+%s" % (self.address, self.city, self.state, self.zip_code)
self.lat_long = get_lat_long(location)
if not self.lat_long:
location = "%s+%s+%s" % (self.city, self.state, self.zip_code)
self.lat_long = get_lat_long(location)
super(Foo, self).save()
- google-maps
- geocode
- google-api
- latitude
- longitude