Django

Code

Changeset 6026

Show
Ignore:
Timestamp:
08/30/07 07:58:04 (1 year ago)
Author:
jbronn
Message:

gis: fixed deprecated backend references in _get_sql_clause(); quote_name() no longer a GeoQuerySet? attribute; PostGIS db creation now tries to use pg_config to obtain the POSTGIS_SQL_PATH.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/db/backend/__init__.py

    r6018 r6026  
    1414from django.conf import settings 
    1515from django.db import connection 
    16 from django.db.models.query import LOOKUP_SEPARATOR, field_choices, find_field, FieldFound, QUERY_TERMS, get_where_clause 
     16from django.db.models.query import field_choices, find_field, get_where_clause, \ 
     17    FieldFound, LOOKUP_SEPARATOR, QUERY_TERMS 
    1718from django.utils.datastructures import SortedDict 
    18 qn = connection.ops.quote_name 
    1919 
    2020if settings.DATABASE_ENGINE == 'postgresql_psycopg2': 
     
    3131#  counterparts to support constructing SQL for geographic queries. 
    3232# 
    33 # Status: Synced with r5609
     33# Status: Synced with r5982
    3434# 
    3535def parse_lookup(kwarg_items, opts): 
     
    9191 
    9292def lookup_inner(path, lookup_type, value, opts, table, column): 
     93    qn = connection.ops.quote_name 
    9394    joins, where, params = SortedDict(), [], [] 
    9495    current_opts = opts 
     
    247248            # Last query term was a normal field. 
    248249            column = field.column 
     250            db_type = field.db_type() 
    249251 
    250252        # If the field is a geometry field, then the WHERE clause will need to be obtained 
  • django/branches/gis/django/contrib/gis/db/backend/postgis/creation.py

    r6018 r6026  
    77 
    88def create_lang(db_name, verbosity=1): 
    9     "This sets up the pl/pgsql language on the given database." 
     9    "Sets up the pl/pgsql language on the given database." 
    1010 
    1111    # Getting the command-line options for the shell command 
     
    5151created_regex = re.compile(r'^createdb: database creation failed: ERROR:  database ".+" already exists') 
    5252def _create_with_shell(db_name, verbosity=1, autoclobber=False): 
    53     """If no spatial database already exists, then using a cursor will not work.  Thus, a 
    54     `createdb` command will be issued through the shell to bootstrap the database.""" 
     53    """ 
     54    If no spatial database already exists, then using a cursor will not work.   
     55     Thus, a `createdb` command will be issued through the shell to bootstrap  
     56     creation of the spatial database. 
     57    """ 
    5558 
    5659    # Getting the command-line options for the shell command 
     
    8184 
    8285def create_spatial_db(test=False, verbosity=1, autoclobber=False, interactive=False): 
    83     "This Python routine creates a spatial database based on settings.py." 
     86    "Creates a spatial database based on the settings." 
    8487 
    8588    # Making sure we're using PostgreSQL and psycopg2 
     
    120123     
    121124def drop_db(db_name=False, test=False): 
    122     "Using the cursor, drops the given database.  All exceptions will be propagated up." 
     125    """ 
     126    Drops the given database (defaults to what is returned from get_spatial_db(). 
     127     All exceptions are propagated up to the caller. 
     128    """ 
    123129    if not db_name: db_name = get_spatial_db(test=test) 
    124130    cursor = connection.cursor() 
     
    139145 
    140146def get_spatial_db(test=False): 
    141     """This routine returns the name of the spatial database. 
    142     Set the 'test' keyword for the test spatial database name.""" 
     147    """ 
     148    Returns the name of the spatial database.  The 'test' keyword may be set  
     149     to return the test spatial database name. 
     150    """ 
    143151    if test: 
    144152        if settings.TEST_DATABASE_NAME: 
     
    153161 
    154162def load_postgis_sql(db_name, verbosity=1): 
    155     "This routine loads up the PostGIS SQL files lwpostgis.sql and spatial_ref_sys.sql." 
     163    """" 
     164    This routine loads up the PostGIS SQL files lwpostgis.sql and  
     165     spatial_ref_sys.sql. 
     166    """ 
    156167 
    157168    # Getting the path to the PostGIS SQL 
     
    161172        sql_path = settings.POSTGIS_SQL_PATH 
    162173    except AttributeError: 
    163         sql_path = '/usr/local/share' 
     174        status, sql_path = getstatusoutput('pg_config --sharedir') 
     175        if status != 0: 
     176            sql_path = '/usr/local/share' 
    164177 
    165178    # The PostGIS SQL post-creation files. 
  • django/branches/gis/django/contrib/gis/db/models/query.py

    r6018 r6026  
    1818    "Geographical-enabled QuerySet object." 
    1919     
    20     quote_name = connection.ops.quote_name 
    21  
    2220    #### Overloaded QuerySet Routines #### 
    2321    def __init__(self, model=None): 
     
    4846 
    4947    def _get_sql_clause(self): 
     48        qn = connection.ops.quote_name 
    5049        opts = self.model._meta 
    5150 
     
    8281        # Add any additional SELECTs. 
    8382        if self._select: 
    84             select.extend(['(%s) AS %s' % (quote_only_if_word(s[1]), self.quote_name(s[0])) for s in self._select.items()]) 
     83            select.extend(['(%s) AS %s' % (quote_only_if_word(s[1]), qn(s[0])) for s in self._select.items()]) 
    8584 
    8685        # Start composing the body of the SQL statement. 
    87         sql = [" FROM", self.quote_name(opts.db_table)] 
     86        sql = [" FROM", qn(opts.db_table)] 
    8887 
    8988        # Compose the join dictionary into SQL describing the joins. 
     
    108107        for f in handle_legacy_orderlist(ordering_to_use): 
    109108            if f == '?': # Special case. 
    110                 order_by.append(backend.get_random_function_sql()) 
     109                order_by.append(connection.ops.random_function_sql()) 
    111110            else: 
    112111                if f.startswith('-'): 
     
    118117                if "." in col_name: 
    119118                    table_prefix, col_name = col_name.split('.', 1) 
    120                     table_prefix = self.quote_name(table_prefix) + '.' 
     119                    table_prefix = qn(table_prefix) + '.' 
    121120                else: 
    122121                    # Use the database table as a column prefix if it wasn't given, 
    123122                    # and if the requested column isn't a custom SELECT. 
    124123                    if "." not in col_name and col_name not in (self._select or ()): 
    125                         table_prefix = self.quote_name(opts.db_table) + '.' 
     124                        table_prefix = qn(opts.db_table) + '.' 
    126125                    else: 
    127126                        table_prefix = '' 
    128                 order_by.append('%s%s %s' % (table_prefix, self.quote_name(orderfield2column(col_name, opts)), order)) 
     127                order_by.append('%s%s %s' % (table_prefix, qn(orderfield2column(col_name, opts)), order)) 
    129128        if order_by: 
    130129            sql.append("ORDER BY " + ", ".join(order_by)) 
     
    132131        # LIMIT and OFFSET clauses 
    133132        if self._limit is not None: 
    134             sql.append("%s " % backend.get_limit_offset_sql(self._limit, self._offset)) 
     133            sql.append("%s " % connection.ops.limit_offset_sql(self._limit, self._offset)) 
    135134        else: 
    136135            assert self._offset is None, "'offset' is not allowed without 'limit'" 
     
    145144    #### Methods specific to the GeoQuerySet #### 
    146145    def _field_column(self, field): 
    147         return "%s.%s" % (self.quote_name(self.model._meta.db_table), 
    148                           self.quote_name(field.column)) 
     146        qn = connection.ops.quote_name 
     147        return "%s.%s" % (qn(self.model._meta.db_table), 
     148                          qn(field.column)) 
    149149     
    150150    def kml(self, field_name, precision=8): 
     
    177177        self._custom_select[field.column] = \ 
    178178            '(ST_Transform(%s, %s)) AS %s' % (self._field_column(field), srid,  
    179                                               self.quote_name(field.column)) 
     179                                              connection.ops.quote_name(field.column)) 
    180180        return self._clone() 
    181181