File tree Expand file tree Collapse file tree 4 files changed +20
-3
lines changed Expand file tree Collapse file tree 4 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -119,11 +119,14 @@ def prepare_template(self, obj):
119
119
raise SearchFieldError ("This field requires either its instance_name variable to be populated or an explicit template_name in order to load the correct template." )
120
120
121
121
if self .template_name is not None :
122
- template_name = self .template_name
122
+ template_names = self .template_name
123
+
124
+ if not isinstance (template_names , (list , tuple )):
125
+ template_names = [template_names ]
123
126
else :
124
- template_name = 'search/indexes/%s/%s_%s.txt' % (obj ._meta .app_label , obj ._meta .module_name , self .instance_name )
127
+ template_names = [ 'search/indexes/%s/%s_%s.txt' % (obj ._meta .app_label , obj ._meta .module_name , self .instance_name )]
125
128
126
- t = loader .get_template ( template_name )
129
+ t = loader .select_template ( template_names )
127
130
return t .render (Context ({'object' : obj }))
128
131
129
132
def convert (self , value ):
Original file line number Diff line number Diff line change
1
+ BAR!
Original file line number Diff line number Diff line change
1
+ FOO!
Original file line number Diff line number Diff line change @@ -232,6 +232,10 @@ def test_init(self):
232
232
233
233
foo = CharField (use_template = True , template_name = 'foo.txt' )
234
234
self .assertEqual (foo .template_name , 'foo.txt' )
235
+
236
+ # Test the select_template usage.
237
+ foo = CharField (use_template = True , template_name = ['bar.txt' , 'foo.txt' ])
238
+ self .assertEqual (foo .template_name , ['bar.txt' , 'foo.txt' ])
235
239
236
240
def test_prepare (self ):
237
241
mock = MockModel ()
@@ -248,6 +252,14 @@ def test_prepare(self):
248
252
template3 = CharField (use_template = True )
249
253
template3 .instance_name = 'template'
250
254
self .assertEqual (template3 .prepare (mock ), u'Indexed!\n 1' )
255
+
256
+ template4 = CharField (use_template = True , template_name = 'search/indexes/foo.txt' )
257
+ template4 .instance_name = 'template'
258
+ self .assertEqual (template4 .prepare (mock ), u'FOO!\n ' )
259
+
260
+ template5 = CharField (use_template = True , template_name = ['foo.txt' , 'search/indexes/bar.txt' ])
261
+ template5 .instance_name = 'template'
262
+ self .assertEqual (template5 .prepare (mock ), u'BAR!\n ' )
251
263
252
264
253
265
##############################################################################
You can’t perform that action at this time.
0 commit comments