Ticket #5445: iterables.patch
| File iterables.patch, 3.4 kB (added by leosoto <leo.soto@gmail.com>, 1 year ago) |
|---|
-
a/django/core/management/validation.py
old new 1 1 import sys 2 import types 2 3 from django.core.management.color import color_style 3 4 4 5 class ModelErrorCollection: … … 11 12 self.errors.append((context, error)) 12 13 self.outfile.write(self.style.ERROR("%s: %s\n" % (context, error))) 13 14 15 def _is_iterable(x): 16 try: 17 iter(x) 18 except TypeError: 19 return False 20 else: 21 return True 14 22 def get_validation_errors(outfile, app=None): 15 23 """ 16 24 Validates all models that are part of the specified app. If no app name is provided, … … 51 59 if f.prepopulate_from is not None and type(f.prepopulate_from) not in (list, tuple): 52 60 e.add(opts, '"%s": prepopulate_from should be a list or tuple.' % f.name) 53 61 if f.choices: 54 if not hasattr(f.choices, '__iter__'): 62 if isinstance(f.choices, types.StringTypes) or \ 63 not _is_iterable(f.choices): 55 64 e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name) 56 65 else: 57 66 for c in f.choices: -
a/django/test/client.py
old new 1 1 import datetime 2 2 import sys 3 import types 3 4 from cStringIO import StringIO 4 5 from urlparse import urlparse 5 6 from django.conf import settings … … 74 75 '', 75 76 value.read() 76 77 ]) 77 elif hasattr(value, '__iter__'): 78 for item in value: 78 else: 79 try: 80 iter(value) 81 except: 82 iterable = False 83 else: 84 iterable = True 85 if iterable and not isinstance(value, types.StringTypes): 86 for item in value: 87 lines.extend([ 88 '--' + boundary, 89 'Content-Disposition: form-data; name="%s"' % to_str(key), 90 '', 91 to_str(item) 92 ]) 93 else: 79 94 lines.extend([ 80 95 '--' + boundary, 81 96 'Content-Disposition: form-data; name="%s"' % to_str(key), 82 97 '', 83 to_str( item)98 to_str(value) 84 99 ]) 85 else:86 lines.extend([87 '--' + boundary,88 'Content-Disposition: form-data; name="%s"' % to_str(key),89 '',90 to_str(value)91 ])92 100 93 101 lines.extend([ 94 102 '--' + boundary + '--',
