Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

unicode: Fixed one of the changes in [5320] in a slightly different w…

…ay. This

should be backwards compatible with trunk, so it's one less things people need
to change.


git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5322 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 19d71a21dfca4bec5a716162355107247530cc10 1 parent 9c44751
Malcolm Tredinnick authored
2  django/db/models/options.py
@@ -215,7 +215,7 @@ def __init__(self, fields=None, js=None, list_display=None, list_display_links=N
215 215
         save_on_top=False, list_select_related=False, manager=None, list_per_page=100):
216 216
         self.fields = fields
217 217
         self.js = js or []
218  
-        self.list_display = list_display or ['__unicode__']
  218
+        self.list_display = list_display or ['__str__']
219 219
         self.list_display_links = list_display_links or []
220 220
         self.list_filter = list_filter or []
221 221
         self.date_hierarchy = date_hierarchy
4  django/utils/encoding.py
@@ -44,7 +44,9 @@ def smart_str(s, encoding='utf-8', strings_only=False, errors='strict'):
44 44
     """
45 45
     if strings_only and isinstance(s, (types.NoneType, int)):
46 46
         return s
47  
-    if not isinstance(s, basestring):
  47
+    if isinstance(s, Promise):
  48
+        return unicode(s).encode(encoding, errors)
  49
+    elif not isinstance(s, basestring):
48 50
         try:
49 51
             return str(s)
50 52
         except UnicodeEncodeError:
57  tests/regressiontests/invalid_admin_options/models.py
@@ -123,9 +123,6 @@ class ListFilterBadOne(models.Model):
123 123
     class Admin:
124 124
         list_filter = 'first_name'     
125 125
 
126  
-    def __unicode__(self):
127  
-        return self.first_name
128  
-
129 126
 model_errors += """invalid_admin_options.listfilterbadone: "admin.list_filter", if given, must be set to a list or tuple.
130 127
 """
131 128
 
@@ -143,9 +140,6 @@ def full_name(self):
143 140
     class Admin:
144 141
         list_filter = ['first_name','last_name','full_name']
145 142
 
146  
-    def __unicode__(self):
147  
-        return self.first_name
148  
-
149 143
 model_errors += """invalid_admin_options.listfilterbadtwo: "admin.list_filter" refers to 'last_name', which isn't a field.
150 144
 invalid_admin_options.listfilterbadtwo: "admin.list_filter" refers to 'full_name', which isn't a field.
151 145
 """
@@ -157,10 +151,7 @@ class DateHierarchyBadOne(models.Model):
157 151
     
158 152
     class Admin:
159 153
         date_hierarchy = 'first_name'
160  
-
161  
-    def __unicode__(self):
162  
-        return self.first_name
163  
-
  154
+        
164 155
 # TODO: Date Hierarchy needs to check if field is a date/datetime field.
165 156
 #model_errors += """invalid_admin_options.datehierarchybadone: "admin.date_hierarchy" refers to 'first_name', which isn't a date field or datetime field.
166 157
 #"""
@@ -173,9 +164,6 @@ class DateHierarchyBadTwo(models.Model):
173 164
     class Admin:
174 165
         date_hierarchy = 'nonexistent'          
175 166
 
176  
-    def __unicode__(self):
177  
-        return self.first_name
178  
-
179 167
 model_errors += """invalid_admin_options.datehierarchybadtwo: "admin.date_hierarchy" refers to 'nonexistent', which isn't a field.
180 168
 """
181 169
 
@@ -186,9 +174,6 @@ class DateHierarchyGood(models.Model):
186 174
     
187 175
     class Admin:
188 176
         date_hierarchy = 'birth_day' 
189  
-
190  
-    def __unicode__(self):
191  
-        return self.first_name
192 177
       
193 178
 class SearchFieldsBadOne(models.Model):
194 179
     "Test search_fields, must be a list or tuple."
@@ -197,9 +182,6 @@ class SearchFieldsBadOne(models.Model):
197 182
     class Admin:
198 183
         search_fields = ('nonexistent')         
199 184
 
200  
-    def __unicode__(self):
201  
-        return self.first_name
202  
-
203 185
 # TODO: Add search_fields validation
204 186
 #model_errors += """invalid_admin_options.seacrhfieldsbadone: "admin.search_fields", if given, must be set to a list or tuple.
205 187
 #"""
@@ -215,9 +197,6 @@ def _last_name(self):
215 197
     class Admin:
216 198
         search_fields = ['first_name','last_name']         
217 199
 
218  
-    def __unicode__(self):
219  
-        return self.first_name
220  
-
221 200
 # TODO: Add search_fields validation
222 201
 #model_errors += """invalid_admin_options.seacrhfieldsbadone: "admin.search_fields" refers to 'last_name', which isn't a field.
223 202
 #"""
@@ -230,8 +209,6 @@ class SearchFieldsGood(models.Model):
230 209
     class Admin:
231 210
         search_fields = ['first_name','last_name']
232 211
 
233  
-    def __unicode__(self):
234  
-        return self.first_name
235 212
 
