Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Ported layermapping for autocommit.

  • Loading branch information...
commit 1adb7b3c38641c2e9e346d21555214e7b320b836 1 parent 3710a91
Aymeric Augustin authored March 11, 2013

Showing 1 changed file with 8 additions and 11 deletions. Show diff stats Hide diff stats

  1. 19  django/contrib/gis/utils/layermapping.py
19  django/contrib/gis/utils/layermapping.py
@@ -59,11 +59,6 @@ class LayerMapping(object):
59 59
         models.PositiveSmallIntegerField : (OFTInteger, OFTReal, OFTString),
60 60
         }
61 61
 
62  
-    # The acceptable transaction modes.
63  
-    TRANSACTION_MODES = {'autocommit' : transaction.autocommit,
64  
-                         'commit_on_success' : transaction.commit_on_success,
65  
-                         }
66  
-
67 62
     def __init__(self, model, data, mapping, layer=0,
68 63
                  source_srs=None, encoding='utf-8',
69 64
                  transaction_mode='commit_on_success',
@@ -127,9 +122,11 @@ def __init__(self, model, data, mapping, layer=0,
127 122
 
128 123
         # Setting the transaction decorator with the function in the
129 124
         # transaction modes dictionary.
130  
-        if transaction_mode in self.TRANSACTION_MODES:
131  
-            self.transaction_decorator = self.TRANSACTION_MODES[transaction_mode]
132  
-            self.transaction_mode = transaction_mode
  125
+        self.transaction_mode = transaction_mode
  126
+        if transaction_mode == 'autocommit':
  127
+            self.transaction_decorator = None
  128
+        elif transaction_mode == 'commit_on_success':
  129
+            self.transaction_decorator = transaction.atomic
133 130
         else:
134 131
             raise LayerMapError('Unrecognized transaction mode: %s' % transaction_mode)
135 132
 
@@ -501,9 +498,6 @@ def save(self, verbose=False, fid_range=False, step=False,
501 498
             else:
502 499
                 progress_interval = progress
503 500
 
504  
-        # Defining the 'real' save method, utilizing the transaction
505  
-        # decorator created during initialization.
506  
-        @self.transaction_decorator
507 501
         def _save(feat_range=default_range, num_feat=0, num_saved=0):
508 502
             if feat_range:
509 503
                 layer_iter = self.layer[feat_range]
@@ -572,6 +566,9 @@ def _save(feat_range=default_range, num_feat=0, num_saved=0):
572 566
             # values returned here.
573 567
             return num_saved, num_feat
574 568
 
  569
+        if self.transaction_decorator is not None:
  570
+            _save = self.transaction_decorator(_save)
  571
+
575 572
         nfeat = self.layer.num_feat
576 573
         if step and isinstance(step, int) and step < nfeat:
577 574
             # Incremental saving is requested at the given interval (step)

0 notes on commit 1adb7b3

Please sign in to comment.
Something went wrong with that request. Please try again.