Django

Code

Changeset 3712

Show
Ignore:
Timestamp:
09/03/06 21:20:26 (2 years ago)
Author:
jpellerin
Message:

[multi-db] Merge trunk to [3661]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/multiple-db-support/AUTHORS

    r3621 r3712  
    127127    Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/> 
    128128    David Schein 
     129    Pete Shinners <pete@shinners.org> 
    129130    sopel 
    130131    Thomas Steinacher <tom@eggdrop.ch> 
     
    139140    Geert Vanderkelen 
    140141    Milton Waddams 
     142    Dan Watson <http://theidioteque.net/> 
    141143    Rachel Willmer <http://www.willmer.com/kb/> 
    142144    wojtek 
  • django/branches/multiple-db-support/django/bin/compile-messages.py

    r3621 r3712  
    2727                os.environ['djangocompilemo'] = pf + '.mo' 
    2828                os.environ['djangocompilepo'] = pf + '.po' 
    29                 cmd = 'msgfmt -o "$djangocompilemo" "$djangocompilepo"' 
     29                if sys.platform == 'win32': # Different shell-variable syntax 
     30                    cmd = 'msgfmt -o "%djangocompilemo%" "%djangocompilepo%"' 
     31                else: 
     32                    cmd = 'msgfmt -o "$djangocompilemo" "$djangocompilepo"' 
    3033                os.system(cmd) 
    3134 
  • django/branches/multiple-db-support/django/conf/global_settings.py

    r3665 r3712  
    305305########### 
    306306 
    307 TEST_RUNNER='django.test.simple.run_tests' 
     307# The name of the method to use to invoke the test suite 
     308TEST_RUNNER = 'django.test.simple.run_tests' 
     309 
     310# The name of the database to use for testing purposes. 
     311# If None, a name of 'test_' + DATABASE_NAME will be assumed 
     312TEST_DATABASE_NAME = None 
     313 
     314# Tuple of other test databases to create. Names in this tuple 
     315# are suffixes that will be appended to TEST_DATABASE_NAME 
     316TEST_DATABASES = [] 
     317 
     318# Models to assign to each test database. This must be a list of 
     319# dicts, with each dict key being a name from TEST_DATABASES and value 
     320# a list of models or app_labels that will use that database. 
     321TEST_DATABASE_MODELS = [] 
  • django/branches/multiple-db-support/django/contrib/admin/views/doc.py

    r3621 r3712  
    329329    views = [] 
    330330    for p in urlpatterns: 
    331         if hasattr(p, 'get_callback'): 
     331        if hasattr(p, '_get_callback'): 
    332332            try: 
    333                 views.append((p.get_callback(), base + p.regex.pattern)) 
     333                views.append((p._get_callback(), base + p.regex.pattern)) 
    334334            except ViewDoesNotExist: 
    335335                continue 
    336336        elif hasattr(p, '_get_url_patterns'): 
    337             views.extend(extract_views_from_urlpatterns(p.url_patterns, base + p.regex.pattern)) 
     337            try: 
     338                patterns = p.url_patterns 
     339            except ImportError: 
     340                continue 
     341            views.extend(extract_views_from_urlpatterns(patterns, base + p.regex.pattern)) 
    338342        else: 
    339343            raise TypeError, _("%s does not appear to be a urlpattern object") % p 
  • django/branches/multiple-db-support/django/contrib/auth/models.py

    r3427 r3712  
    3434    Permissions are set globally per type of object, not per specific object instance. It is possible to say "Mary may change news stories," but it's not currently possible to say "Mary may change news stories, but only the ones she created herself" or "Mary may only change news stories that have a certain status or publication date." 
    3535 
    36     Three basic permissions -- add, create and delete -- are automatically created for each Django model. 
     36    Three basic permissions -- add, change and delete -- are automatically created for each Django model. 
    3737    """ 
    3838    name = models.CharField(_('name'), maxlength=50) 
  • django/branches/multiple-db-support/django/core/management.py

    r3668 r3712  
    295295            pass 
    296296 
    297     # Send the post_syncdb signal, so individual apps can do whatever they need 
    298     # to do at this point. 
     297    # Install each app 
    299298    for app in models.get_apps(): 
    300299        # Install each application (models already installed will be skipped) 
     
    304303                print "Created table %s" % model._meta.db_table 
    305304        created_models.extend(created) 
     305    transaction.commit_unless_managed() 
     306 
     307    # Send the post_syncdb signal, so individual apps can do whatever they need 
     308    # to do at this point. 
     309    for app in models.get_apps(): 
    306310        dispatcher.send(signal=signals.post_syncdb, sender=app, 
    307311            app=app, created_models=created_models,  
    308312            verbosity=verbosity, interactive=interactive) 
    309     transaction.commit_unless_managed() 
    310313 
    311314    # Install initial data for the app (but only if this is a model we've 
  • django/branches/multiple-db-support/django/core/serializers/base.py

    r3258 r3712  
    1212    """Something bad happened during serialization.""" 
    1313    pass 
    14      
     14 
    1515class DeserializationError(Exception): 
    1616    """Something bad happened during deserialization.""" 
     
    2121    Abstract serializer base class. 
    2222    """ 
    23      
     23 
    2424    def serialize(self, queryset, **options): 
    2525        """ 
     
    2727        """ 
    2828        self.options = options 
    29          
     29 
    3030        self.stream = options.get("stream", StringIO()) 
    31          
     31 
    3232        self.start_serialization() 
    3333        for obj in queryset: 
     
    4545        self.end_serialization() 
    4646        return self.getvalue() 
    47      
     47 
    4848    def get_string_value(self, obj, field): 
    4949        """ 
     
    5151        """ 
    5252        if isinstance(field, models.DateTimeField): 
    53             value = getattr(obj, field.name).strftime("%Y-%m-%d %H:%M:%S") 
     53            value = getattr(obj, field.name) 
     54            if value is None: 
     55                value = '' 
     56            else: 
     57                value = value.strftime("%Y-%m-%d %H:%M:%S") 
    5458        elif isinstance(field, models.FileField): 
    5559            value = getattr(obj, "get_%s_url" % field.name, lambda: None)() 
     
    5761            value = field.flatten_data(follow=None, obj=obj).get(field.name, "") 
    5862        return str(value) 
    59      
     63 
    6064    def start_serialization(self): 
    6165        """ 
     
    6367        """ 
    6468        raise NotImplementedError 
    65      
     69 
    6670    def end_serialization(self): 
    6771        """ 
     
    6973        """ 
    7074        pass 
    71      
     75 
    7276    def start_object(self, obj): 
    7377        """ 
     
    7579        """ 
    7680        raise NotImplementedError 
    77      
     81 
    7882    def end_object(self, obj): 
    7983        """ 
     
    8185        """ 
    8286        pass 
    83      
     87 
    8488    def handle_field(self, obj, field): 
    8589        """ 
     
    8791        """ 
    8892        raise NotImplementedError 
    89      
     93 
    9094    def handle_fk_field(self, obj, field): 
    9195        """ 
     
    9397        """ 
    9498        raise NotImplementedError 
    95      
     99 
    96100    def handle_m2m_field(self, obj, field): 
    97101        """ 
     
    99103        """ 
    100104        raise NotImplementedError 
    101      
     105 
    102106    def getvalue(self): 
    103107        """ 
     
    110114    Abstract base deserializer class. 
    111115    """ 
    112      
     116 
    113117    def __init__(self, stream_or_string, **options): 
    114118        """ 
     
    124128        # and friends might fail...) 
    125129        models.get_apps() 
    126      
     130 
    127131    def __iter__(self): 
    128132        return self 
    129      
     133 
    130134    def next(self): 
    131135        """Iteration iterface -- return the next item in the stream""" 
    132136        raise NotImplementedError 
    133          
     137 
    134138class DeserializedObject(object): 
    135139    """ 
    136140    A deserialzed model. 
    137      
     141 
    138142    Basically a container for holding the pre-saved deserialized data along 
    139143    with the many-to-many data saved with the object. 
    140      
     144 
    141145    Call ``save()`` to save the object (with the many-to-many data) to the 
    142146    database; call ``save(save_m2m=False)`` to save just the object fields 
    143147    (and not touch the many-to-many stuff.) 
    144148    """ 
    145      
     149 
    146150    def __init__(self, obj, m2m_data=None): 
    147151        self.object = obj 
    148152        self.m2m_data = m2m_data 
    149          
     153 
    150154    def __repr__(self): 
    151155        return "<DeserializedObject: %s>" % str(self.object) 
    152          
     156 
    153157    def save(self, save_m2m=True): 
    154158        self.object.save() 
     
    156160            for accessor_name, object_list in self.m2m_data.items(): 
    157161                setattr(self.object, accessor_name, object_list) 
    158          
    159         # prevent a second (possibly accidental) call to save() from saving  
     162 
     163        # prevent a second (possibly accidental) call to save() from saving 
    160164        # the m2m data twice. 
    161165        self.m2m_data = None 
  • django/branches/multiple-db-support/django/core/serializers/json.py

    r3502 r3712  
    4949            return o.strftime(self.TIME_FORMAT) 
    5050        else: 
    51             return super(self, DateTimeAwareJSONEncoder).default(o) 
     51            return super(DateTimeAwareJSONEncoder, self).default(o) 
  • django/branches/multiple-db-support/django/db/backends/postgresql_psycopg2/base.py

    r3581 r3712  
    1111    from django.core.exceptions import ImproperlyConfigured 
    1212    raise ImproperlyConfigured, "Error loading psycopg2 module: %s" % e 
    13  
    14 # Register Unicode conversions 
    15 import psycopg2.extensions 
    16 psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) 
    1713 
    1814DatabaseError = Database.DatabaseError 
     
    4844            self.connection.set_isolation_level(1) # make transactions transparent to all cursors 
    4945        cursor = self.connection.cursor() 
     46        cursor.tzinfo_factory = None 
    5047        cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) 
    5148        if settings.DEBUG: 
  • django/branches/multiple-db-support/django/db/backends/util.py

    r3113 r3712  
    9999def _dict_helper(desc, row): 
    100100    "Returns a dictionary for the given cursor.description and result row." 
    101     return dict([(desc[col[0]][0], col[1]) for col in enumerate(row)]
     101    return dict(zip([col[0] for col in desc], row)
    102102 
    103103def dictfetchone(cursor): 
  • django/branches/multiple-db-support/django/template/defaulttags.py

    r3664 r3712  
    252252        if self.parsed: 
    253253            try: 
    254                 t = Template(output, name=self.filepath
     254                t = Template(output
    255255                return t.render(context) 
    256256            except TemplateSyntaxError, e: 
  • django/branches/multiple-db-support/django/template/__init__.py

    r3664 r3712  
    6161from django.utils.functional import curry 
    6262from django.utils.text import smart_split 
    63 from django.dispatch import dispatcher 
    64 from django.template import signals 
    6563 
    6664__all__ = ('Template', 'Context', 'RequestContext', 'compile_string') 
     
    140138 
    141139class Template(object): 
    142     def __init__(self, template_string, origin=None, name='<Unknown Template>'): 
     140    def __init__(self, template_string, origin=None): 
    143141        "Compilation stage" 
    144142        if settings.TEMPLATE_DEBUG and origin == None: 
     
    147145            # came from... 
    148146        self.nodelist = compile_string(template_string, origin) 
    149         self.name = name 
    150147 
    151148    def __iter__(self): 
     
    156153    def render(self, context): 
    157154        "Display stage -- can be called many times" 
    158         dispatcher.send(signal=signals.template_rendered, sender=self, template=self, context=context) 
    159155        return self.nodelist.render(context) 
    160156 
     
    619615    (The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.') 
    620616    """ 
    621     if path == 'False': 
    622         current = False 
    623     elif path == 'True': 
    624         current = True 
    625     elif path[0].isdigit(): 
     617    if path[0].isdigit(): 
    626618        number_type = '.' in path and float or int 
    627619        try: 
  • django/branches/multiple-db-support/django/template/loader.py

    r3664 r3712  
    7777    handling template inheritance recursively. 
    7878    """ 
    79     source, origin = find_template_source(template_name) 
    80     template = get_template_from_string(source, origin, template_name) 
    81     return template 
     79    return get_template_from_string(*find_template_source(template_name)) 
    8280 
    83 def get_template_from_string(source, origin=None, name=None): 
     81def get_template_from_string(source, origin=None): 
    8482    """ 
    8583    Returns a compiled Template object for the given template code, 
    8684    handling template inheritance recursively. 
    8785    """ 
    88     return Template(source, origin, name
     86    return Template(source, origin
    8987 
    9088def render_to_string(template_name, dictionary=None, context_instance=None): 
  • django/branches/multiple-db-support/django/template/loader_tags.py

    r3664 r3712  
    5858            raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent 
    5959        else: 
    60             return get_template_from_string(source, origin, parent
     60            return get_template_from_string(source, origin
    6161 
    6262    def render(self, context): 
  • django/branches/multiple-db-support/django/test/simple.py

    r3658 r3712  
    6262        suite.addTest(test) 
    6363 
    64     old_name = create_test_db(verbosity) 
     64    old_name = settings.DATABASE_NAME 
     65    create_test_db(verbosity) 
    6566    management.syncdb(verbosity, interactive=False) 
    6667    unittest.TextTestRunner(verbosity=verbosity).run(suite) 
  • django/branches/multiple-db-support/django/test/utils.py

    r3658 r3712  
    11import sys, time 
    22from django.conf import settings 
    3 from django.db import connection, transaction 
     3from django.db import backend, connect, connection, connection_info, connections 
    44 
    55# The prefix to put on the default database name when creating 
     
    1313    elif hasattr(connection.connection, "set_isolation_level"): 
    1414        connection.connection.set_isolation_level(0) 
    15  
     15         
    1616def create_test_db(verbosity=1, autoclobber=False): 
    1717    if verbosity >= 1: 
    1818        print "Creating test database..." 
     19         
    1920    # If we're using SQLite, it's more convenient to test against an 
    2021    # in-memory database. 
    2122    if settings.DATABASE_ENGINE == "sqlite3": 
    2223        TEST_DATABASE_NAME = ":memory:" 
     24        if verbosity >= 2: 
     25            print "Using in-memory sqlite database for testing" 
    2326    else: 
    24         TEST_DATABASE_NAME = TEST_DATABASE_PREFIX + settings.DATABASE_NAME 
    25          
     27        if settings.TEST_DATABASE_NAME: 
     28            TEST_DATABASE_NAME = settings.TEST_DATABASE_NAME 
     29        else: 
     30            TEST_DATABASE_NAME = TEST_DATABASE_PREFIX + settings.DATABASE_NAME 
     31 
     32        qn = backend.quote_name 
    2633        # Create the test database and connect to it. We need to autocommit 
    2734        # if the database supports it because PostgreSQL doesn't allow  
     
    3037        _set_autocommit(connection) 
    3138        try: 
    32             cursor.execute("CREATE DATABASE %s" % TEST_DATABASE_NAME
     39            cursor.execute("CREATE DATABASE %s" % qn(db_name)
    3340        except Exception, e:             
    3441            sys.stderr.write("Got an error creating the test database: %s\n" % e) 
    3542            if not autoclobber: 
    36                 confirm = raw_input("It appears the test database, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % TEST_DATABASE_NAME
     43                confirm = raw_input("It appears the test database, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % db_name
    3744            if autoclobber or confirm == 'yes': 
    3845                try: 
    3946                    if verbosity >= 1: 
    4047                        print "Destroying old test database..."                 
    41                     cursor.execute("DROP DATABASE %s" % TEST_DATABASE_NAME
     48                    cursor.execute("DROP DATABASE %s" % qn(db_name)
    4249                    if verbosity >= 1: 
    4350                        print "Creating test database..." 
    44                     cursor.execute("CREATE DATABASE %s" % TEST_DATABASE_NAME
     51                    cursor.execute("CREATE DATABASE %s" % qn(db_name)
    4552                except Exception, e: 
    4653                    sys.stderr.write("Got an error recreating the test database: %s\n" % e) 
     
    4956                print "Tests cancelled." 
    5057                sys.exit(1) 
    51                 
    52     connection.close() 
    53     old_database_name = settings.DATABASE_NAME 
    54     settings.DATABASE_NAME = TEST_DATABASE_NAME 
     58        # Close the old connection 
     59        connection.close() 
    5560 
    56     # Get a cursor (even though we don't need one yet). This has 
    57     # the side effect of initializing the test database. 
    58     cursor = connection.cursor() 
    59              
    60     return old_database_name 
     61        # Get a cursor (even though we don't need one yet). This has