# Coverage for /Users/marco/Code/django-rosetta/rosetta/templatetags/rosetta : 81.54%

## 59 statements 48 run 11 missing 0 excluded 1 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | from django import template from django.utils.safestring import mark_safe from django.utils.html import escape import re from django.template import Node import six register = template.Library() rx = re.compile(r'(%(\([^\s\)]*\))?[sd])') def format_message(message): return mark_safe(rx.sub('<code>\\1</code>', escape(message).replace(r'\n', '<br />\n'))) format_message = register.filter(format_message) def lines_count(message): return 1 + sum([len(line) / 50 for line in message.split('\n')]) lines_count = register.filter(lines_count) def mult(a, b): return int(a) * int(b) mult = register.filter(mult) def minus(a, b): try: return int(a) - int(b) except: return 0 minus = register.filter(minus) def gt(a, b): try: return int(a) > int(b) except: return False gt = register.filter(gt) def do_incr(parser, token): args = token.split_contents() 47 if len(args) < 2: raise SyntaxError("'incr' tag requires at least one argument") name = args[1] if not hasattr(parser, '_namedIncrNodes'): parser._namedIncrNodes = {} if not name in parser._namedIncrNodes: parser._namedIncrNodes[name] = IncrNode(0) return parser._namedIncrNodes[name] do_incr = register.tag('increment', do_incr) class IncrNode(template.Node): def __init__(self, init_val=0): self.val = init_val def render(self, context): self.val += 1 return six.text_type(self.val) def is_fuzzy(message): return message and hasattr(message, 'flags') and 'fuzzy' in message.flags is_fuzzy = register.filter(is_fuzzy) class RosettaCsrfTokenPlaceholder(Node): def render(self, context): return mark_safe(u"<!-- csrf token placeholder -->") def rosetta_csrf_token(parser, token): try: from django.template.defaulttags import csrf_token return csrf_token(parser, token) except ImportError: return RosettaCsrfTokenPlaceholder() rosetta_csrf_token = register.tag(rosetta_csrf_token)