1
1
import re
2
+
2
3
from django import template
3
4
4
- from ..exceptions import SetComponentNameError , ComponentNameError , ComponentArgsError , ComponentNotDefined
5
+ from ..exceptions import (
6
+ ComponentArgsError ,
7
+ ComponentNameError ,
8
+ ComponentNotDefined ,
9
+ SetComponentNameError ,
10
+ )
5
11
6
12
# allow line breaks inside tags
7
13
template .base .tag_re = re .compile (template .base .tag_re .pattern , re .DOTALL )
@@ -41,10 +47,11 @@ def render(self, context):
41
47
@register .tag
42
48
def component (parser , token ):
43
49
bits = token .split_contents ()
44
- if len (bits ) < 2 or '=' in bits [1 ]:
45
- example = '{% component \ " name\ " ' + ' ' .join (bits [1 :]) + ' %}'
50
+ if len (bits ) < 2 or "=" in bits [1 ]:
51
+ example = '{% component "name" ' + ' ' .join (bits [1 :]) + ' %}'
46
52
raise ComponentNameError (
47
- 'Component takes at least one required argument (name of component):\n %s' % example
53
+ 'Component takes at least one required argument (name of component):\n %s'
54
+ % example
48
55
)
49
56
50
57
component_name = str (parser .compile_filter (bits [1 ]))
@@ -58,7 +65,9 @@ def component(parser, token):
58
65
if name :
59
66
kwargs [name ] = parser .compile_filter (value )
60
67
else :
61
- example = '{% component "' + component_name + '" param1=%s' % bit + ' ... %}'
68
+ example = (
69
+ '{% component "' + component_name + '" param1=%s' % bit + ' ... %}'
70
+ )
62
71
raise ComponentArgsError (
63
72
'Argument %s must be takes as kwargs:\n %s' % (bit , example )
64
73
)
@@ -76,8 +85,8 @@ def render(self, context):
76
85
nodelist = context ['components' ][self .component_name ]
77
86
except KeyError :
78
87
raise ComponentNotDefined (
79
- 'The component \' %s\' has not been previously defined. Check that the component is named correctly. '
80
- % self .component_name
88
+ 'The component \' %s\' has not been previously defined. '
89
+ 'Check that the component is named correctly.' % self .component_name
81
90
)
82
91
83
92
if self .kwargs is not None :
0 commit comments