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/core/management/commands/compilemessages.py

    r7918 r8215  
    22import sys 
    33from optparse import make_option 
    4 from django.core.management.base import BaseCommand 
    5 from django.core.management.color import no_style 
     4from django.core.management.base import BaseCommand, CommandError 
    65 
    76try: 
  • django/branches/gis/django/core/management/commands/test.py

    r7354 r8215  
    1818    def handle(self, *test_labels, **options): 
    1919        from django.conf import settings 
    20         from django.db.models import get_app, get_apps 
    2120 
    2221        verbosity = int(options.get('verbosity', 1)) 
  • django/branches/gis/django/core/management/commands/testserver.py

    r7354 r8215  
    1818 
    1919    def handle(self, *fixture_labels, **options): 
    20         from django.conf import settings 
    2120        from django.core.management import call_command 
    2221        from django.test.utils import create_test_db 
  • django/branches/gis/django/core/management/sql.py

    r7836 r8215  
    182182        opts = model._meta 
    183183        for f in opts.local_many_to_many: 
    184             if isinstance(f.rel, generic.GenericRel)
     184            if not f.creates_table
    185185                continue 
    186186            if cursor and table_name_converter(f.m2m_db_table()) in table_names: 
     
    354354    inline_references = connection.features.inline_fk_references 
    355355    for f in opts.local_many_to_many: 
    356         if not isinstance(f.rel, generic.GenericRel)
     356        if f.creates_table
    357357            tablespace = f.db_tablespace or opts.db_tablespace 
    358358            if tablespace and connection.features.supports_tablespaces:  
     
    436436 
    437437    # 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). 
     438    # However, this should not be done for fields that are part of a a parent 
     439    # model (via model inheritance). 
    440440    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')] 
     441    post_sql_fields = [f for f in opts.local_fields if hasattr(f, 'post_create_sql')] 
    442442    for f in post_sql_fields: 
    443         output.extend(f._post_create_sql(style, model._meta.db_table)) 
     443        output.extend(f.post_create_sql(style, model._meta.db_table)) 
    444444 
    445445    # Some backends can't execute more than one SQL statement at a time, 
  • django/branches/gis/django/core/management/validation.py

    r7979 r8215  
    103103                            e.add(opts, "Reverse query name for field '%s' clashes with related field '%s.%s'. Add a related_name argument to the definition for '%s'." % (f.name, rel_opts.object_name, r.get_accessor_name(), f.name)) 
    104104 
     105        seen_intermediary_signatures = []  
    105106        for i, f in enumerate(opts.local_many_to_many): 
    106107            # Check to see if the related m2m field will clash with any 
     
    113114                if isinstance(f.rel.to, (str, unicode)): 
    114115                    continue 
    115  
     116            if getattr(f.rel, 'through', None) is not None: 
     117                if hasattr(f.rel, 'through_model'): 
     118                    from_model, to_model = cls, f.rel.to 
     119                    if from_model == to_model and f.rel.symmetrical: 
     120                        e.add(opts, "Many-to-many fields with intermediate tables cannot be symmetrical.") 
     121                    seen_from, seen_to, seen_self = False, False, 0 
     122                    for inter_field in f.rel.through_model._meta.fields: 
     123                        rel_to = getattr(inter_field.rel, 'to', None) 
     124                        if from_model == to_model: # relation to self 
     125                            if rel_to == from_model: 
     126                                seen_self += 1 
     127                            if seen_self > 2: 
     128                                e.add(opts, "Intermediary model %s has more than two foreign keys to %s, which is ambiguous and is not permitted." % (f.rel.through_model._meta.object_name, from_model._meta.object_name)) 
     129                        else: 
     130                            if rel_to == from_model: 
     131                                if seen_from: 
     132                                    e.add(opts, "Intermediary model %s has more than one foreign key to %s, which is ambiguous and is not permitted." % (f.rel.through_model._meta.object_name, rel_from._meta.object_name)) 
     133                                else: 
     134                                    seen_from = True 
     135                            elif rel_to == to_model: 
     136                                if seen_to: 
     137                                    e.add(opts, "Intermediary model %s has more than one foreign key to %s, which is ambiguous and is not permitted." % (f.rel.through_model._meta.object_name, rel_to._meta.object_name)) 
     138                                else: 
     139                                    seen_to = True 
     140                    if f.rel.through_model not in models.get_models(): 
     141                        e.add(opts, "'%s' specifies an m2m relation through model %s, which has not been installed." % (f.name, f.rel.through)) 
     142                    signature = (f.rel.to, cls, f.rel.through_model) 
     143                    if signature in seen_intermediary_signatures: 
     144                        e.add(opts, "The model %s has two manually-defined m2m relations through the model %s, which is not permitted. Please consider using an extra field on your intermediary model instead." % (cls._meta.object_name, f.rel.through_model._meta.object_name)) 
     145                    else: 
     146                        seen_intermediary_signatures.append(signature) 
     147                    seen_related_fk, seen_this_fk = False, False 
     148                    for field in f.rel.through_model._meta.fields: 
     149                        if field.rel: 
     150                            if not seen_related_fk and field.rel.to == f.rel.to: 
     151                                seen_related_fk = True 
     152                            elif field.rel.to == cls: 
     153                                seen_this_fk = True 
     154                    if not seen_related_fk or not seen_this_fk: 
     155                        e.add(opts, "'%s' has a manually-defined m2m relation through model %s, which does not have foreign keys to %s and %s" % (f.name, f.rel.through, f.rel.to._meta.object_name, cls._meta.object_name)) 
     156                else: 
     157                    e.add(opts, "'%s' specifies an m2m relation through model %s, which has not been installed" % (f.name, f.rel.through)) 
     158             
    116159            rel_opts = f.rel.to._meta 
    117160            rel_name = RelatedObject(f.rel.to, cls, f).get_accessor_name()