@@ -102,14 +102,20 @@ def do_tags_for_model(parser, token):
102
102
bits = token .contents .split ()
103
103
len_bits = len (bits )
104
104
if len_bits not in (4 , 6 ):
105
- raise TemplateSyntaxError (_ ('%s tag requires either three or five arguments' ) % bits [0 ])
105
+ raise TemplateSyntaxError (
106
+ _ ('%s tag requires either three or five arguments' ) % bits [0 ])
106
107
if bits [2 ] != 'as' :
107
- raise TemplateSyntaxError (_ ("second argument to %s tag must be 'as'" ) % bits [0 ])
108
+ raise TemplateSyntaxError (
109
+ _ ("second argument to %s tag must be 'as'" ) % bits [0 ])
108
110
if len_bits == 6 :
109
111
if bits [4 ] != 'with' :
110
- raise TemplateSyntaxError (_ ("if given, fourth argument to %s tag must be 'with'" ) % bits [0 ])
112
+ raise TemplateSyntaxError (
113
+ _ ("if given, fourth argument to %s tag must be 'with'" ) %
114
+ bits [0 ])
111
115
if bits [5 ] != 'counts' :
112
- raise TemplateSyntaxError (_ ("if given, fifth argument to %s tag must be 'counts'" ) % bits [0 ])
116
+ raise TemplateSyntaxError (
117
+ _ ("if given, fifth argument to %s tag must be 'counts'" ) %
118
+ bits [0 ])
113
119
if len_bits == 4 :
114
120
return TagsForModelNode (bits [1 ], bits [3 ], counts = False )
115
121
else :
@@ -149,50 +155,65 @@ def do_tag_cloud_for_model(parser, token):
149
155
Examples::
150
156
151
157
{% tag_cloud_for_model products.Widget as widget_tags %}
152
- {% tag_cloud_for_model products.Widget as widget_tags with steps=9 min_count=3 distribution=log %}
158
+ {% tag_cloud_for_model products.Widget as widget_tags
159
+ with steps=9 min_count=3 distribution=log %}
153
160
154
161
"""
155
162
bits = token .contents .split ()
156
163
len_bits = len (bits )
157
164
if len_bits != 4 and len_bits not in range (6 , 9 ):
158
- raise TemplateSyntaxError (_ ('%s tag requires either three or between five and seven arguments' ) % bits [0 ])
165
+ raise TemplateSyntaxError (
166
+ _ ('%s tag requires either three or between five '
167
+ 'and seven arguments' ) % bits [0 ])
159
168
if bits [2 ] != 'as' :
160
- raise TemplateSyntaxError (_ ("second argument to %s tag must be 'as'" ) % bits [0 ])
169
+ raise TemplateSyntaxError (
170
+ _ ("second argument to %s tag must be 'as'" ) % bits [0 ])
161
171
kwargs = {}
162
172
if len_bits > 5 :
163
173
if bits [4 ] != 'with' :
164
- raise TemplateSyntaxError (_ ("if given, fourth argument to %s tag must be 'with'" ) % bits [0 ])
174
+ raise TemplateSyntaxError (
175
+ _ ("if given, fourth argument to %s tag must be 'with'" ) %
176
+ bits [0 ])
165
177
for i in range (5 , len_bits ):
166
178
try :
167
179
name , value = bits [i ].split ('=' )
168
180
if name == 'steps' or name == 'min_count' :
169
181
try :
170
182
kwargs [str (name )] = int (value )
171
183
except ValueError :
172
- raise TemplateSyntaxError (_ ("%(tag)s tag's '%(option)s' option was not a valid integer: '%(value)s'" ) % {
173
- 'tag' : bits [0 ],
174
- 'option' : name ,
175
- 'value' : value ,
176
- })
184
+ raise TemplateSyntaxError (
185
+ _ ("%(tag)s tag's '%(option)s' option was not "
186
+ "a valid integer: '%(value)s'" ) % {
187
+ 'tag' : bits [0 ],
188
+ 'option' : name ,
189
+ 'value' : value ,
190
+ })
177
191
elif name == 'distribution' :
178
192
if value in ['linear' , 'log' ]:
179
- kwargs [str (name )] = {'linear' : LINEAR , 'log' : LOGARITHMIC }[value ]
193
+ kwargs [str (name )] = {'linear' : LINEAR ,
194
+ 'log' : LOGARITHMIC }[value ]
180
195
else :
181
- raise TemplateSyntaxError (_ ("%(tag)s tag's '%(option)s' option was not a valid choice: '%(value)s'" ) % {
196
+ raise TemplateSyntaxError (
197
+ _ ("%(tag)s tag's '%(option)s' option was not "
198
+ "a valid choice: '%(value)s'" ) % {
199
+ 'tag' : bits [0 ],
200
+ 'option' : name ,
201
+ 'value' : value ,
202
+ })
203
+ else :
204
+ raise TemplateSyntaxError (
205
+ _ ("%(tag)s tag was given an "
206
+ "invalid option: '%(option)s'" ) % {
182
207
'tag' : bits [0 ],
183
208
'option' : name ,
184
- 'value' : value ,
185
209
})
186
- else :
187
- raise TemplateSyntaxError (_ ("%(tag)s tag was given an invalid option: '%(option)s'" ) % {
210
+ except ValueError :
211
+ raise TemplateSyntaxError (
212
+ _ ("%(tag)s tag was given a badly "
213
+ "formatted option: '%(option)s'" ) % {
188
214
'tag' : bits [0 ],
189
- 'option' : name ,
215
+ 'option' : bits [ i ] ,
190
216
})
191
- except ValueError :
192
- raise TemplateSyntaxError (_ ("%(tag)s tag was given a badly formatted option: '%(option)s'" ) % {
193
- 'tag' : bits [0 ],
194
- 'option' : bits [i ],
195
- })
196
217
return TagCloudForModelNode (bits [1 ], bits [3 ], ** kwargs )
197
218
198
219
@@ -211,9 +232,11 @@ def do_tags_for_object(parser, token):
211
232
"""
212
233
bits = token .contents .split ()
213
234
if len (bits ) != 4 :
214
- raise TemplateSyntaxError (_ ('%s tag requires exactly three arguments' ) % bits [0 ])
235
+ raise TemplateSyntaxError (
236
+ _ ('%s tag requires exactly three arguments' ) % bits [0 ])
215
237
if bits [2 ] != 'as' :
216
- raise TemplateSyntaxError (_ ("second argument to %s tag must be 'as'" ) % bits [0 ])
238
+ raise TemplateSyntaxError (
239
+ _ ("second argument to %s tag must be 'as'" ) % bits [0 ])
217
240
return TagsForObjectNode (bits [1 ], bits [3 ])
218
241
219
242
@@ -237,11 +260,14 @@ def do_tagged_objects(parser, token):
237
260
"""
238
261
bits = token .contents .split ()
239
262
if len (bits ) != 6 :
240
- raise TemplateSyntaxError (_ ('%s tag requires exactly five arguments' ) % bits [0 ])
263
+ raise TemplateSyntaxError (
264
+ _ ('%s tag requires exactly five arguments' ) % bits [0 ])
241
265
if bits [2 ] != 'in' :
242
- raise TemplateSyntaxError (_ ("second argument to %s tag must be 'in'" ) % bits [0 ])
266
+ raise TemplateSyntaxError (
267
+ _ ("second argument to %s tag must be 'in'" ) % bits [0 ])
243
268
if bits [4 ] != 'as' :
244
- raise TemplateSyntaxError (_ ("fourth argument to %s tag must be 'as'" ) % bits [0 ])
269
+ raise TemplateSyntaxError (
270
+ _ ("fourth argument to %s tag must be 'as'" ) % bits [0 ])
245
271
return TaggedObjectsNode (bits [1 ], bits [3 ], bits [5 ])
246
272
247
273
0 commit comments