Management About page reworked + cosmetic changes
[myslice.git] / portal / templatetags / portal_filters.py
index 9bd0175..74f113a 100644 (file)
@@ -1,5 +1,6 @@
 from django import template
 from django.template.loader_tags import do_include
+from django.core.files.storage import default_storage
 from myslice.settings import theme
 
 register = template.Library()
@@ -37,4 +38,13 @@ def widget(parser, token):
         raise template.TemplateSyntaxError, \
             "%r tag requires a single argument" % token.contents.split()[0]
 
-    return IncludeNode(template_name[1:-1])
\ No newline at end of file
+    return IncludeNode(template_name[1:-1])
+
+@register.filter(name='file_exists')
+def file_exists(filepath):
+    if default_storage.exists('portal' + filepath):
+        return filepath
+    else:
+        index = filepath.rfind('/')
+        new_filepath = filepath[:index] + '/image.png'
+        return new_filepath
\ No newline at end of file