Ticket #17336: merge-alex-gsoc.patch

File merge-alex-gsoc.patch, 4.4 KB (added by jonash, 3 years ago)
  • django/db/backends/creation.py

    commit 4f8356075d59ea4904b38d3e99f2806fb07e03c2
    Author: Jonas Haag <jonas@lophus.org>
    Date:   Wed Sep 28 21:47:11 2011 +0200
    
        Merge Alex Gaynor's GSoC branch
    
    diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
    index ce1da6d..a0089ca 100644
    a b import sys 
    22import time
    33
    44from django.conf import settings
     5from django.utils.datastructures import DictWrapper
    56
    67# The prefix to put on the default database name when creating
    78# the test database.
    class BaseDatabaseCreation(object): 
    2627        """
    2728        return '%x' % (abs(hash(args)) % 4294967296L)  # 2**32
    2829
     30    def db_type(self, field):
     31        return self._db_type(field, field.get_internal_type())
     32
     33    def related_db_type(self, field):
     34        return self._db_type(field, field.get_related_internal_type())
     35
     36    def _db_type(self, field, internal_type):
     37        data = DictWrapper(field.__dict__, self.connection.ops.quote_name, "qn_")
     38        try:
     39            return self.connection.creation.data_types[internal_type] % data
     40        except KeyError:
     41            return None
     42
    2943    def sql_create_model(self, model, style, known_models=set()):
    3044        """
    3145        Returns the SQL required to create a single model, as a tuple of:
  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    index 93aaf99..472979a 100644
    a b class DatabaseWrapper(BaseDatabaseWrapper): 
    366366
    367367    def _rollback(self):
    368368        try:
    369             BaseDatabaseWrapper._rollback(self)
     369            super(DatabaseWrapper, self)._rollback()
    370370        except Database.NotSupportedError:
    371371            pass
    372372
  • django/db/backends/sqlite3/base.py

    diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
    index a610606..92875cb 100644
    a b class DatabaseWrapper(BaseDatabaseWrapper): 
    289289        # database. To prevent accidental data loss, ignore close requests on
    290290        # an in-memory db.
    291291        if self.settings_dict['NAME'] != ":memory:":
    292             BaseDatabaseWrapper.close(self)
     292            super(DatabaseWrapper, self).close()
    293293
    294294FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s')
    295295
  • django/db/models/fields/__init__.py

    diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
    index 04b13aa..bdb8233 100644
    a b from django.db.models.query_utils import QueryWrapper 
    1010from django.conf import settings
    1111from django import forms
    1212from django.core import exceptions, validators
    13 from django.utils.datastructures import DictWrapper
    1413from django.utils.dateparse import parse_date, parse_datetime, parse_time
    1514from django.utils.functional import curry
    1615from django.utils.text import capfirst
    class Field(object): 
    221220        # mapped to one of the built-in Django field types. In this case, you
    222221        # can implement db_type() instead of get_internal_type() to specify
    223222        # exactly which wacky database column type you want to use.
    224         data = DictWrapper(self.__dict__, connection.ops.quote_name, "qn_")
    225         try:
    226             return (connection.creation.data_types[self.get_internal_type()]
    227                     % data)
    228         except KeyError:
    229             return None
     223        return connection.creation.db_type(self)
     224
     225    def related_db_type(self, connection):
     226        # This is the db_type used by a ForeignKey.
     227        return connection.creation.related_db_type(self)
    230228
    231229    @property
    232230    def unique(self):
    class Field(object): 
    261259    def get_internal_type(self):
    262260        return self.__class__.__name__
    263261
     262    def get_related_internal_type(self):
     263        return self.get_internal_type()
     264
    264265    def pre_save(self, model_instance, add):
    265266        """
    266267        Returns field's value just before saving.
    class AutoField(Field): 
    518519    def get_internal_type(self):
    519520        return "AutoField"
    520521
     522    def get_related_internal_type(self):
     523        return "RelatedAutoField"
     524
     525    def related_db_type(self, connection):
     526        db_type = super(AutoField, self).related_db_type(connection=connection)
     527        if db_type is None:
     528            return IntegerField().db_type(connection=connection)
     529        return db_type
     530
    521531    def to_python(self, value):
    522532        if value is None:
    523533            return value
Back to Top