Skip to content
This repository has been archived by the owner on Jun 20, 2018. It is now read-only.

Added Jinja template tag #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions gargoyle/templatetags/jinja_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from coffin.template import Library
from django.conf import settings
from django.template.defaultfilters import slugify
from gargoyle import gargoyle
import logging

logger = logging.getLogger(__name__)
register = Library()

@register.object
def switch_is_active(switch_slug, *instances):
'''
Jinja implementation for the ifswitch
Usage:
{% if switch_is_active('myspecialfeature') %}
{% endif %}

providing a request object (for ip based switches)
{% if switch_is_active('myspecialfeature', request) %}
{% endif %}

providing the user for user based switches
{% if switch_is_active('myspecialfeature', user) %}
{% endif %}
'''
assert slugify(switch_slug) == switch_slug, 'switch slug should be a valid slug'


is_active = gargoyle.is_active(switch_slug, *instances)
logger.info('Switch %s is active is %s, based on these instances %s', switch_slug, is_active, map(type,instances))

return is_active

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name='gargoyle',
version='0.2.3',
version='0.2.4',
author='DISQUS',
author_email='opensource@disqus.com',
url='http://github.com/disqus/gargoyle',
Expand Down