Django

Code

Show
Ignore:
Timestamp:
08/05/08 12:15:33 (5 months ago)
Author:
jbronn
Message:

gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis

    • Property svnmerge-integrated changed from /django/trunk:1-7978 to /django/trunk:1-8214
  • django/branches/gis/django/db/backends/__init__.py

    r7979 r8215  
    55    # Import copy of _thread_local.py from Python 2.4 
    66    from django.utils._threading_local import local 
     7 
     8from django.db.backends import util 
     9from django.utils import datetime_safe 
    710 
    811class BaseDatabaseWrapper(local): 
     
    3740 
    3841    def make_debug_cursor(self, cursor): 
    39         from django.db.backends import util 
    4042        return util.CursorDebugWrapper(cursor, self) 
    4143 
     
    4345    allows_group_by_ordinal = True 
    4446    inline_fk_references = True 
     47    # True if django.db.backend.utils.typecast_timestamp is used on values 
     48    # returned from dates() calls. 
    4549    needs_datetime_string_cast = True 
    4650    supports_constraints = True 
     
    5054    empty_fetchmany_value = [] 
    5155    update_can_self_select = True 
    52     supports_usecs = True 
    53     time_field_needs_date = False 
    5456    interprets_empty_strings_as_nulls = False 
    55     date_field_supports_time_value = True 
    5657    can_use_chunked_reads = True 
    5758 
     
    264265        from django.utils.encoding import smart_unicode 
    265266        return smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") 
     267 
     268    def value_to_db_date(self, value): 
     269        """ 
     270        Transform a date value to an object compatible with what is expected 
     271        by the backend driver for date columns. 
     272        """ 
     273        if value is None: 
     274            return None 
     275        return datetime_safe.new_date(value).strftime('%Y-%m-%d') 
     276 
     277    def value_to_db_datetime(self, value): 
     278        """ 
     279        Transform a datetime value to an object compatible with what is expected 
     280        by the backend driver for datetime columns. 
     281        """ 
     282        if value is None: 
     283            return None 
     284        return unicode(value) 
     285 
     286    def value_to_db_time(self, value): 
     287        """ 
     288        Transform a datetime value to an object compatible with what is expected 
     289        by the backend driver for time columns. 
     290        """ 
     291        if value is None: 
     292            return None 
     293        return unicode(value) 
     294 
     295    def value_to_db_decimal(self, value, max_digits, decimal_places): 
     296        """ 
     297        Transform a decimal.Decimal value to an object compatible with what is 
     298        expected by the backend driver for decimal (numeric) columns. 
     299        """ 
     300        if value is None: 
     301            return None 
     302        return util.format_number(value, max_digits, decimal_places) 
     303 
     304    def year_lookup_bounds(self, value): 
     305        """ 
     306        Returns a two-elements list with the lower and upper bound to be used 
     307        with a BETWEEN operator to query a field value using a year lookup 
     308 
     309        `value` is an int, containing the looked-up year. 
     310        """ 
     311        first = '%s-01-01 00:00:00' 
     312        second = '%s-12-31 23:59:59.999999' 
     313        return [first % value, second % value] 
     314 
     315    def year_lookup_bounds_for_date_field(self, value): 
     316        """ 
     317        Returns a two-elements list with the lower and upper bound to be used 
     318        with a BETWEEN operator to query a DateField value using a year lookup 
     319 
     320        `value` is an int, containing the looked-up year. 
     321 
     322        By default, it just calls `self.year_lookup_bounds`. Some backends need 
     323        this hook because on their DB date fields can't be compared to values 
     324        which include a time part. 
     325        """ 
     326        return self.year_lookup_bounds(value) 
     327 
  • django/branches/gis/django/db/backends/mysql/base.py

    r7918 r8215  
    6464    empty_fetchmany_value = () 
    6565    update_can_self_select = False 
    66     supports_usecs = False 
    6766 
    6867class DatabaseOperations(BaseDatabaseOperations): 
     
    124123        else: 
    125124            return [] 
     125 
     126    def value_to_db_datetime(self, value): 
     127        # MySQL doesn't support microseconds 
     128        if value is None: 
     129            return None 
     130        return unicode(value.replace(microsecond=0)) 
     131 
     132    def value_to_db_time(self, value): 
     133        # MySQL doesn't support microseconds 
     134        if value is None: 
     135            return None 
     136        return unicode(value.replace(microsecond=0)) 
     137 
     138    def year_lookup_bounds(self, value): 
     139        # Again, no microseconds 
     140        first = '%s-01-01 00:00:00' 
     141        second = '%s-12-31 23:59:59.99' 
     142        return [first % value, second % value] 
    126143 
    127144class DatabaseWrapper(BaseDatabaseWrapper): 
  • django/branches/gis/django/db/backends/oracle/base.py

    r7918 r8215  
    66 
    77import os 
     8import datetime 
     9import time 
    810 
    911from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 
    1012from django.db.backends.oracle import query 
    11 from django.utils.datastructures import SortedDict 
    1213from django.utils.encoding import smart_str, force_unicode 
    1314 
     
    3031    uses_case_insensitive_names = True 
    3132    uses_custom_query_class = True 
    32     time_field_needs_date = True 
    3333    interprets_empty_strings_as_nulls = True 
    34     date_field_supports_time_value = False 
    3534 
    3635class DatabaseOperations(BaseDatabaseOperations): 
     
    181180    def tablespace_sql(self, tablespace, inline=False): 
    182181        return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""), self.quote_name(tablespace)) 
     182 
     183    def value_to_db_time(self, value): 
     184        if value is None: 
     185            return None 
     186        if isinstance(value, basestring): 
     187            return datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6])) 
     188        return datetime.datetime(1900, 1, 1, value.hour, value.minute, 
     189                                 value.second, value.microsecond) 
     190 
     191    def year_lookup_bounds_for_date_field(self, value): 
     192        first = '%s-01-01' 
     193        second = '%s-12-31' 
     194        return [first % value, second % value] 
     195 
     196 
    183197 
    184198class DatabaseWrapper(BaseDatabaseWrapper): 
     
    246260class OracleParam(object): 
    247261    """ 
    248     Wrapper object for formatting parameters for Oracle. If the string  
    249     representation of the value is large enough (greater than 4000 characters)  
     262    Wrapper object for formatting parameters for Oracle. If the string 
     263    representation of the value is large enough (greater than 4000 characters) 
    250264    the input size needs to be set as NCLOB. Alternatively, if the parameter has 
    251     an `input_size` attribute, then the value of the `input_size` attribute will  
     265    an `input_size` attribute, then the value of the `input_size` attribute will 
    252266    be used instead. Otherwise, no input size will be set for the parameter when 
    253267    executing the query. 
     
    283297        else: 
    284298            return tuple([OracleParam(p, self.charset, True) for p in params]) 
    285      
     299 
    286300    def _guess_input_sizes(self, params_list): 
    287301        if isinstance(params_list[0], dict): 
     
    304318        else: 
    305319            return [p.smart_str for p in params] 
    306          
     320 
    307321    def execute(self, query, params=None): 
    308322        if params is None: 
  • django/branches/gis/django/db/backends/oracle/query.py

    r7523 r8215  
    8888            included in the query. 
    8989            """ 
     90 
    9091            # The `do_offset` flag indicates whether we need to construct 
    9192            # the SQL needed to use limit/offset w/Oracle. 
    92             do_offset = with_limits and (self.high_mark or self.low_mark) 
     93            do_offset = with_limits and (self.high_mark is not None 
     94                                         or self.low_mark) 
    9395 
    9496            # If no offsets, just return the result of the base class 
     
    118120            # extra selection SQL. 
    119121            self.extra_select['rn'] = 'ROW_NUMBER() OVER (ORDER BY %s )' % rn_orderby 
    120             sql, params= super(OracleQuery, self).as_sql(with_limits=False, 
     122            sql, params = super(OracleQuery, self).as_sql(with_limits=False, 
    121123                    with_col_aliases=True) 
    122124 
     
    127129            # Place WHERE condition on `rn` for the desired range. 
    128130            result.append('WHERE rn > %d' % self.low_mark) 
    129             if self.high_mark
     131            if self.high_mark is not None
    130132                result.append('AND rn <= %d' % self.high_mark) 
    131133 
     
    149151    _classes[QueryClass] = OracleQuery 
    150152    return OracleQuery 
    151  
  • django/branches/gis/django/db/backends/sqlite3/base.py

    r7979 r8215  
    8585        return sql 
    8686 
     87    def year_lookup_bounds(self, value): 
     88        first = '%s-01-01' 
     89        second = '%s-12-31 23:59:59.999999' 
     90        return [first % value, second % value] 
     91 
     92 
    8793class DatabaseWrapper(BaseDatabaseWrapper): 
    8894    features = DatabaseFeatures() 
     
    160166    except (ValueError, TypeError): 
    161167        return None 
    162     return str(getattr(dt, lookup_type)
     168    return getattr(dt, lookup_type
    163169 
    164170def _sqlite_date_trunc(lookup_type, dt): 
  • django/branches/gis/django/db/backends/util.py

    r7279 r8215  
    11import datetime 
    2 import md5 
    32from time import time 
     3 
     4from django.utils.hashcompat import md5_constructor 
    45 
    56try: 
     
    115116        return name 
    116117 
    117     hash = md5.md5(name).hexdigest()[:4] 
     118    hash = md5_constructor(name).hexdigest()[:4] 
    118119 
    119120    return '%s%s' % (name[:length-4], hash) 
     121 
     122def format_number(value, max_digits, decimal_places): 
     123    """ 
     124    Formats a number into a string with the requisite number of digits and 
     125    decimal places. 
     126    """ 
     127    return u"%.*f" % (decimal_places, value)