1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

A large number of stylistic cleanups across django/db/

This commit is contained in:
Alex Gaynor
2013-07-08 10:39:54 +10:00
parent 0b69a75502
commit 03d9566e0d
48 changed files with 383 additions and 195 deletions

View File

@@ -27,6 +27,7 @@ class TransactionManagementError(Exception):
"""
pass
################
# Private APIs #
################
@@ -40,6 +41,7 @@ def get_connection(using=None):
using = DEFAULT_DB_ALIAS
return connections[using]
###########################
# Deprecated private APIs #
###########################
@@ -56,6 +58,7 @@ def abort(using=None):
"""
get_connection(using).abort()
def enter_transaction_management(managed=True, using=None, forced=False):
"""
Enters transaction management for a running thread. It must be balanced with
@@ -68,6 +71,7 @@ def enter_transaction_management(managed=True, using=None, forced=False):
"""
get_connection(using).enter_transaction_management(managed, forced)
def leave_transaction_management(using=None):
"""
Leaves transaction management for a running thread. A dirty flag is carried
@@ -76,6 +80,7 @@ def leave_transaction_management(using=None):
"""
get_connection(using).leave_transaction_management()
def is_dirty(using=None):
"""
Returns True if the current transaction requires a commit for changes to
@@ -83,6 +88,7 @@ def is_dirty(using=None):
"""
return get_connection(using).is_dirty()
def set_dirty(using=None):
"""
Sets a dirty flag for the current thread and code streak. This can be used
@@ -91,6 +97,7 @@ def set_dirty(using=None):
"""
get_connection(using).set_dirty()
def set_clean(using=None):
"""
Resets a dirty flag for the current thread and code streak. This can be used
@@ -99,22 +106,27 @@ def set_clean(using=None):
"""
get_connection(using).set_clean()
def is_managed(using=None):
warnings.warn("'is_managed' is deprecated.",
DeprecationWarning, stacklevel=2)
def managed(flag=True, using=None):
warnings.warn("'managed' no longer serves a purpose.",
DeprecationWarning, stacklevel=2)
def commit_unless_managed(using=None):
warnings.warn("'commit_unless_managed' is now a no-op.",
DeprecationWarning, stacklevel=2)
def rollback_unless_managed(using=None):
warnings.warn("'rollback_unless_managed' is now a no-op.",
DeprecationWarning, stacklevel=2)
###############
# Public APIs #
###############
@@ -125,24 +137,28 @@ def get_autocommit(using=None):
"""
return get_connection(using).get_autocommit()
def set_autocommit(autocommit, using=None):
"""
Set the autocommit status of the connection.
"""
return get_connection(using).set_autocommit(autocommit)
def commit(using=None):
"""
Commits a transaction and resets the dirty flag.
"""
get_connection(using).commit()
def rollback(using=None):
"""
Rolls back a transaction and resets the dirty flag.
"""
get_connection(using).rollback()
def savepoint(using=None):
"""
Creates a savepoint (if supported and required by the backend) inside the
@@ -151,6 +167,7 @@ def savepoint(using=None):
"""
return get_connection(using).savepoint()
def savepoint_rollback(sid, using=None):
"""
Rolls back the most recent savepoint (if one exists). Does nothing if
@@ -158,6 +175,7 @@ def savepoint_rollback(sid, using=None):
"""
get_connection(using).savepoint_rollback(sid)
def savepoint_commit(sid, using=None):
"""
Commits the most recent savepoint (if one exists). Does nothing if
@@ -165,18 +183,21 @@ def savepoint_commit(sid, using=None):
"""
get_connection(using).savepoint_commit(sid)
def clean_savepoints(using=None):
"""
Resets the counter used to generate unique savepoint ids in this thread.
"""
get_connection(using).clean_savepoints()
def get_rollback(using=None):
"""
Gets the "needs rollback" flag -- for *advanced use* only.
"""
return get_connection(using).get_rollback()
def set_rollback(rollback, using=None):
"""
Sets or unsets the "needs rollback" flag -- for *advanced use* only.
@@ -191,6 +212,7 @@ def set_rollback(rollback, using=None):
"""
return get_connection(using).set_rollback(rollback)
#################################
# Decorators / context managers #
#################################
@@ -398,6 +420,7 @@ class Transaction(object):
return func(*args, **kwargs)
return inner
def _transaction_func(entering, exiting, using):
"""
Takes 3 things, an entering function (what to do to start this block of
@@ -436,6 +459,7 @@ def autocommit(using=None):
return _transaction_func(entering, exiting, using)
def commit_on_success(using=None):
"""
This decorator activates commit on response. This way, if the view function
@@ -466,6 +490,7 @@ def commit_on_success(using=None):
return _transaction_func(entering, exiting, using)
def commit_manually(using=None):
"""
Decorator that activates manual transaction control. It just disables
@@ -484,6 +509,7 @@ def commit_manually(using=None):
return _transaction_func(entering, exiting, using)
def commit_on_success_unless_managed(using=None, savepoint=False):
"""
Transitory API to preserve backwards-compatibility while refactoring.