Changeset 4152
- Timestamp:
- 12/04/06 12:16:40 (2 years ago)
- Files:
-
- django/branches/multiple-db-support/AUTHORS (modified) (1 diff)
- django/branches/multiple-db-support/django/conf/global_settings.py (modified) (1 diff)
- django/branches/multiple-db-support/django/contrib/admin/views/decorators.py (modified) (1 diff)
- django/branches/multiple-db-support/django/contrib/auth/models.py (modified) (1 diff)
- django/branches/multiple-db-support/django/core/handlers/base.py (modified) (3 diffs)
- django/branches/multiple-db-support/django/core/handlers/modpython.py (modified) (2 diffs)
- django/branches/multiple-db-support/django/core/handlers/wsgi.py (modified) (1 diff)
- django/branches/multiple-db-support/django/core/management.py (modified) (16 diffs)
- django/branches/multiple-db-support/docs/admin_css.txt (modified) (1 diff)
- django/branches/multiple-db-support/docs/api_stability.txt (modified) (2 diffs)
- django/branches/multiple-db-support/docs/authentication.txt (modified) (5 diffs)
- django/branches/multiple-db-support/docs/faq.txt (modified) (1 diff)
- django/branches/multiple-db-support/docs/forms.txt (modified) (1 diff)
- django/branches/multiple-db-support/docs/release_notes_0.95.txt (modified) (1 diff)
- django/branches/multiple-db-support/docs/settings.txt (modified) (1 diff)
- django/branches/multiple-db-support/docs/templates_python.txt (modified) (1 diff)
- django/branches/multiple-db-support/docs/templates.txt (modified) (2 diffs)
- django/branches/multiple-db-support/docs/testing.txt (modified) (3 diffs)
- django/branches/multiple-db-support/docs/tutorial03.txt (modified) (1 diff)
- django/branches/multiple-db-support/docs/tutorial04.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/multiple-db-support/AUTHORS
r4151 r4152 76 76 Andy Dustman <farcepest@gmail.com> 77 77 Clint Ecker 78 Enrico <rico.bl@gmail.com> 78 79 favo@exoweb.net 79 80 gandalf@owca.info django/branches/multiple-db-support/django/conf/global_settings.py
r4142 r4152 227 227 MONTH_DAY_FORMAT = 'F j' 228 228 229 # Whether to enable Psyco, which optimizes Python code. Requires Psyco.230 # http://psyco.sourceforge.net/231 ENABLE_PSYCO = False232 233 229 # Do you want to manage transactions manually? 234 230 # Hint: you really don't! django/branches/multiple-db-support/django/contrib/admin/views/decorators.py
r3427 r4152 88 88 # The user data is correct; log in the user in and continue. 89 89 else: 90 if user.is_ staff:90 if user.is_active and user.is_staff: 91 91 login(request, user) 92 92 # TODO: set last_login with an event. django/branches/multiple-db-support/django/contrib/auth/models.py
r3712 r4152 217 217 def has_module_perms(self, app_label): 218 218 "Returns True if the user has any permissions in the given app label." 219 if not self.is_active: 220 return False 219 221 if self.is_superuser: 220 222 return True django/branches/multiple-db-support/django/core/handlers/base.py
r4151 r4152 90 90 except http.Http404, e: 91 91 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) 93 94 else: 94 95 callback, param_dict = resolver.resolve404() … … 100 101 except: # Handle everything else, including SuspiciousOperation, etc. 101 102 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()) 103 105 else: 104 106 # Get the exception info now, in case another exception is thrown later. … … 113 115 message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr) 114 116 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) 135 120 136 121 def _get_traceback(self, exc_info=None): django/branches/multiple-db-support/django/core/handlers/modpython.py
r4151 r4152 140 140 from django.conf import settings 141 141 142 if settings.ENABLE_PSYCO:143 import psyco144 psyco.profile()145 146 142 # if we need to set up middleware, now that settings works we can do it now. 147 143 if self._request_middleware is None: … … 161 157 162 158 # 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 164 172 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] = value172 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_code175 try:176 for chunk in http_response:177 mod_python_req.write(chunk)178 finally:179 http_response.close()180 173 181 174 def handler(req): django/branches/multiple-db-support/django/core/handlers/wsgi.py
r4151 r4152 175 175 from django.conf import settings 176 176 177 if settings.ENABLE_PSYCO:178 import psyco179 psyco.profile()180 181 177 # Set up middleware if needed. We couldn't do this earlier, because 182 178 # settings weren't available. django/branches/multiple-db-support/django/core/management.py
r4151 r4152 231 231 from django.db.models import get_models 232 232 connection_output = {} 233 234 233 for model in get_models(app): 235 234 opts = model._meta … … 242 241 get_sql_indexes.help_doc = "Prints the CREATE INDEX SQL statements for the given model module name(s)." 243 242 get_sql_indexes.args = APP_ARGS 243 244 def _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 244 260 245 261 def get_sql_all(app): … … 270 286 return map(str, final_output) 271 287 272 def syncdb(verbosity= 2, interactive=True):288 def syncdb(verbosity=1, interactive=True): 273 289 "Creates the database tables for all apps in INSTALLED_APPS whose tables haven't already been created." 274 290 from django.conf import settings … … 297 313 # Install each application (models already installed will be skipped) 298 314 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: 301 318 for model in created: 302 319 print "Created table %s" % model._meta.db_table … … 312 329 # to do at this point. 313 330 for app in models.get_apps(): 331 if verbosity >= 2: 332 print "Sending post-syncdb signal for application", app.__name__.split('.')[-2] 314 333 dispatcher.send(signal=signals.post_syncdb, sender=app, 315 334 app=app, created_models=created_models, … … 323 342 try: 324 343 if (model._default_manager.load_initial_data() 325 and verbosity >= 2):344 and verbosity >= 1): 326 345 print "Installed initial data for %s model" % model._meta.object_name 327 346 except Exception, e: … … 392 411 393 412 def _install(app, commit=True, initial_data=True, pending_allowed=False, 394 pending=None ):413 pending=None, verbosity=1): 395 414 from django.db import connection, models, transaction 396 415 import sys … … 408 427 pending = {} 409 428 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) 410 432 manager = model._default_manager 411 433 tables = manager.get_table_list() … … 446 468 install.args = APP_ARGS 447 469 448 def reset(app ):470 def reset(app, interactive=True): 449 471 "Executes the equivalent of 'get_sql_reset' in the current database." 450 472 from django.db import connection, transaction … … 457 479 sql_list = get_sql_reset(app) 458 480 459 confirm = raw_input(""" 481 if interactive: 482 confirm = raw_input(""" 460 483 You have requested a database reset. 461 484 This will IRREVERSIBLY DESTROY any data in your database. … … 463 486 464 487 Type 'yes' to continue, or 'no' to cancel: """) 488 else: 489 confirm = 'yes' 490 465 491 if confirm == 'yes': 466 492 try: … … 469 495 cursor.execute(sql) 470 496 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: 472 498 * 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. 474 500 * The SQL was invalid. 475 501 Hint: Look at the output of 'django-admin.py sqlreset %s'. That's the SQL this command wasn't able to run. … … 1032 1058 runfcgi.args = '[various KEY=val options, use `runfcgi help` for help]' 1033 1059 1034 def test( verbosity, app_labels):1060 def test(app_labels, verbosity=1): 1035 1061 "Runs the test suite for the specified applications" 1036 1062 from django.conf import settings … … 1134 1160 parser.add_option('--noreload', action='store_false', dest='use_reloader', default=True, 1135 1161 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', 1137 1163 type='choice', choices=['0', '1', '2'], 1138 1164 help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'), … … 1183 1209 elif action == 'test': 1184 1210 try: 1185 action_mapping[action]( int(options.verbosity), args[1:])1211 action_mapping[action](args[1:], int(options.verbosity)) 1186 1212 except IndexError: 1187 1213 parser.print_usage_and_exit() … … 1217 1243 print style.SQL_KEYWORD("BEGIN;") 1218 1244 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) 1220 1249 if output: 1221 1250 print '\n'.join(output) django/branches/multiple-db-support/docs/admin_css.txt
r3427 r4152 83 83 This is a custom class for blocks of inline help text explaining the 84 84 function of form elements. It makes text smaller and gray, and when applied 85 to ``p`` elements within g``.form-row`` elements (see Form Styles below),85 to ``p`` elements within ``.form-row`` elements (see Form Styles below), 86 86 it will offset the text to align with the form field. Use this for help 87 87 text, instead of ``small quiet``. It works on other elements, but try to django/branches/multiple-db-support/docs/api_stability.txt
r3502 r4152 83 83 change: 84 84 85 - `Forms and validation`_ will most likely be comp eltely rewritten to85 - `Forms and validation`_ will most likely be completely rewritten to 86 86 deemphasize Manipulators in favor of validation-aware models. 87 87 … … 92 92 93 93 - Generic relations will most likely be moved out of core and into the 94 content-types contrib package to avoid core dependa cies on optional94 content-types contrib package to avoid core dependancies on optional 95 95 components. 96 96 django/branches/multiple-db-support/docs/authentication.txt
r4142 r4152 67 67 * ``is_staff`` -- Boolean. Designates whether this user can access the 68 68 admin site. 69 * ``is_active`` -- Boolean. Designates whether this user can log into the70 Django admin. Set thisto ``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. 71 71 * ``is_superuser`` -- Boolean. Designates that this user has all permissions 72 72 without explicitly assigning them. … … 100 100 101 101 * ``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. 103 105 104 106 * ``get_full_name()`` -- Returns the ``first_name`` plus the ``last_name``, … … 121 123 * ``has_perm(perm)`` -- Returns ``True`` if the user has the specified 122 124 permission, where perm is in the format ``"package.codename"``. 125 If the user is inactive, this method will always return ``False``. 123 126 124 127 * ``has_perms(perm_list)`` -- Returns ``True`` if the user has each of the 125 128 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``. 127 131 128 132 * ``has_module_perms(package_name)`` -- Returns ``True`` if the user has 129 133 any permissions in the given package (the Django app label). 134 If the user is inactive, this method will always return ``False``. 130 135 131 136 * ``get_and_delete_messages()`` -- Returns a list of ``Message`` objects in … … 284 289 user = authenticate(username='john', password='secret') 285 290 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!" 287 295 else: 288 296 print "Your username and password were incorrect." … … 302 310 user = authenticate(username=username, password=password) 303 311 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 306 317 else: 307 # Return an error message.318 # Return an 'invalid login' error message. 308 319 309 320 How to log a user out django/branches/multiple-db-support/docs/faq.txt
r4151 r4152 500 500 ------------------------------------------------------------------------------------------------------------------ 501 501 502 We try to avoid adding special cases in the Django code to accom odate all the502 We try to avoid adding special cases in the Django code to accommodate all the 503 503 database-specific options such as table type, etc. If you'd like to use any of 504 504 these options, create an `SQL initial data file`_ that contains ``ALTER TABLE`` django/branches/multiple-db-support/docs/forms.txt
r4142 r4152 490 490 validators for that field are called in turn. The emphasized portion in the 491 491 last sentence is important: if a form field is not submitted (because it 492 contains no data -- which is normal HTML behavio ur), the validators are not492 contains no data -- which is normal HTML behavior), the validators are not 493 493 run against the field. 494 494 django/branches/multiple-db-support/docs/release_notes_0.95.txt
r3502 r4152 111 111 112 112 Finally, for those who prefer the more immediate feedback offered by IRC, 113 there's a #django channel o rirc.freenode.net that is regularly populated by113 there's a #django channel on irc.freenode.net that is regularly populated by 114 114 Django users and developers from around the world. Friendly people are usually 115 115 available at any hour of the day -- to help, or just to chat. django/branches/multiple-db-support/docs/settings.txt
r4142 r4152 401 401 or ``django.core.mail.mail_managers``. You'll probably want to include the 402 402 trailing space. 403 404 ENABLE_PSYCO405 ------------406 407 Default: ``False``408 409 Whether to enable Psyco, which optimizes Python code. Requires Psyco_.410 411 .. _Psyco: http://psyco.sourceforge.net/412 403 413 404 IGNORABLE_404_ENDS django/branches/multiple-db-support/docs/templates_python.txt
r4151 r4152 818 818 Another common type of template tag is the type that displays some data by 819 819 rendering *another* template. For example, Django's admin interface uses custom 820 template tags to display the buttons along the botto nof the "add/change" form820 template tags to display the buttons along the bottom of the "add/change" form 821 821 pages. Those buttons always look the same, but the link targets change depending 822 822 on the object being edited -- so they're a perfect case for using a small django/branches/multiple-db-support/docs/templates.txt
r3648 r4152 540 540 ... 541 541 {% endifequal %} 542 543 It is only possible to compare an argument to template variables or strings. 544 You 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`` 546 and ``ifnot`` tags instead. 542 547 543 548 ifnotequal … … 1052 1057 the comparison point (without the argument, the comparison point is *now*). 1053 1058 For example, if ``blog_date`` is a date instance representing midnight on 1 1054 June 2006, and ``comment_date`` is a date instan ace for 08:00 on 1 June 2006,1059 June 2006, and ``comment_date`` is a date instance for 08:00 on 1 June 2006, 1055 1060 then ``{{ comment_date|timesince:blog_date }}`` would return "8 hours". 1056 1061 django/branches/multiple-db-support/docs/testing.txt
r3739 r4152 390 390 When you run ``./manage.py test``, Django looks at the ``TEST_RUNNER`` 391 391 setting to determine what to do. By default, ``TEST_RUNNER`` points to ``django.test.simple.run_tests``. This method defines the default Django 392 testing behavio ur. This behaviour involves:392 testing behavior. This behavior involves: 393 393 394 394 #. Performing global pre-test setup … … 436 436 Creates a new test database, and run ``syncdb`` against it. 437 437 438 ``verbosity`` has the same behavio ur as in the test runner.438 ``verbosity`` has the same behavior as in the test runner. 439 439 440 440 ``Autoclobber`` describes the behavior that will occur if a database with … … 451 451 and restores the value of ``settings.DATABASE_NAME`` to the provided name. 452 452 453 ``verbosity`` has the same behavio ur 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 92 92 pattern "captures" the text matched by that pattern and sends it as an argument 93 93 to 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 exp eression to match a sequence of94 identify the matched pattern; and ``\d+`` is a regular expression to match a sequence of 95 95 digits (i.e., a number). 96 96 django/branches/multiple-db-support/docs/tutorial04.txt
r3502 r4152 208 208 209 209 In 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,210 that contains the ``poll`` and ``latest_poll_list`` context variables. However, 211 211 the generic views provide the variables ``object`` and ``object_list`` as context. 212 212 Therefore, you need to change your templates to match the new context variables.
