Skip to content

Commit

Permalink
avoid css file when not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ljean committed Feb 28, 2017
1 parent 247f5d7 commit 11b0b74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion coop_bar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

VERSION = (1, 3, 2)
VERSION = (1, 3, 3)


def get_version():
Expand Down
16 changes: 15 additions & 1 deletion coop_bar/templatetags/coop_bar_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,20 @@ def coop_bar(parser, token):


class CoopBarHeaderNode(template.Node):

def __init__(self, option):
self.option = option

def render(self, context):
request = context.get("request", None)

if request:
if self.option == "admin-only" and not request.user.is_staff:
return ''

if self.option == "auth-only" and not request.user.is_authenticated():
return ''

static_url = getattr(settings, 'STATIC_URL', '')
url = u'<link rel="stylesheet" href="{0}css/coop_bar.css?v={1}" type="text/css" />'.format(
static_url, get_version()
Expand All @@ -41,5 +53,7 @@ def render(self, context):

@register.tag
def coop_bar_headers(parser, token):
return CoopBarHeaderNode()
args = token.split_contents()
option = args[1] if len(args) > 1 else ''
return CoopBarHeaderNode(option)

0 comments on commit 11b0b74

Please sign in to comment.