Ticket #7589: gis_post_create_sql.diff

File gis_post_create_sql.diff, 3.1 KB (added by jbronn, 16 years ago)

Modification of Django management commands to support GeoDjango

  • commands/sqlcustom.py

     
    77
    88    def handle_app(self, app, **options):
    99        from django.core.management.sql import sql_custom
    10         return u'\n'.join(sql_custom(app)).encode('utf-8')
     10        return u'\n'.join(sql_custom(app, self.style)).encode('utf-8')
  • commands/syncdb.py

     
    112112            app_name = app.__name__.split('.')[-2]
    113113            for model in models.get_models(app):
    114114                if model in created_models:
    115                     custom_sql = custom_sql_for_model(model)
     115                    custom_sql = custom_sql_for_model(model, self.style)
    116116                    if custom_sql:
    117117                        if verbosity >= 1:
    118118                            print "Installing custom SQL for %s.%s model" % (app_name, model._meta.object_name)
  • sql.py

     
    219219    statements = connection.ops.sql_flush(style, tables, sequence_list())
    220220    return statements
    221221
    222 def sql_custom(app):
     222def sql_custom(app, style):
    223223    "Returns a list of the custom table modifying SQL statements for the given app."
    224224    from django.db.models import get_models
    225225    output = []
     
    228228    app_dir = os.path.normpath(os.path.join(os.path.dirname(app.__file__), 'sql'))
    229229
    230230    for model in app_models:
    231         output.extend(custom_sql_for_model(model))
     231        output.extend(custom_sql_for_model(model, style))
    232232
    233233    return output
    234234
     
    242242
    243243def sql_all(app, style):
    244244    "Returns a list of CREATE TABLE SQL, initial-data inserts, and CREATE INDEX SQL for the given module."
    245     return sql_create(app, style) + sql_custom(app) + sql_indexes(app, style)
     245    return sql_create(app, style) + sql_custom(app, style) + sql_indexes(app, style)
    246246
    247247def sql_model_create(model, style, known_models=set()):
    248248    """
     
    426426
    427427    return final_output
    428428
    429 def custom_sql_for_model(model):
     429def custom_sql_for_model(model, style):
    430430    from django.db import models
    431431    from django.conf import settings
    432432
     
    434434    app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql'))
    435435    output = []
    436436
     437    # Post-creation SQL should come before any initial SQL data is loaded.
     438    # However, this should not be done for fields that are part of a
     439    # a parent model (via model inheritance).
     440    nm = opts.init_name_map()
     441    post_sql_fields = [f for f in opts.fields if nm[f.name][1] is None and hasattr(f, '_post_create_sql')]
     442    for f in post_sql_fields:
     443        output.extend(f._post_create_sql(style, model._meta.db_table))
     444
    437445    # Some backends can't execute more than one SQL statement at a time,
    438446    # so split into separate statements.
    439447    statements = re.compile(r";[ \t]*$", re.M)
Back to Top