0001-assets-fix-asset_url-templatetag-when-file-does-not-.patch
combo/apps/assets/templatetags/assets.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import os |
|
18 | ||
17 | 19 |
from django import template |
18 | 20 |
from django.db.models.fields.files import ImageFieldFile |
19 | 21 |
from django.utils import six |
... | ... | |
51 | 53 |
if not asset: |
52 | 54 |
return '' |
53 | 55 | |
56 |
if not os.path.exists(asset.path): |
|
57 |
return asset.url |
|
58 | ||
54 | 59 |
geometry_string = kwargs.pop('size', None) |
55 | 60 |
if not geometry_string or asset.file.name.endswith('svg'): |
56 | 61 |
return asset.url |
tests/test_public_templatetags.py | ||
---|---|---|
181 | 181 |
t = Template('''{% load assets %}{% asset_url page.picture "collectivity:banner" size="200x200" %}''') |
182 | 182 |
assert t.render(Context()).startswith('/media/cache/') |
183 | 183 | |
184 |
# unless file is missing |
|
185 |
os.remove(page.picture.path) |
|
186 |
del page.picture.file |
|
187 |
t = Template('''{% load assets %}{% asset_url page.picture "collectivity:banner" size="200x200" %}''') |
|
188 |
assert t.render(Context({'page': page})) == '/media/page-pictures/test2.png' |
|
189 | ||
184 | 190 |
# unless it's in SVG |
185 | 191 |
page.picture = File(StringIO('test'), 'test2.svg') |
186 | 192 |
page.save() |
187 |
- |