diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-06-12 22:51:11 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-06-12 22:51:11 -0400 |
commit | 3a3a11d32c72ab79ce94679aae7a549230c7104f (patch) | |
tree | 3ac36a302b85d5497b3d335238044c8f481ac0fd /forum/deps/livesettings/templatetags/config_tags.py | |
parent | 8b6a10ead45bcd915f5da223de2b3fd3c30fc7b5 (diff) | |
download | askbot-3a3a11d32c72ab79ce94679aae7a549230c7104f.tar.gz askbot-3a3a11d32c72ab79ce94679aae7a549230c7104f.tar.bz2 askbot-3a3a11d32c72ab79ce94679aae7a549230c7104f.zip |
moved livesettings and django_authopenid into forum/deps
Diffstat (limited to 'forum/deps/livesettings/templatetags/config_tags.py')
-rw-r--r-- | forum/deps/livesettings/templatetags/config_tags.py | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/forum/deps/livesettings/templatetags/config_tags.py b/forum/deps/livesettings/templatetags/config_tags.py new file mode 100644 index 00000000..140014ba --- /dev/null +++ b/forum/deps/livesettings/templatetags/config_tags.py @@ -0,0 +1,91 @@ +from django import template +from django.contrib.sites.models import Site +from django.core import urlresolvers +from forum.deps.livesettings import config_value +from forum.deps.livesettings.utils import url_join +import logging + +log = logging.getLogger('configuration.config_tags') + +register = template.Library() + +def force_space(value, chars=40): + """Forces spaces every `chars` in value""" + + chars = int(chars) + if len(value) < chars: + return value + else: + out = [] + start = 0 + end = 0 + looping = True + + while looping: + start = end + end += chars + out.append(value[start:end]) + looping = end < len(value) + + return ' '.join(out) + +def break_at(value, chars=40): + """Force spaces into long lines which don't have spaces""" + #todo: EF - lazy patch + return value + + chars = int(chars) + value = unicode(value) + if len(value) < chars: + return value + else: + out = [] + line = value.split(' ') + for word in line: + if len(word) > chars: + out.append(force_space(word, chars)) + else: + out.append(word) + + return " ".join(out) + +register.filter('break_at', break_at) + +def config_boolean(option): + """Looks up the configuration option, returning true or false.""" + args = option.split('.') + try: + val = config_value(*args) + except: + log.warn('config_boolean tag: Tried to look up config setting "%s", got SettingNotSet, returning False', option) + val = False + if val: + return "true" + else: + return "" + +register.filter('config_boolean', config_boolean) + +def admin_site_views(view): + """Returns a formatted list of sites, rendering for view, if any""" + + if view: + path = urlresolvers.reverse(view) + else: + path = None + + links = [] + for site in Site.objects.all(): + paths = ["http://", site.domain] + if path: + paths.append(path) + + links.append((site.name, url_join(paths))) + + ret = { + 'links' : links, + } + return ret + + +register.inclusion_tag('forum.deps.livesettings/_admin_site_views.html')(admin_site_views) |