mirror of
https://github.com/django/django.git
synced 2024-11-29 22:56:46 +01:00
Ported layermapping for autocommit.
This commit is contained in:
parent
3710a918b2
commit
1adb7b3c38
@ -59,11 +59,6 @@ class LayerMapping(object):
|
|||||||
models.PositiveSmallIntegerField : (OFTInteger, OFTReal, OFTString),
|
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,
|
def __init__(self, model, data, mapping, layer=0,
|
||||||
source_srs=None, encoding='utf-8',
|
source_srs=None, encoding='utf-8',
|
||||||
transaction_mode='commit_on_success',
|
transaction_mode='commit_on_success',
|
||||||
@ -127,9 +122,11 @@ class LayerMapping(object):
|
|||||||
|
|
||||||
# Setting the transaction decorator with the function in the
|
# Setting the transaction decorator with the function in the
|
||||||
# transaction modes dictionary.
|
# transaction modes dictionary.
|
||||||
if transaction_mode in self.TRANSACTION_MODES:
|
self.transaction_mode = transaction_mode
|
||||||
self.transaction_decorator = self.TRANSACTION_MODES[transaction_mode]
|
if transaction_mode == 'autocommit':
|
||||||
self.transaction_mode = transaction_mode
|
self.transaction_decorator = None
|
||||||
|
elif transaction_mode == 'commit_on_success':
|
||||||
|
self.transaction_decorator = transaction.atomic
|
||||||
else:
|
else:
|
||||||
raise LayerMapError('Unrecognized transaction mode: %s' % transaction_mode)
|
raise LayerMapError('Unrecognized transaction mode: %s' % transaction_mode)
|
||||||
|
|
||||||
@ -501,9 +498,6 @@ class LayerMapping(object):
|
|||||||
else:
|
else:
|
||||||
progress_interval = progress
|
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):
|
def _save(feat_range=default_range, num_feat=0, num_saved=0):
|
||||||
if feat_range:
|
if feat_range:
|
||||||
layer_iter = self.layer[feat_range]
|
layer_iter = self.layer[feat_range]
|
||||||
@ -572,6 +566,9 @@ class LayerMapping(object):
|
|||||||
# values returned here.
|
# values returned here.
|
||||||
return num_saved, num_feat
|
return num_saved, num_feat
|
||||||
|
|
||||||
|
if self.transaction_decorator is not None:
|
||||||
|
_save = self.transaction_decorator(_save)
|
||||||
|
|
||||||
nfeat = self.layer.num_feat
|
nfeat = self.layer.num_feat
|
||||||
if step and isinstance(step, int) and step < nfeat:
|
if step and isinstance(step, int) and step < nfeat:
|
||||||
# Incremental saving is requested at the given interval (step)
|
# Incremental saving is requested at the given interval (step)
|
||||||
|
Loading…
Reference in New Issue
Block a user