Beispiel #1
0
    def validate_models(self):
        import django
        try:
            django_setup = django.setup
        except AttributeError:
            pass
        else:
            django_setup()
        s = io.StringIO()
        try:
            from django.core.management.validation import get_validation_errors
        except ImportError:
            from django.core.management.base import BaseCommand
            cmd = BaseCommand()
            try:
                # since django 1.5
                from django.core.management.base import OutputWrapper
                cmd.stdout = OutputWrapper(sys.stdout)
                cmd.stderr = OutputWrapper(sys.stderr)
            except ImportError:
                cmd.stdout, cmd.stderr = sys.stdout, sys.stderr

            cmd.check()
        else:
            num_errors = get_validation_errors(s, None)
            if num_errors:
                raise RuntimeError(
                    'One or more Django models did not validate:\n{0}'.format(
                        s.getvalue()))
Beispiel #2
0
def make_wsgi_application():
    # validate models
    s = StringIO()
    import django
    from django.core.management.base import BaseCommand
    django.setup()
    cmd = BaseCommand()
    import sys
    cmd.stdout, cmd.stderr = sys.stdout, sys.stderr
    cmd.check()
    translation.activate(settings.LANGUAGE_CODE)
    if django14:
        return get_internal_wsgi_application()
    return WSGIHandler()
Beispiel #3
0
 def validate_models(self):
     s = io.StringIO()
     try:
         from django.core.management.validation import get_validation_errors
     except ImportError:
         import django
         from django.core.management.base import BaseCommand
         django.setup()
         cmd = BaseCommand()
         cmd.stdout, cmd.stderr = sys.stdout, sys.stderr
         cmd.check()
     else:
         num_errors = get_validation_errors(s, None)
         if num_errors:
             raise RuntimeError(
                 'One or more Django models did not validate:\n{0}'.format(
                     s.getvalue()))