11import re
2+
23from django import template
34
4- from ..exceptions import SetComponentNameError , ComponentNameError , ComponentArgsError , ComponentNotDefined
5+ from ..exceptions import (
6+ ComponentArgsError ,
7+ ComponentNameError ,
8+ ComponentNotDefined ,
9+ SetComponentNameError ,
10+ )
511
612# allow line breaks inside tags
713template .base .tag_re = re .compile (template .base .tag_re .pattern , re .DOTALL )
@@ -41,10 +47,11 @@ def render(self, context):
4147@register .tag
4248def component (parser , token ):
4349 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 :]) + ' %}'
4652 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
4855 )
4956
5057 component_name = str (parser .compile_filter (bits [1 ]))
@@ -58,7 +65,9 @@ def component(parser, token):
5865 if name :
5966 kwargs [name ] = parser .compile_filter (value )
6067 else :
61- example = '{% component "' + component_name + '" param1=%s' % bit + ' ... %}'
68+ example = (
69+ '{% component "' + component_name + '" param1=%s' % bit + ' ... %}'
70+ )
6271 raise ComponentArgsError (
6372 'Argument %s must be takes as kwargs:\n %s' % (bit , example )
6473 )
@@ -76,8 +85,8 @@ def render(self, context):
7685 nodelist = context ['components' ][self .component_name ]
7786 except KeyError :
7887 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
8190 )
8291
8392 if self .kwargs is not None :
0 commit comments