236 213
 class JsBadOne(models.Model):
237 214
     "Test js, must be a list or tuple"
@@ -239,9 +216,6 @@ class JsBadOne(models.Model):
239 216
     
240 217
     class Admin:
241 218
         js = 'test.js'
242  
-
243  
-    def __unicode__(self):
244  
-        return self.name
245 219
         
246 220
 # TODO: Add a js validator
247 221
 #model_errors += """invalid_admin_options.jsbadone: "admin.js", if given, must be set to a list or tuple.
@@ -254,9 +228,6 @@ class SaveAsBad(models.Model):
254 228
     class Admin:
255 229
         save_as = 'not True or False'
256 230
 
257  
-    def __unicode__(self):
258  
-        return self.name
259  
-
260 231
 # TODO: Add a save_as validator.       
261 232
 #model_errors += """invalid_admin_options.saveasbad: "admin.save_as", if given, must be set to True or False.
262 233
 #"""
@@ -268,9 +239,6 @@ class SaveOnTopBad(models.Model):
268 239
     class Admin:
269 240
         save_on_top = 'not True or False'
270 241
 
271  
-    def __unicode__(self):
272  
-        return self.name
273  
-
274 242
 # TODO: Add a save_on_top validator.       
275 243
 #model_errors += """invalid_admin_options.saveontopbad: "admin.save_on_top", if given, must be set to True or False.
276 244
 #"""
@@ -282,9 +250,6 @@ class ListSelectRelatedBad(models.Model):
282 250
     class Admin:
283 251
         list_select_related = 'not True or False'
284 252
 
285  
-    def __unicode__(self):
286  
-        return self.name
287  
-
288 253
 # TODO: Add a list_select_related validator.       
289 254
 #model_errors += """invalid_admin_options.listselectrelatebad: "admin.list_select_related", if given, must be set to True or False.
290 255
 #"""
@@ -296,9 +261,6 @@ class ListPerPageBad(models.Model):
296 261
     class Admin:
297 262
         list_per_page = 89.3
298 263
 
299  
-    def __unicode__(self):
300  
-        return self.name
301  
-
302 264
 # TODO: Add a list_per_page validator.       
303 265
 #model_errors += """invalid_admin_options.listperpagebad: "admin.list_per_page", if given, must be a positive integer.
304 266
 #"""
@@ -311,9 +273,6 @@ class FieldsBadOne(models.Model):
311 273
     class Admin:
312 274
         fields = 'not a tuple'
313 275
 
314  
-    def __unicode__(self):
315  
-        return self.first_name
316  
-
317 276
 # TODO: Add a fields validator.       
318 277
 #model_errors += """invalid_admin_options.fieldsbadone: "admin.fields", if given, must be a tuple.
319 278
 #"""
@@ -325,9 +284,6 @@ class FieldsBadTwo(models.Model):
325 284
     
326 285
     class Admin:
327 286
         fields = ('Name', {'description': 'this fieldset needs fields'})
328  
-
329  
-    def __unicode__(self):
330  
-        return self.first_name
331 287
         
332 288
 # TODO: Add a fields validator.       
333 289
 #model_errors += """invalid_admin_options.fieldsbadtwo: "admin.fields" each fieldset must include a 'fields' dict.
@@ -341,9 +297,6 @@ class FieldsBadThree(models.Model):
341 297
     class Admin:
342 298
         fields = ('Name', {'fields': ('first_name','last_name'),'badoption': 'verybadoption'})
343 299
 
344  
-    def __unicode__(self):
345  
-        return self.first_name
346  
-
347 300
 # TODO: Add a fields validator.       
348 301
 #model_errors += """invalid_admin_options.fieldsbadthree: "admin.fields" fieldset options must be either 'classes' or 'description'.
349 302
 #"""
@@ -359,9 +312,6 @@ class Admin:
359 312
                   ('Name', {'fields': ('first_name','last_name'),'classes': 'collapse'}),
360 313
                   (None, {'fields': ('birth_day',),'description': 'enter your b-day'})
361 314
                   )
362  
-
363  
-    def __unicode__(self):
364  
-        return self.first_name
365 315
                   
366 316
 class OrderingBad(models.Model):
367 317
     "Test ordering, must be a field."
@@ -371,9 +321,6 @@ class OrderingBad(models.Model):
371 321
     class Admin:
372 322
         ordering = 'nonexistent'
373 323
 
374  
-    def __unicode__(self):
375  
-        return self.first_name
376  
-
377 324
 # TODO: Add a ordering validator.       
378 325
 #model_errors += """invalid_admin_options.orderingbad: "admin.ordering" refers to 'nonexistent', which isn't a field.
379 326
 #"""
@@ -387,4 +334,4 @@ def __unicode__(self):
387 334
 #        manager = 'nonexistent'
388 335
 #       
389 336
 #model_errors += """invalid_admin_options.managerbad: "admin.manager" refers to 'nonexistent', which isn't a Manager().
390  
-#"""
  337
+#"""

0 notes on commit 19d71a2

Please sign in to comment.
Something went wrong with that request. Please try again.