ifsecure

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class IfSecureNode(template.Node):
    def __init__(self, nodelist_true, nodelist_false):
        self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false

    def __repr__(self):
        return ""

    def render(self, context):
	request = context.get('request', None)
	if request is None:
            return self.nodelist_false.render(context)
	if request.is_secure():
            return self.nodelist_true.render(context)
        return self.nodelist_false.render(context)

def do_ifsecure(parser, token):
    bits = list(token.split_contents())
    end_tag = 'end' + bits[0]
    nodelist_true = parser.parse(('else', end_tag))
    token = parser.next_token()
    if token.contents == 'else':
        nodelist_false = parser.parse((end_tag,))
        parser.delete_first_token()
    else:
        nodelist_false = template.NodeList()
    return IfSecureNode(nodelist_true, nodelist_false)

@register.tag
def ifsecure(parser, token):
    return do_ifsecure(parser, token)

register.tag('ifsecure', ifsecure)

More like this

  1. Load static media from secure (SSL) static server (Context Processor) by ianreardon 3 years, 7 months ago
  2. Enable AWS ELB with SSL Termination by zvikico 1 year, 10 months ago
  3. Template filter implementing the Trac wiki markup language by simon 4 years, 8 months ago
  4. Sorl Thumbnail + Amazon S3 by skoczen 3 years, 11 months ago
  5. Git media cache busting tag by adamlofts 3 years, 6 months ago

Comments

(Forgotten your password?)