Django

Code

Changeset 4152

Show
Ignore:
Timestamp:
12/04/06 12:16:40 (2 years ago)
Author:
jpellerin
Message:

[multi-db] Merged trunk to [3890]

Files:

Legend:

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

    r4151 r4152  
    7676    Andy Dustman <farcepest@gmail.com> 
    7777    Clint Ecker 
     78    Enrico <rico.bl@gmail.com> 
    7879    favo@exoweb.net 
    7980    gandalf@owca.info 
  • django/branches/multiple-db-support/django/conf/global_settings.py

    r4142 r4152  
    227227MONTH_DAY_FORMAT = 'F j' 
    228228 
    229 # Whether to enable Psyco, which optimizes Python code. Requires Psyco. 
    230 # http://psyco.sourceforge.net/ 
    231 ENABLE_PSYCO = False 
    232  
    233229# Do you want to manage transactions manually? 
    234230# Hint: you really don't! 
  • django/branches/multiple-db-support/django/contrib/admin/views/decorators.py

    r3427 r4152  
    8888        # The user data is correct; log in the user in and continue. 
    8989        else: 
    90             if user.is_staff: 
     90            if user.is_active and user.is_staff: 
    9191                login(request, user) 
    9292                # TODO: set last_login with an event. 
  • django/branches/multiple-db-support/django/contrib/auth/models.py

    r3712 r4152  
    217217    def has_module_perms(self, app_label): 
    218218        "Returns True if the user has any permissions in the given app label." 
     219        if not self.is_active: 
     220            return False 
    219221        if self.is_superuser: 
    220222            return True 
  • django/branches/multiple-db-support/django/core/handlers/base.py

    r4151 r4152  
    9090        except http.Http404, e: 
    9191            if settings.DEBUG: 
    92                 return self.get_technical_error_response(request, is404=True, exception=e) 
     92                from django.views import debug 
     93                return debug.technical_404_response(request, e) 
    9394            else: 
    9495                callback, param_dict = resolver.resolve404() 
     
    100101        except: # Handle everything else, including SuspiciousOperation, etc. 
    101102            if settings.DEBUG: 
    102                 return self.get_technical_error_response(request) 
     103                from django.views import debug 
     104                return debug.technical_500_response(request, *sys.exc_info()) 
    103105            else: 
    104106                # Get the exception info now, in case another exception is thrown later. 
     
    113115                message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr) 
    114116                mail_admins(subject, message, fail_silently=True) 
    115                 return self.get_friendly_error_response(request, resolver) 
    116  
    117     def get_friendly_error_response(self, request, resolver): 
    118         """ 
    119         Returns an HttpResponse that displays a PUBLIC error message for a 
    120         fundamental error. 
    121         """ 
    122         callback, param_dict = resolver.resolve500() 
    123         return callback(request, **param_dict) 
    124  
    125     def get_technical_error_response(self, request, is404=False, exception=None): 
    126         """ 
    127         Returns an HttpResponse that displays a TECHNICAL error message for a 
    128         fundamental error. 
    129         """ 
    130         from django.views import debug 
    131         if is404: 
    132             return debug.technical_404_response(request, exception) 
    133         else: 
    134             return debug.technical_500_response(request, *sys.exc_info()) 
     117                # Return an HttpResponse that displays a friendly error message. 
     118                callback, param_dict = resolver.resolve500() 
     119                return callback(request, **param_dict) 
    135120 
    136121    def _get_traceback(self, exc_info=None): 
  • django/branches/multiple-db-support/django/core/handlers/modpython.py

    r4151 r4152  
    140140        from django.conf import settings 
    141141 
    142         if settings.ENABLE_PSYCO: 
    143             import psyco 
    144             psyco.profile() 
    145  
    146142        # if we need to set up middleware, now that settings works we can do it now. 
    147143        if self._request_middleware is None: 
     
    161157 
    162158        # Convert our custom HttpResponse object back into the mod_python req. 
    163         populate_apache_request(response, req) 
     159        req.content_type = response['Content-Type'] 
     160        for key, value in response.headers.items(): 
     161            if key != 'Content-Type': 
     162                req.headers_out[key] = value 
     163        for c in response.cookies.values(): 
     164            req.headers_out.add('Set-Cookie', c.output(header='')) 
     165        req.status = response.status_code 
     166        try: 
     167            for chunk in response: 
     168                req.write(chunk) 
     169        finally: 
     170            response.close() 
     171 
    164172        return 0 # mod_python.apache.OK 
    165  
    166 def populate_apache_request(http_response, mod_python_req): 
    167     "Populates the mod_python request object with an HttpResponse" 
    168     mod_python_req.content_type = http_response['Content-Type'] 
    169     for key, value in http_response.headers.items(): 
    170         if key != 'Content-Type': 
    171             mod_python_req.headers_out[key] = value 
    172     for c in http_response.cookies.values(): 
    173         mod_python_req.headers_out.add('Set-Cookie', c.output(header='')) 
    174     mod_python_req.status = http_response.status_code 
    175     try: 
    176         for chunk in http_response: 
    177             mod_python_req.write(chunk) 
    178     finally: 
    179         http_response.close() 
    180173 
    181174def handler(req): 
  • django/branches/multiple-db-support/django/core/handlers/wsgi.py

    r4151 r4152  
    175175        from django.conf import settings 
    176176 
    177         if settings.ENABLE_PSYCO: 
    178             import psyco 
    179             psyco.profile() 
    180  
    181177        # Set up middleware if needed. We couldn't do this earlier, because 
    182178        # settings weren't available. 
  • django/branches/multiple-db-support/django/core/management.py

    r4151 r4152  
    231231    from django.db.models import get_models 
    232232    connection_output = {} 
    233  
    234233    for model in get_models(app): 
    235234        opts = model._meta 
     
    242241get_sql_indexes.help_doc = "Prints the CREATE INDEX SQL statements for the given model module name(s)." 
    243242get_sql_indexes.args = APP_ARGS 
     243 
     244def _get_sql_index(model): 
     245    "Returns the CREATE INDEX SQL statements for a specific model" 
     246    from django.db import backend 
     247    output = [] 
     248 
     249    for f in model._meta.fields: 
     250        if f.db_index: 
     251            unique = f.unique and 'UNIQUE ' or '' 
     252            output.append( 
     253                style.SQL_KEYWORD('CREATE %sINDEX' % unique) + ' ' + \ 
     254                style.SQL_TABLE('%s_%s' % (model._meta.db_table, f.column)) + ' ' + \ 
     255                style.SQL_KEYWORD('ON') + ' ' + \ 
     256                style.SQL_TABLE(backend.quote_name(model._meta.db_table)) + ' ' + \ 
     257                "(%s);" % style.SQL_FIELD(backend.quote_name(f.column)) 
     258            ) 
     259    return output 
    244260 
    245261def get_sql_all(app): 
     
    270286    return map(str, final_output) 
    271287 
    272 def syncdb(verbosity=2, interactive=True): 
     288def syncdb(verbosity=1, interactive=True): 
    273289    "Creates the database tables for all apps in INSTALLED_APPS whose tables haven't already been created." 
    274290    from django.conf import settings 
     
    297313        # Install each application (models already installed will be skipped) 
    298314        created, pending = _install(app, commit=False, initial_data=False, 
    299                                     pending_allowed=True, pending=pending) 
    300         if verbosity >= 2: 
     315                                    pending_allowed=True, pending=pending, 
     316                                    verbosity=verbosity) 
     317        if verbosity >= 1: 
    301318            for model in created: 
    302319                print "Created table %s" % model._meta.db_table 
     
    312329    # to do at this point. 
    313330    for app in models.get_apps(): 
     331        if verbosity >= 2: 
     332            print "Sending post-syncdb signal for application", app.__name__.split('.')[-2] 
    314333        dispatcher.send(signal=signals.post_syncdb, sender=app, 
    315334            app=app, created_models=created_models, 
     
    323342                try: 
    324343                    if (model._default_manager.load_initial_data()  
    325                         and verbosity >= 2): 
     344                        and verbosity >= 1): 
    326345                        print "Installed initial data for %s model" % model._meta.object_name 
    327346                except Exception, e: 
     
    392411 
    393412def _install(app, commit=True, initial_data=True, pending_allowed=False, 
    394              pending=None): 
     413             pending=None, verbosity=1): 
    395414    from django.db import connection, models, transaction 
    396415    import sys 
     
    408427            pending = {} 
    409428        for model in models.get_models(app, creation_order=True): 
     429            if verbosity >= 2: 
     430                print "Processing %s.%s model" % (app_name, 
     431                                                  model._meta.object_name) 
    410432            manager = model._default_manager 
    411433            tables = manager.get_table_list() 
     
    446468install.args = APP_ARGS 
    447469 
    448 def reset(app): 
     470def reset(app, interactive=True): 
    449471    "Executes the equivalent of 'get_sql_reset' in the current database." 
    450472    from django.db import connection, transaction 
     
    457479    sql_list = get_sql_reset(app) 
    458480 
    459     confirm = raw_input(""" 
     481    if interactive: 
     482        confirm = raw_input(""" 
    460483You have requested a database reset. 
    461484This will IRREVERSIBLY DESTROY any data in your database. 
     
    463486 
    464487Type 'yes' to continue, or 'no' to cancel: """) 
     488    else: 
     489        confirm = 'yes' 
     490         
    465491    if confirm == 'yes': 
    466492        try: 
     
    469495                cursor.execute(sql) 
    470496        except Exception, e: 
    471             sys.stderr.write(style.ERROR("""Error: %s couldn't be installed. Possible reasons: 
     497            sys.stderr.write(style.ERROR("""Error: %s couldn't be reset. Possible reasons: 
    472498  * The database isn't running or isn't configured correctly. 
    473   * At least one of the database tables already exists
     499  * At least one of the database tables doesn't exist
    474500  * The SQL was invalid. 
    475501Hint: Look at the output of 'django-admin.py sqlreset %s'. That's the SQL this command wasn't able to run. 
     
    10321058runfcgi.args = '[various KEY=val options, use `runfcgi help` for help]' 
    10331059 
    1034 def test(verbosity, app_labels): 
     1060def test(app_labels, verbosity=1): 
    10351061    "Runs the test suite for the specified applications" 
    10361062    from django.conf import settings 
     
    11341160    parser.add_option('--noreload', action='store_false', dest='use_reloader', default=True, 
    11351161        help='Tells Django to NOT use the auto-reloader when running the development server.') 
    1136     parser.add_option('--verbosity', action='store', dest='verbosity', default='2', 
     1162    parser.add_option('--verbosity', action='store', dest='verbosity', default='1', 
    11371163        type='choice', choices=['0', '1', '2'], 
    11381164        help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'), 
     
    11831209    elif action == 'test': 
    11841210        try: 
    1185             action_mapping[action](int(options.verbosity), args[1:]
     1211            action_mapping[action](args[1:], int(options.verbosity)
    11861212        except IndexError: 
    11871213            parser.print_usage_and_exit() 
     
    12171243            print style.SQL_KEYWORD("BEGIN;") 
    12181244        for mod in mod_list: 
    1219             output = action_mapping[action](mod) 
     1245            if action == 'reset': 
     1246                output = action_mapping[action](mod, options.interactive) 
     1247            else: 
     1248                output = action_mapping[action](mod) 
    12201249            if output: 
    12211250                print '\n'.join(output) 
  • django/branches/multiple-db-support/docs/admin_css.txt

    r3427 r4152  
    8383    This is a custom class for blocks of inline help text explaining the 
    8484    function of form elements. It makes text smaller and gray, and when applied 
    85     to ``p`` elements withing ``.form-row`` elements (see Form Styles below), 
     85    to ``p`` elements within ``.form-row`` elements (see Form Styles below), 
    8686    it will offset the text to align with the form field. Use this for help 
    8787    text, instead of ``small quiet``. It works on other elements, but try to 
  • django/branches/multiple-db-support/docs/api_stability.txt

    r3502 r4152  
    8383change: 
    8484 
    85    - `Forms and validation`_ will most likely be compeltely rewritten to 
     85   - `Forms and validation`_ will most likely be completely rewritten to 
    8686     deemphasize Manipulators in favor of validation-aware models. 
    8787 
     
    9292 
    9393   - Generic relations will most likely be moved out of core and into the 
    94      content-types contrib package to avoid core dependacies on optional 
     94     content-types contrib package to avoid core dependancies on optional 
    9595     components. 
    9696 
  • django/branches/multiple-db-support/docs/authentication.txt

    r4142 r4152  
    6767    * ``is_staff`` -- Boolean. Designates whether this user can access the 
    6868      admin site. 
    69     * ``is_active`` -- Boolean. Designates whether this user can log into the 
    70       Django admin. Set this to ``False`` instead of deleting accounts. 
     69    * ``is_active`` -- Boolean. Designates whether this account can be used 
     70      to log in. Set this flag to ``False`` instead of deleting accounts. 
    7171    * ``is_superuser`` -- Boolean. Designates that this user has all permissions 
    7272      without explicitly assigning them. 
     
    100100 
    101101    * ``is_authenticated()`` -- Always returns ``True``. This is a way to 
    102       tell if the user has been authenticated. 
     102      tell if the user has been authenticated. This does not imply any  
     103      permissions, and doesn't check if the user is active - it only indicates 
     104      that the user has provided a valid username and password. 
    103105 
    104106    * ``get_full_name()`` -- Returns the ``first_name`` plus the ``last_name``, 
     
    121123    * ``has_perm(perm)`` -- Returns ``True`` if the user has the specified 
    122124      permission, where perm is in the format ``"package.codename"``. 
     125      If the user is inactive, this method will always return ``False``. 
    123126 
    124127    * ``has_perms(perm_list)`` -- Returns ``True`` if the user has each of the 
    125128      specified permissions, where each perm is in the format 
    126       ``"package.codename"``. 
     129      ``"package.codename"``. If the user is inactive, this method will  
     130      always return ``False``. 
    127131 
    128132    * ``has_module_perms(package_name)`` -- Returns ``True`` if the user has 
    129133      any permissions in the given package (the Django app label). 
     134      If the user is inactive, this method will always return ``False``. 
    130135 
    131136    * ``get_and_delete_messages()`` -- Returns a list of ``Message`` objects in 
     
    284289    user = authenticate(username='john', password='secret') 
    285290    if user is not None: 
    286         print "You provided a correct username and password!" 
     291        if user.is_active: 
     292            print "You provided a correct username and password!" 
     293        else: 
     294            print "Your account has been disabled!" 
    287295    else: 
    288296        print "Your username and password were incorrect." 
     
    302310        user = authenticate(username=username, password=password) 
    303311        if user is not None: 
    304             login(request, user) 
    305             # Redirect to a success page. 
     312            if user.is_active: 
     313                login(request, user) 
     314                # Redirect to a success page. 
     315            else: 
     316                # Return a 'disabled account' error message 
    306317        else: 
    307             # Return an error message. 
     318            # Return an 'invalid login' error message. 
    308319 
    309320How to log a user out 
  • django/branches/multiple-db-support/docs/faq.txt

    r4151 r4152  
    500500------------------------------------------------------------------------------------------------------------------ 
    501501 
    502 We try to avoid adding special cases in the Django code to accomodate all the 
     502We try to avoid adding special cases in the Django code to accommodate all the 
    503503database-specific options such as table type, etc. If you'd like to use any of 
    504504these options, create an `SQL initial data file`_ that contains ``ALTER TABLE`` 
  • django/branches/multiple-db-support/docs/forms.txt

    r4142 r4152  
    490490validators for that field are called in turn. The emphasized portion in the 
    491491last sentence is important: if a form field is not submitted (because it 
    492 contains no data -- which is normal HTML behaviour), the validators are not 
     492contains no data -- which is normal HTML behavior), the validators are not 
    493493run against the field. 
    494494 
  • django/branches/multiple-db-support/docs/release_notes_0.95.txt

    r3502 r4152  
    111111 
    112112Finally, for those who prefer the more immediate feedback offered by IRC, 
    113 there's a #django channel or irc.freenode.net that is regularly populated by 
     113there's a #django channel on irc.freenode.net that is regularly populated by 
    114114Django users and developers from around the world. Friendly people are usually 
    115115available at any hour of the day -- to help, or just to chat. 
  • django/branches/multiple-db-support/docs/settings.txt

    r4142 r4152  
    401401or ``django.core.mail.mail_managers``. You'll probably want to include the 
    402402trailing space. 
    403  
    404 ENABLE_PSYCO 
    405 ------------ 
    406  
    407 Default: ``False`` 
    408  
    409 Whether to enable Psyco, which optimizes Python code. Requires Psyco_. 
    410  
    411 .. _Psyco: http://psyco.sourceforge.net/ 
    412403 
    413404IGNORABLE_404_ENDS 
  • django/branches/multiple-db-support/docs/templates_python.txt

    r4151 r4152  
    818818Another common type of template tag is the type that displays some data by 
    819819rendering *another* template. For example, Django's admin interface uses custom 
    820 template tags to display the buttons along the botton of the "add/change" form 
     820template tags to display the buttons along the bottom of the "add/change" form 
    821821pages. Those buttons always look the same, but the link targets change depending 
    822822on the object being edited -- so they're a perfect case for using a small 
  • django/branches/multiple-db-support/docs/templates.txt

    r3648 r4152  
    540540        ... 
    541541    {% endifequal %} 
     542 
     543It is only possible to compare an argument to template variables or strings. 
     544You cannot check for equality with Python objects such as ``True`` or 
     545``False``.  If you need to test if something is true or false, use the ``if`` 
     546and ``ifnot`` tags instead. 
    542547 
    543548ifnotequal 
     
    10521057the comparison point (without the argument, the comparison point is *now*). 
    10531058For example, if ``blog_date`` is a date instance representing midnight on 1 
    1054 June 2006, and ``comment_date`` is a date instanace for 08:00 on 1 June 2006, 
     1059June 2006, and ``comment_date`` is a date instance for 08:00 on 1 June 2006, 
    10551060then ``{{ comment_date|timesince:blog_date }}`` would return "8 hours". 
    10561061 
  • django/branches/multiple-db-support/docs/testing.txt

    r3739 r4152  
    390390When you run ``./manage.py test``, Django looks at the ``TEST_RUNNER`` 
    391391setting to determine what to do. By default, ``TEST_RUNNER`` points to ``django.test.simple.run_tests``. This method defines the default Django 
    392 testing behaviour. This behaviour involves: 
     392testing behavior. This behavior involves: 
    393393 
    394394#. Performing global pre-test setup 
     
    436436    Creates a new test database, and run ``syncdb`` against it. 
    437437 
    438     ``verbosity`` has the same behaviour as in the test runner. 
     438    ``verbosity`` has the same behavior as in the test runner. 
    439439 
    440440    ``Autoclobber`` describes the behavior that will occur if a database with 
     
    451451    and restores the value of ``settings.DATABASE_NAME`` to the provided name. 
    452452 
    453     ``verbosity`` has the same behaviour as in the test runner. 
     453    ``verbosity`` has the same behavior as in the test runner. 
  • django/branches/multiple-db-support/docs/tutorial03.txt

    r3427 r4152  
    9292pattern "captures" the text matched by that pattern and sends it as an argument 
    9393to the view function; the ``?P<poll_id>`` defines the name that will be used to 
    94 identify the matched pattern; and ``\d+`` is a regular experession to match a sequence of 
     94identify the matched pattern; and ``\d+`` is a regular expression to match a sequence of 
    9595digits (i.e., a number). 
    9696 
  • django/branches/multiple-db-support/docs/tutorial04.txt

    r3502 r4152  
    208208 
    209209In previous parts of the tutorial, the templates have been provided with a context 
    210 that contains the ``poll` and ``latest_poll_list`` context variables. However, 
     210that contains the ``poll`` and ``latest_poll_list`` context variables. However, 
    211211the generic views provide the variables ``object`` and ``object_list`` as context. 
    212212Therefore, you need to change your templates to match the new context variables.