Ticket #1332: management.py+get_validation_errors+core_modules_validation_on_install.patch
File management.py+get_validation_errors+core_modules_validation_on_install.patch, 3.0 KB (added by , 19 years ago) |
---|
-
django_src/django/core/meta/__init__.py
117 117 _installed_modules_cache.append(mod) 118 118 return _installed_modules_cache 119 119 120 _core_model_modules = [] 121 def get_core_model_modules(): 122 " Returns a list of the core models modules." 123 124 from django.models import __all__ 125 for cm in __all__: 126 _core_model_modules.append(__import__('django.models.%s' % cm, '', '',[''])) 127 return _core_model_modules 128 129 120 130 class LazyDate: 121 131 """ 122 132 Use in limit_choices_to to compare the field to dates calculated at run time -
django_src/django/core/management.py
397 397 def install(mod): 398 398 "Executes the equivalent of 'get_sql_all' in the current database." 399 399 from django.core import db 400 from django.core.meta import get_core_model_modules 400 401 from cStringIO import StringIO 401 402 mod_name = mod.__name__[mod.__name__.rindex('.')+1:] 402 403 403 404 # First, try validating the models. 404 s = StringIO() 405 num_errors = get_validation_errors(s) 406 if num_errors: 407 sys.stderr.write("Error: %s couldn't be installed, because there were errors in your model:\n" % mod_name) 408 s.seek(0) 409 sys.stderr.write(s.read()) 410 sys.exit(1) 411 sql_list = get_sql_all(mod) 405 module_list = [] 406 module_list.extend(get_core_model_modules()) 407 module_list.append(mod) 408 for m in module_list: 409 mn = m.__name__[m.__name__.rindex('.')+1:] 410 s = StringIO() 411 num_errors = get_validation_errors(s, selected_mod=m) 412 if num_errors: 413 sys.stderr.write("Error: %s couldn't be installed, because there were errors in your model:\n" % mn) 414 s.seek(0) 415 sys.stderr.write(s.read()) 416 sys.exit(1) 417 sql_list = get_sql_all(m) 412 418 413 419 try: 414 420 cursor = db.db.cursor() … … 646 652 self.errors.append((opts, error)) 647 653 self.outfile.write("%s.%s: %s\n" % (opts.app_label, opts.module_name, error)) 648 654 649 def get_validation_errors(outfile): 650 "Validates all installed models. Writes errors, if any, to outfile. Returns number of errors." 655 def get_validation_errors(outfile, selected_mod=None): 656 "Validates all installed models or models from 'selected_mod'.Writes errors, if any, to outfile.Returns number of errors." 657 651 658 import django.models 652 659 from django.core import meta 653 660 e = ModelErrorCollection(outfile) 654 module_list = meta.get_installed_model_modules() 661 if not selected_mod: 662 module_list = meta.get_installed_model_modules() 663 else: 664 module_list = selected_mod, 655 665 for module in module_list: 656 666 for mod in module._MODELS: 657 667 opts = mod._meta