Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ported layermapping for autocommit.

  • Loading branch information...
commit 1adb7b3c38641c2e9e346d21555214e7b320b836 1 parent 3710a91
Aymeric Augustin aaugustin authored
Showing with 8 additions and 11 deletions.
  1. +8 −11 django/contrib/gis/utils/layermapping.py
19 django/contrib/gis/utils/layermapping.py
View
@@ -59,11 +59,6 @@ class LayerMapping(object):
models.PositiveSmallIntegerField : (OFTInteger, OFTReal, OFTString),
}
- # The acceptable transaction modes.
- TRANSACTION_MODES = {'autocommit' : transaction.autocommit,
- 'commit_on_success' : transaction.commit_on_success,
- }
-
def __init__(self, model, data, mapping, layer=0,
source_srs=None, encoding='utf-8',
transaction_mode='commit_on_success',
@@ -127,9 +122,11 @@ def __init__(self, model, data, mapping, layer=0,
# Setting the transaction decorator with the function in the
# transaction modes dictionary.
- if transaction_mode in self.TRANSACTION_MODES:
- self.transaction_decorator = self.TRANSACTION_MODES[transaction_mode]
- self.transaction_mode = transaction_mode
+ self.transaction_mode = transaction_mode
+ if transaction_mode == 'autocommit':
+ self.transaction_decorator = None
+ elif transaction_mode == 'commit_on_success':
+ self.transaction_decorator = transaction.atomic
else:
raise LayerMapError('Unrecognized transaction mode: %s' % transaction_mode)
@@ -501,9 +498,6 @@ def save(self, verbose=False, fid_range=False, step=False,
else:
progress_interval = progress
- # Defining the 'real' save method, utilizing the transaction
- # decorator created during initialization.
- @self.transaction_decorator
def _save(feat_range=default_range, num_feat=0, num_saved=0):
if feat_range:
layer_iter = self.layer[feat_range]
@@ -572,6 +566,9 @@ def _save(feat_range=default_range, num_feat=0, num_saved=0):
# values returned here.
return num_saved, num_feat
+ if self.transaction_decorator is not None:
+ _save = self.transaction_decorator(_save)
+
nfeat = self.layer.num_feat
if step and isinstance(step, int) and step < nfeat:
# Incremental saving is requested at the given interval (step)
Please sign in to comment.
Something went wrong with that request. Please try again.