From ca33d307dee3cf68cc9cd2ccfae00c7ff23ea890 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 15 Sep 2007 21:57:25 +0000 Subject: queryset-refactor: Merged to [6300] git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6340 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/handlers/base.py | 4 ++-- django/core/mail.py | 6 +++++- django/core/management/base.py | 10 +++++++--- django/core/management/commands/syncdb.py | 14 +++++++------- django/core/management/sql.py | 2 +- django/core/serializers/__init__.py | 6 +++--- django/core/serializers/python.py | 9 +++++---- django/core/validators.py | 17 +++++++++++------ 8 files changed, 41 insertions(+), 27 deletions(-) (limited to 'django/core') diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index 50495b4ff3..13c7f4193f 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -116,7 +116,7 @@ class BaseHandler(object): else: # Get the exception info now, in case another exception is thrown later. exc_info = sys.exc_info() - receivers = dispatcher.send(signal=signals.got_request_exception) + receivers = dispatcher.send(signal=signals.got_request_exception, request=request) # When DEBUG is False, send an error message to the admins. subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path) try: @@ -142,7 +142,7 @@ def fix_location_header(request, response): Code constructing response objects is free to insert relative paths and this function converts them to absolute paths. """ - if 'Location' in response and http.get_host(request): + if 'Location' in response and request.get_host(): response['Location'] = request.build_absolute_uri(response['Location']) return response diff --git a/django/core/mail.py b/django/core/mail.py index ff653400f9..b90752e649 100644 --- a/django/core/mail.py +++ b/django/core/mail.py @@ -50,7 +50,11 @@ def make_msgid(idstring=None): """ timeval = time.time() utcdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(timeval)) - pid = os.getpid() + try: + pid = os.getpid() + except AttributeError: + # Not getpid() in Jython, for example. + pid = 1 randint = random.randrange(100000) if idstring is None: idstring = '' diff --git a/django/core/management/base.py b/django/core/management/base.py index 83b0ed05cd..d883fe23dc 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -206,7 +206,11 @@ def copy_helper(style, app_or_project, name, directory, other_name=''): def _make_writeable(filename): "Makes sure that the file is writeable. Useful if our source is read-only." import stat + if sys.platform.startswith('java'): + # On Jython there is no os.access() + return if not os.access(filename, os.W_OK): - st = os.stat(filename) - new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR - os.chmod(filename, new_permissions) + st = os.stat(filename) + new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR + os.chmod(filename, new_permissions) + diff --git a/django/core/management/commands/syncdb.py b/django/core/management/commands/syncdb.py index c1f360a985..81938c777c 100644 --- a/django/core/management/commands/syncdb.py +++ b/django/core/management/commands/syncdb.py @@ -38,16 +38,16 @@ class Command(NoArgsCommand): cursor = connection.cursor() - # Get a list of all existing database tables, - # so we know what needs to be added. - table_list = table_list() if connection.features.uses_case_insensitive_names: - table_name_converter = str.upper + table_name_converter = lambda x: x.upper() else: table_name_converter = lambda x: x + # Get a list of all existing database tables, so we know what needs to + # be added. + tables = [table_name_converter(name) for name in table_list()] # Get a list of already installed *models* so that references work right. - seen_models = installed_models(table_list) + seen_models = installed_models(tables) created_models = set() pending_references = {} @@ -59,7 +59,7 @@ class Command(NoArgsCommand): # Create the model's database table, if it doesn't already exist. if verbosity >= 2: print "Processing %s.%s model" % (app_name, model._meta.object_name) - if table_name_converter(model._meta.db_table) in table_list: + if table_name_converter(model._meta.db_table) in tables: continue sql, references = sql_model_create(model, self.style, seen_models) seen_models.add(model) @@ -71,7 +71,7 @@ class Command(NoArgsCommand): print "Creating table %s" % model._meta.db_table for statement in sql: cursor.execute(statement) - table_list.append(table_name_converter(model._meta.db_table)) + tables.append(table_name_converter(model._meta.db_table)) # Create the m2m tables. This must be done after all tables have been created # to ensure that all referred tables will exist. diff --git a/django/core/management/sql.py b/django/core/management/sql.py index ed76bc4e35..d7a46f0cd6 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -130,7 +130,7 @@ def sql_delete(app, style): else: table_names = [] if connection.features.uses_case_insensitive_names: - table_name_converter = str.upper + table_name_converter = lambda x: x.upper() else: table_name_converter = lambda x: x diff --git a/django/core/serializers/__init__.py b/django/core/serializers/__init__.py index 049edf7521..1e24e2bd22 100644 --- a/django/core/serializers/__init__.py +++ b/django/core/serializers/__init__.py @@ -3,9 +3,9 @@ Interfaces for serializing Django objects. Usage:: - >>> from django.core import serializers - >>> json = serializers.serialize("json", some_query_set) - >>> objects = list(serializers.deserialize("json", json)) + from django.core import serializers + json = serializers.serialize("json", some_query_set) + objects = list(serializers.deserialize("json", json)) To add your own serializers, use the SERIALIZATION_MODULES setting:: diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index f61a2fa4a2..6fc13d76b5 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -27,13 +27,13 @@ class Serializer(base.Serializer): def end_object(self, obj): self.objects.append({ "model" : smart_unicode(obj._meta), - "pk" : smart_unicode(obj._get_pk_val()), + "pk" : smart_unicode(obj._get_pk_val(), strings_only=True), "fields" : self._current }) self._current = None def handle_field(self, obj, field): - self._current[field.name] = getattr(obj, field.name) + self._current[field.name] = smart_unicode(getattr(obj, field.name), strings_only=True) def handle_fk_field(self, obj, field): related = getattr(obj, field.name) @@ -44,10 +44,11 @@ class Serializer(base.Serializer): else: # Related to remote object via other field related = getattr(related, field.rel.field_name) - self._current[field.name] = related + self._current[field.name] = smart_unicode(related, strings_only=True) def handle_m2m_field(self, obj, field): - self._current[field.name] = [related._get_pk_val() for related in getattr(obj, field.name).iterator()] + self._current[field.name] = [smart_unicode(related._get_pk_val(), strings_only=True) + for related in getattr(obj, field.name).iterator()] def getvalue(self): return self.objects diff --git a/django/core/validators.py b/django/core/validators.py index 7611aef921..874edaefdd 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -405,12 +405,17 @@ class NumberIsInRange(object): class IsAPowerOf(object): """ - >>> v = IsAPowerOf(2) - >>> v(4, None) - >>> v(8, None) - >>> v(16, None) - >>> v(17, None) - django.core.validators.ValidationError: ['This value must be a power of 2.'] + Usage: If you create an instance of the IsPowerOf validator: + v = IsAPowerOf(2) + + The following calls will succeed: + v(4, None) + v(8, None) + v(16, None) + + But this call: + v(17, None) + will raise "django.core.validators.ValidationError: ['This value must be a power of 2.']" """ def __init__(self, power_of): self.power_of = power_of -- cgit v1.3