From f53559f06630aee2118c28962ba2ba2b7cd04126 Mon Sep 17 00:00:00 2001 From: Tzach Yarimi Date: Sun, 21 Sep 2014 11:09:11 +0300 Subject: [PATCH 1/7] creating wsgi app using the recommended way to fix support for django 1.7 --- djangoappengine/main/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/djangoappengine/main/__init__.py b/djangoappengine/main/__init__.py index 9bceeb2..77257b9 100644 --- a/djangoappengine/main/__init__.py +++ b/djangoappengine/main/__init__.py @@ -58,7 +58,7 @@ def validate_models(): if not on_production_server: validate_models() -from django.core.handlers.wsgi import WSGIHandler +from django.core.wsgi import get_wsgi_application from google.appengine.ext.webapp.util import run_wsgi_app from django.conf import settings @@ -72,7 +72,7 @@ def log_traceback(*args, **kwargs): # Create a Django application for WSGI. -application = WSGIHandler() +application = get_wsgi_application() # Add the staticfiles handler if necessary. if settings.DEBUG and 'django.contrib.staticfiles' in settings.INSTALLED_APPS: From 76e0a78cc6a657581756e64ec2587db133223568 Mon Sep 17 00:00:00 2001 From: Tzach Yarimi Date: Sun, 21 Sep 2014 11:25:22 +0300 Subject: [PATCH 2/7] make model validations work with django the 1.7 new check system --- djangoappengine/main/__init__.py | 39 ++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/djangoappengine/main/__init__.py b/djangoappengine/main/__init__.py index 77257b9..4b0e7f4 100644 --- a/djangoappengine/main/__init__.py +++ b/djangoappengine/main/__init__.py @@ -34,21 +34,36 @@ def validate_models(): model valdidation here to ensure it is run every time the code changes. """ + import logging - from django.core.management.validation import get_validation_errors + logging.info("Validating models...") + error_text = None + try: - from cStringIO import StringIO + from django.core.management.validation import get_validation_errors + try: + from cStringIO import StringIO + except ImportError: + from StringIO import StringIO + + s = StringIO() + num_errors = get_validation_errors(s, None) + + if num_errors: + s.seek(0) + error_text = s.read() + except ImportError: - from StringIO import StringIO - - logging.info("Validating models...") - - s = StringIO() - num_errors = get_validation_errors(s, None) - - if num_errors: - s.seek(0) - error_text = s.read() + import django + from django.core.checks.model_checks import check_all_models + + django.setup() + errors = check_all_models() + + if errors: + error_text = "\n".join(errors) + + if error_text: logging.critical("One or more models did not validate:\n%s" % error_text) else: From 3b26b21f185649d47a015b783012bf8a8db3bd72 Mon Sep 17 00:00:00 2001 From: Tzach Yarimi Date: Wed, 25 Feb 2015 13:57:29 +0200 Subject: [PATCH 3/7] adding support for email attachments with content-id --- djangoappengine/mail.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/djangoappengine/mail.py b/djangoappengine/mail.py index 044bf6f..0f836e0 100644 --- a/djangoappengine/mail.py +++ b/djangoappengine/mail.py @@ -45,8 +45,10 @@ def _copy_message(self, message): attachments = [] for attachment in message.attachments: if isinstance(attachment, MIMEBase): - attachments.append((attachment.get_filename(), - attachment.get_payload(decode=True))) + attachments.append(aeemail.Attachment( + attachment.get_filename(), + attachment.get_payload(decode=True), + content_id = attachment.get('content-id'))) else: attachments.append((attachment[0], attachment[1])) gmsg.attachments = attachments From e17cbb989be6c6d270361434623105f103f1b8ea Mon Sep 17 00:00:00 2001 From: Tzach Yarimi Date: Sun, 19 Apr 2015 15:44:28 +0300 Subject: [PATCH 4/7] Applying devappserver2 changes from devappengine2 branch --- djangoappengine/boot.py | 28 +++--- djangoappengine/db/base.py | 4 +- djangoappengine/db/stubs.py | 48 +++++++--- djangoappengine/main/__init__.py | 17 ++-- djangoappengine/management/commands/deploy.py | 2 - .../management/commands/runserver.py | 89 +++++++++++++------ .../management/commands/testserver.py | 16 ++-- djangoappengine/settings_base.py | 10 ++- djangoappengine/utils.py | 13 +-- 9 files changed, 148 insertions(+), 79 deletions(-) diff --git a/djangoappengine/boot.py b/djangoappengine/boot.py index 121cd1d..b7c5a6a 100644 --- a/djangoappengine/boot.py +++ b/djangoappengine/boot.py @@ -22,9 +22,12 @@ def find_project_dir(): env_ext['DJANGO_SETTINGS_MODULE'] = 'settings' -def setup_env(): +def setup_env(dev_appserver_version=1): """Configures GAE environment for command-line apps.""" + if dev_appserver_version not in (1, 2): + raise Exception('Invalid dev_appserver_version setting, expected 1 or 2, got %s' % dev_appserver_version) + # Try to import the appengine code from the system path. try: from google.appengine.api import apiproxy_stub_map @@ -74,10 +77,16 @@ def setup_env(): from dev_appserver import fix_sys_path except ImportError: from old_dev_appserver import fix_sys_path + + if dev_appserver_version == 2: + # emulate dev_appserver._run_file in devappserver2 + from dev_appserver import _PATHS + sys.path = _PATHS._script_to_paths['dev_appserver.py'] + sys.path fix_sys_path() - setup_project() - from .utils import have_appserver + setup_project(dev_appserver_version) + + from djangoappengine.utils import have_appserver if have_appserver: # App Engine's threading.local is broken. setup_threading() @@ -125,7 +134,7 @@ def setup_logging(): # Enable logging. level = logging.DEBUG - from .utils import have_appserver + from djangoappengine.utils import have_appserver if have_appserver: # We can't import settings at this point when running a normal # manage.py command because this module gets imported from @@ -135,9 +144,8 @@ def setup_logging(): level = logging.INFO logging.getLogger().setLevel(level) - -def setup_project(): - from .utils import have_appserver, on_production_server +def setup_project(dev_appserver_version): + from djangoappengine.utils import have_appserver, on_production_server if have_appserver: # This fixes a pwd import bug for os.path.expanduser(). env_ext['HOME'] = PROJECT_DIR @@ -145,11 +153,11 @@ def setup_project(): # The dev_appserver creates a sandbox which restricts access to # certain modules and builtins in order to emulate the production # environment. Here we get the subprocess module back into the - # dev_appserver sandbox.This module is just too important for + # dev_appserver sandbox. This module is just too important for # development. Also we add the compiler/parser module back and # enable https connections (seem to be broken on Windows because # the _ssl module is disallowed). - if not have_appserver: + if not have_appserver and dev_appserver_version == 1: try: from google.appengine.tools import dev_appserver except ImportError: @@ -178,7 +186,7 @@ def setup_project(): logging.warn("Could not patch modules whitelist. the compiler " "and parser modules will not work and SSL support " "is disabled.") - elif not on_production_server: + elif not on_production_server and dev_appserver_version == 1: try: try: from google.appengine.tools import dev_appserver diff --git a/djangoappengine/db/base.py b/djangoappengine/db/base.py index 0488d51..1dfb7b9 100644 --- a/djangoappengine/db/base.py +++ b/djangoappengine/db/base.py @@ -158,7 +158,7 @@ def _value_for_db(self, value, field, field_kind, db_type, lookup): value = key_from_path(field.model._meta.db_table, value) except (BadArgumentError, BadValueError,): raise DatabaseError("Only strings and positive integers " - "may be used as keys on GAE.") + "may be used as keys on GAE. Received %r." % value) # Store all strings as unicode, use db.Text for longer content. elif db_type == 'string' or db_type == 'text': @@ -342,7 +342,7 @@ def flush(self): stub_manager.activate_test_stubs(self) else: destroy_datastore(get_datastore_paths(self.settings_dict)) - stub_manager.setup_local_stubs(self) + stub_manager.reset_stubs(self) def delete_all_entities(): diff --git a/djangoappengine/db/stubs.py b/djangoappengine/db/stubs.py index c89b5eb..337e6fc 100644 --- a/djangoappengine/db/stubs.py +++ b/djangoappengine/db/stubs.py @@ -35,32 +35,53 @@ def setup_stubs(self, connection): if self.active_stubs is not None: return if not have_appserver: + self.activate_stubs(connection) + + def activate_stubs(self, connection): + try: + from google.appengine.tools import dev_appserver_main + self.setup_local_stubs(connection) + except ImportError: + self.activate_test_stubs(connection) + + def reset_stubs(self, connection, datastore_path=None): + if self.active_stubs == 'test': + self.deactivate_test_stubs() + self.activate_test_stubs(connection, datastore_path) + + elif self.active_stubs == 'local': self.setup_local_stubs(connection) - def activate_test_stubs(self, connection): + elif self.active_stubs == 'remote': + self.setup_remote_stubs(connection) + + def activate_test_stubs(self, connection, datastore_path=None): if self.active_stubs == 'test': return + if self.testbed is None: + from google.appengine.ext.testbed import Testbed + self.testbed = Testbed() + + self.testbed.activate() + self.pre_test_stubs = self.active_stubs + self.active_stubs = 'test' + + os.environ['APPLICATION_ID'] = 'dev~' + appid os.environ['HTTP_HOST'] = "%s.appspot.com" % appid appserver_opts = connection.settings_dict.get('DEV_APPSERVER_OPTIONS', {}) high_replication = appserver_opts.get('high_replication', False) require_indexes = appserver_opts.get('require_indexes', False) + use_sqlite = appserver_opts.get('use_sqlite', False) - datastore_opts = {'require_indexes': require_indexes} + datastore_opts = {'require_indexes': require_indexes, 'use_sqlite': use_sqlite} if high_replication: from google.appengine.datastore import datastore_stub_util datastore_opts['consistency_policy'] = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1) - if self.testbed is None: - from google.appengine.ext.testbed import Testbed - self.testbed = Testbed() - - self.testbed.activate() - self.pre_test_stubs = self.active_stubs - self.active_stubs = 'test' - self.testbed.init_datastore_v3_stub(root_path=PROJECT_DIR, **datastore_opts) + self.testbed.init_datastore_v3_stub(datastore_file=datastore_path, **datastore_opts) self.testbed.init_memcache_stub() self.testbed.init_taskqueue_stub(auto_task_running=True, root_path=PROJECT_DIR) self.testbed.init_urlfetch_stub() @@ -76,6 +97,7 @@ def deactivate_test_stubs(self): def setup_local_stubs(self, connection): if self.active_stubs == 'local': return + from .base import get_datastore_paths from google.appengine.tools import dev_appserver_main args = dev_appserver_main.DEFAULT_ARGS.copy() @@ -96,8 +118,10 @@ def setup_remote_stubs(self, connection): if self.active_stubs == 'remote': return if not connection.remote_api_path: - from ..utils import appconfig - for handler in appconfig.handlers: + from djangoappengine.utils import appconfig + from google.appengine.api import appinfo + default_module = next(m for m in appconfig.modules if m.module_name == appinfo.DEFAULT_MODULE) + for handler in default_module.handlers: if handler.script in REMOTE_API_SCRIPTS: connection.remote_api_path = handler.url.split('(', 1)[0] break diff --git a/djangoappengine/main/__init__.py b/djangoappengine/main/__init__.py index 4b0e7f4..0b00f8c 100644 --- a/djangoappengine/main/__init__.py +++ b/djangoappengine/main/__init__.py @@ -24,8 +24,16 @@ if k.startswith('django.') or k == 'django']: del sys.modules[k] + +from django.conf import settings +from django.core import signals +from django.core.wsgi import get_wsgi_application +from google.appengine.ext.webapp.util import run_wsgi_app + +from djangoappengine.utils import on_production_server + from djangoappengine.boot import setup_env -setup_env() +setup_env(settings.DEV_APPSERVER_VERSION) def validate_models(): @@ -69,20 +77,13 @@ def validate_models(): else: logging.info("All models validated.") -from djangoappengine.utils import on_production_server if not on_production_server: validate_models() -from django.core.wsgi import get_wsgi_application -from google.appengine.ext.webapp.util import run_wsgi_app -from django.conf import settings - - def log_traceback(*args, **kwargs): import logging logging.exception("Exception in request:") -from django.core import signals signals.got_request_exception.connect(log_traceback) diff --git a/djangoappengine/management/commands/deploy.py b/djangoappengine/management/commands/deploy.py index dcc250e..303502f 100644 --- a/djangoappengine/management/commands/deploy.py +++ b/djangoappengine/management/commands/deploy.py @@ -29,8 +29,6 @@ def run_appcfg(argv): new_args = argv[:] new_args[1] = 'update' - if appconfig.runtime != 'python': - new_args.insert(1, '-R') new_args.append(PROJECT_DIR) syncdb = True if '--nosyncdb' in new_args: diff --git a/djangoappengine/management/commands/runserver.py b/djangoappengine/management/commands/runserver.py index cb60166..b626675 100644 --- a/djangoappengine/management/commands/runserver.py +++ b/djangoappengine/management/commands/runserver.py @@ -2,16 +2,28 @@ from optparse import make_option import sys -from django.db import connections +from django.conf import settings from django.core.management.base import BaseCommand -from django.core.management.commands.runserver import BaseRunserverCommand +from django.core.management.commands.runserver import BaseRunserverCommand, DEFAULT_PORT from django.core.exceptions import ImproperlyConfigured +from django.db import connections -from google.appengine.tools import dev_appserver_main +from djangoappengine.boot import PROJECT_DIR +from djangoappengine.db.base import DatabaseWrapper, get_datastore_paths -from ...boot import PROJECT_DIR -from ...db.base import DatabaseWrapper, get_datastore_paths +if settings.DEV_APPSERVER_VERSION == 1: + from google.appengine.tools import dev_appserver_main +else: + import os + import _python_runtime + sys.argv[0] = os.path.join( + os.path.dirname(_python_runtime.__file__), + "devappserver2.py") + # The following import sets the path for _python_runtime.py from + # sys.argv[0], so we need to hack sys.argv[0] before this import + from google.appengine.tools.devappserver2 import devappserver2 +DEV_APPSERVER_V2_DEFAULT_PORT = "8080" class Command(BaseRunserverCommand): """ @@ -24,6 +36,10 @@ class Command(BaseRunserverCommand): """ option_list = BaseCommand.option_list + ( + make_option( + '--auto_id_policy', + help="Dictate how automatic IDs are assigned by the datastore " \ + "stub. 'sequential' or 'scattered'."), make_option( '--debug', action='store_true', default=False, help="Prints verbose debugging messages to the console while " \ @@ -106,7 +122,10 @@ def create_parser(self, prog_name, subcommand): parse the arguments to this command. """ # Hack __main__ so --help in dev_appserver_main works OK. - sys.modules['__main__'] = dev_appserver_main + if settings.DEV_APPSERVER_VERSION == 1: + sys.modules['__main__'] = dev_appserver_main + else: + sys.modules['__main__'] = devappserver2 return super(Command, self).create_parser(prog_name, subcommand) def run_from_argv(self, argv): @@ -130,9 +149,15 @@ def run(self, *args, **options): args = [] # Set bind ip/port if specified. if self.addr: - args.extend(['--address', self.addr]) + if settings.DEV_APPSERVER_VERSION == 1: + args.extend(['--address', self.addr]) + else: + args.extend(['--host', self.addr]) if self.port: - args.extend(['--port', self.port]) + if settings.DEV_APPSERVER_VERSION == 1: + args.extend(['--port', self.port]) + else: + args.extend(['--port', self.port if self.port != DEFAULT_PORT else DEV_APPSERVER_V2_DEFAULT_PORT]) # If runserver is called using handle(), progname will not be # set. @@ -140,7 +165,6 @@ def run(self, *args, **options): self.progname = 'manage.py' # Add email settings. - from django.conf import settings if not options.get('smtp_host', None) and \ not options.get('enable_sendmail', None): args.extend(['--smtp_host', settings.EMAIL_HOST, @@ -154,32 +178,34 @@ def run(self, *args, **options): for name in connections: connection = connections[name] if isinstance(connection, DatabaseWrapper): - for key, path in get_datastore_paths( - connection.settings_dict).items(): - # XXX/TODO: Remove this when SDK 1.4.3 is released. - if key == 'prospective_search_path': - continue - + for key, path in get_datastore_paths(connection.settings_dict).items(): arg = '--' + key if arg not in args: args.extend([arg, path]) # Get dev_appserver option presets, to be applied below. - preset_options = connection.settings_dict.get( - 'DEV_APPSERVER_OPTIONS', {}) + preset_options = connection.settings_dict.get('DEV_APPSERVER_OPTIONS', {}) break # Process the rest of the options here. - bool_options = [ - 'debug', 'debug_imports', 'clear_datastore', 'require_indexes', - 'high_replication', 'enable_sendmail', 'use_sqlite', - 'allow_skipped_files', 'disable_task_running', ] + if settings.DEV_APPSERVER_VERSION == 1: + bool_options = [ + 'debug', 'debug_imports', 'clear_datastore', 'require_indexes', + 'high_replication', 'enable_sendmail', 'use_sqlite', + 'allow_skipped_files', 'disable_task_running'] + else: + bool_options = [ + 'debug', 'debug_imports', 'clear_datastore', 'require_indexes', + 'enable_sendmail', 'allow_skipped_files', 'disable_task_running'] for opt in bool_options: if options[opt] != False: - args.append('--%s' % opt) + if settings.DEV_APPSERVER_VERSION == 1: + args.append('--%s' % opt) + else: + args.extend(['--%s' % opt, 'yes']) str_options = [ 'datastore_path', 'blobstore_path', 'history_path', 'login_url', 'smtp_host', - 'smtp_port', 'smtp_user', 'smtp_password', ] + 'smtp_port', 'smtp_user', 'smtp_password', 'auto_id_policy'] for opt in str_options: if options.get(opt, None) != None: args.extend(['--%s' % opt, options[opt]]) @@ -189,7 +215,10 @@ def run(self, *args, **options): arg = '--%s' % opt if arg not in args: if value and opt in bool_options: - args.append(arg) + if settings.DEV_APPSERVER_VERSION == 1: + args.append(arg) + else: + args.extend([arg, value]) elif opt in str_options: args.extend([arg, value]) # TODO: Issue warning about bogus option key(s)? @@ -199,4 +228,14 @@ def run(self, *args, **options): logging.getLogger().setLevel(logging.INFO) # Append the current working directory to the arguments. - dev_appserver_main.main([self.progname] + args + [PROJECT_DIR]) + if settings.DEV_APPSERVER_VERSION == 1: + dev_appserver_main.main([self.progname] + args + [PROJECT_DIR]) + else: + from google.appengine.api import apiproxy_stub_map + + # Environment is set in djangoappengine.stubs.setup_local_stubs() + # We need to do this effectively reset the stubs. + apiproxy_stub_map.apiproxy = apiproxy_stub_map.GetDefaultAPIProxy() + + sys.argv = ['/home/user/google_appengine/devappserver2.py'] + args + [PROJECT_DIR] + devappserver2.main() diff --git a/djangoappengine/management/commands/testserver.py b/djangoappengine/management/commands/testserver.py index cc0a8b0..e9787e9 100644 --- a/djangoappengine/management/commands/testserver.py +++ b/djangoappengine/management/commands/testserver.py @@ -1,12 +1,14 @@ from django.core.management.base import BaseCommand +from djangoappengine.management.commands.runserver import Command as RunServerCommand + from google.appengine.api import apiproxy_stub_map from google.appengine.datastore import datastore_stub_util from optparse import make_option class Command(BaseCommand): - option_list = BaseCommand.option_list + ( + option_list = RunServerCommand.option_list + ( make_option('--noinput', action='store_false', dest='interactive', default=True, help='Tells Django to NOT prompt the user for input of any kind.'), make_option('--addrport', action='store', dest='addrport', @@ -23,12 +25,10 @@ class Command(BaseCommand): def handle(self, *fixture_labels, **options): from django.core.management import call_command from django import db - from ...db.base import get_datastore_paths, DatabaseWrapper + from ...db.base import get_datastore_paths, destroy_datastore, DatabaseWrapper from ...db.stubs import stub_manager verbosity = int(options.get('verbosity')) - interactive = options.get('interactive') - addrport = options.get('addrport') db_name = None @@ -38,11 +38,9 @@ def handle(self, *fixture_labels, **options): settings = conn.settings_dict for key, path in get_datastore_paths(settings).items(): settings[key] = "%s-testdb" % path - conn.flush() + destroy_datastore(get_datastore_paths(settings)) - # reset stub manager - stub_manager.active_stubs = None - stub_manager.setup_local_stubs(conn) + stub_manager.reset_stubs(conn, datastore_path=settings['datastore_path']) db_name = name break @@ -63,4 +61,4 @@ def handle(self, *fixture_labels, **options): # a strange error -- it causes this handle() method to be called # multiple times. shutdown_message = '\nServer stopped.\nNote that the test database, %r, has not been deleted. You can explore it on your own.' % db_name - call_command('runserver', addrport=addrport, shutdown_message=shutdown_message, use_reloader=False, use_ipv6=options['use_ipv6']) + call_command('runserver', shutdown_message=shutdown_message, use_reloader=False, **options) diff --git a/djangoappengine/settings_base.py b/djangoappengine/settings_base.py index 2ebd8bf..53e2036 100644 --- a/djangoappengine/settings_base.py +++ b/djangoappengine/settings_base.py @@ -1,9 +1,15 @@ +# Initialize App Engine SDK if necessary. +try: + from dev_appserver_version import DEV_APPSERVER_VERSION +except ImportError: + DEV_APPSERVER_VERSION = 2 + # Initialize App Engine SDK if necessary. try: from google.appengine.api import apiproxy_stub_map except ImportError: - from .boot import setup_env - setup_env() + from djangoappengine.boot import setup_env + setup_env(DEV_APPSERVER_VERSION) from djangoappengine.utils import on_production_server, have_appserver diff --git a/djangoappengine/utils.py b/djangoappengine/utils.py index 5e0ad6c..dbbad3a 100644 --- a/djangoappengine/utils.py +++ b/djangoappengine/utils.py @@ -10,15 +10,10 @@ appid = get_application_id() else: try: - try: - from google.appengine.tools import dev_appserver - except ImportError: - from google.appengine.tools import old_dev_appserver as dev_appserver - - from .boot import PROJECT_DIR - appconfig = dev_appserver.LoadAppConfig(PROJECT_DIR, {}, - default_partition='dev')[0] - appid = appconfig.application.split('~', 1)[-1] + from google.appengine.tools.devappserver2 import application_configuration + from djangoappengine.boot import PROJECT_DIR + appconfig = application_configuration.ApplicationConfiguration([PROJECT_DIR]) + appid = appconfig.app_id.replace('dev~', '') except ImportError, e: raise Exception("Could not get appid. Is your app.yaml file missing? " "Error was: %s" % e) From c6d5612d8fd7b66dee59e95ee8567609f6aa18b4 Mon Sep 17 00:00:00 2001 From: Tzach Yarimi Date: Sun, 17 May 2015 14:04:27 +0300 Subject: [PATCH 5/7] fixing bug where attachment filename is None --- djangoappengine/mail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djangoappengine/mail.py b/djangoappengine/mail.py index 0f836e0..174ac68 100644 --- a/djangoappengine/mail.py +++ b/djangoappengine/mail.py @@ -46,7 +46,7 @@ def _copy_message(self, message): for attachment in message.attachments: if isinstance(attachment, MIMEBase): attachments.append(aeemail.Attachment( - attachment.get_filename(), + attachment.get_filename() or '', attachment.get_payload(decode=True), content_id = attachment.get('content-id'))) else: From 8597e66ad2c1f28154a185c9c343e51dbeb7a46a Mon Sep 17 00:00:00 2001 From: Tzach Yarimi Date: Tue, 4 Aug 2015 14:12:50 +0300 Subject: [PATCH 6/7] allowing loading django from virtualenv --- djangoappengine/main/__init__.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/djangoappengine/main/__init__.py b/djangoappengine/main/__init__.py index 0b00f8c..e492361 100644 --- a/djangoappengine/main/__init__.py +++ b/djangoappengine/main/__init__.py @@ -13,11 +13,6 @@ sys.path.remove(project_dir) sys.path.insert(0, project_dir) -for path in sys.path[:]: - if path != project_dir and os.path.isdir(os.path.join(path, 'django')): - sys.path.remove(path) - break - # Remove the standard version of Django. if 'django' in sys.modules and sys.modules['django'].VERSION < (1, 2): for k in [k for k in sys.modules @@ -46,7 +41,7 @@ def validate_models(): import logging logging.info("Validating models...") error_text = None - + try: from django.core.management.validation import get_validation_errors try: @@ -60,17 +55,17 @@ def validate_models(): if num_errors: s.seek(0) error_text = s.read() - + except ImportError: import django from django.core.checks.model_checks import check_all_models - + django.setup() errors = check_all_models() - + if errors: error_text = "\n".join(errors) - + if error_text: logging.critical("One or more models did not validate:\n%s" % error_text) From 86d5d23898ac18724f4af907b5d4c529f6a4a409 Mon Sep 17 00:00:00 2001 From: Tzach Yarimi Date: Sun, 13 Dec 2015 15:15:46 +0200 Subject: [PATCH 7/7] using importlib instead of django.utils.importlib that was removed in 1.9 --- djangoappengine/db/db_settings.py | 2 +- djangoappengine/deferred/handler.py | 2 +- djangoappengine/mapreduce/handler.py | 2 +- djangoappengine/views.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/djangoappengine/db/db_settings.py b/djangoappengine/db/db_settings.py index 262f7fb..77a4734 100644 --- a/djangoappengine/db/db_settings.py +++ b/djangoappengine/db/db_settings.py @@ -1,5 +1,5 @@ from django.conf import settings -from django.utils.importlib import import_module +from importlib import import_module # TODO: Add autodiscover() and make API more like dbindexer's # register_index. diff --git a/djangoappengine/deferred/handler.py b/djangoappengine/deferred/handler.py index b5a5ef8..62ca17a 100644 --- a/djangoappengine/deferred/handler.py +++ b/djangoappengine/deferred/handler.py @@ -1,7 +1,7 @@ # Initialize Django. from djangoappengine import main -from django.utils.importlib import import_module +from importlib import import_module from django.conf import settings diff --git a/djangoappengine/mapreduce/handler.py b/djangoappengine/mapreduce/handler.py index 99719f5..fa6646e 100644 --- a/djangoappengine/mapreduce/handler.py +++ b/djangoappengine/mapreduce/handler.py @@ -1,6 +1,6 @@ # Initialize Django. from djangoappengine import main -from django.utils.importlib import import_module +from importlib import import_module from django.conf import settings # Load all models.py to ensure signal handling installation or index diff --git a/djangoappengine/views.py b/djangoappengine/views.py index b3071ec..9f0e833 100644 --- a/djangoappengine/views.py +++ b/djangoappengine/views.py @@ -1,6 +1,6 @@ from django.conf import settings from django.http import HttpResponse -from django.utils.importlib import import_module +from importlib import import_module def warmup(request):