mirror of
https://github.com/django/django.git
synced 2025-07-05 18:29:11 +00:00
[multi-db] Fix style handling: don't use mutable default style argument.
git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3262 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
2f44c9f24f
commit
a206863cf6
@ -4,11 +4,12 @@ import os
|
|||||||
import re
|
import re
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
# FIXME correct handling of styles,
|
# default dummy style
|
||||||
# allow style object to be passed in
|
|
||||||
class dummy:
|
class dummy:
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
return lambda x: x
|
return lambda x: x
|
||||||
|
default_style = dummy()
|
||||||
|
del dummy
|
||||||
|
|
||||||
class BoundStatement(object):
|
class BoundStatement(object):
|
||||||
"""Represents an SQL statement that is to be executed, at some point in
|
"""Represents an SQL statement that is to be executed, at some point in
|
||||||
@ -39,8 +40,8 @@ class SchemaBuilder(object):
|
|||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.models_already_seen = []
|
self.models_already_seen = []
|
||||||
|
|
||||||
def get_create_table(self, model, style=dummy()):
|
def get_create_table(self, model, style=None):
|
||||||
"""Construct and return the SQL expression(s) needed to create the
|
"""Construct and return the SQL expression(s) needed to create the
|
||||||
table for the given model, and any constraints on that
|
table for the given model, and any constraints on that
|
||||||
table. The return value is a 2-tuple. The first element of the tuple
|
table. The return value is a 2-tuple. The first element of the tuple
|
||||||
@ -49,6 +50,8 @@ class SchemaBuilder(object):
|
|||||||
can't be executed immediately because (for instance) the referent
|
can't be executed immediately because (for instance) the referent
|
||||||
table does not exist.
|
table does not exist.
|
||||||
"""
|
"""
|
||||||
|
if style is None:
|
||||||
|
style = default_style
|
||||||
if model in self.models_already_seen:
|
if model in self.models_already_seen:
|
||||||
return ([], [])
|
return ([], [])
|
||||||
self.models_already_seen.append(model)
|
self.models_already_seen.append(model)
|
||||||
@ -129,10 +132,12 @@ class SchemaBuilder(object):
|
|||||||
pending.append(BoundStatement(sql, opts.connection))
|
pending.append(BoundStatement(sql, opts.connection))
|
||||||
return (create, pending)
|
return (create, pending)
|
||||||
|
|
||||||
def get_create_indexes(self, model, style=dummy()):
|
def get_create_indexes(self, model, style=None):
|
||||||
"""Construct and return SQL statements needed to create the indexes for
|
"""Construct and return SQL statements needed to create the indexes for
|
||||||
a model. Returns a list of BoundStatements.
|
a model. Returns a list of BoundStatements.
|
||||||
"""
|
"""
|
||||||
|
if style is None:
|
||||||
|
style = default_style
|
||||||
info = model._meta.connection_info
|
info = model._meta.connection_info
|
||||||
backend = info.backend
|
backend = info.backend
|
||||||
connection = info.connection
|
connection = info.connection
|
||||||
@ -155,13 +160,15 @@ class SchemaBuilder(object):
|
|||||||
)
|
)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_create_many_to_many(self, model, style=dummy()):
|
def get_create_many_to_many(self, model, style=None):
|
||||||
"""Construct and return SQL statements needed to create the
|
"""Construct and return SQL statements needed to create the
|
||||||
tables and relationships for all many-to-many relations
|
tables and relationships for all many-to-many relations
|
||||||
defined in the model. Returns a list of bound statments. Note
|
defined in the model. Returns a list of bound statments. Note
|
||||||
that these statements should only be executed after all models
|
that these statements should only be executed after all models
|
||||||
for an app have been created.
|
for an app have been created.
|
||||||
"""
|
"""
|
||||||
|
if style is None:
|
||||||
|
style = default_style
|
||||||
info = model._meta.connection_info
|
info = model._meta.connection_info
|
||||||
quote_name = info.backend.quote_name
|
quote_name = info.backend.quote_name
|
||||||
connection = info.connection
|
connection = info.connection
|
||||||
@ -197,7 +204,9 @@ class SchemaBuilder(object):
|
|||||||
connection))
|
connection))
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_initialdata(self, model, style=dummy()):
|
def get_initialdata(self, model, style=None):
|
||||||
|
if style is None:
|
||||||
|
style = default_style
|
||||||
opts = model._meta
|
opts = model._meta
|
||||||
info = opts.connection_info
|
info = opts.connection_info
|
||||||
settings = info.connection.settings
|
settings = info.connection.settings
|
||||||
|
Loading…
x
Reference in New Issue
Block a user