Changeset 2936

Show
Ignore:
Timestamp:
02/21/07 14:49:55 (2 years ago)
Author:
mscott
Message:

Calling extent transaction methods

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/mscott/SchevoPylonsNav/trunk/schevopylonsnav/config/routing.py

    r2935 r2936  
    3030                 name_prefix='extent_', 
    3131                 ) 
     32 
     33    map.resource('transaction', 'transactions') 
    3234     
    3335    map.resource('transaction', 'transactions', 
     
    3739                 member=dict(call='POST'), 
    3840                 ) 
    39  
     41                  
    4042    map.connect(':controller/:action/:id') 
    4143    map.connect('*url', controller='template', action='view') 
    4244 
    4345    return map 
     46\ 
  • sandbox/mscott/SchevoPylonsNav/trunk/schevopylonsnav/controllers/extent_transactions.py

    r2935 r2936  
    1919        """POST /id;call: Call the transaction method.""" 
    2020        # url_for('call_extent_transaction', id=ID) 
    21         pass 
     21        db = self.dbs[db_id] 
     22        extent = db.extent(extent_id) 
     23        method = extent.t[id] 
     24        tx = method() 
     25        tx_cache = g.tx_cache 
     26        token = g.new_cache_token(tx_cache) 
     27        tx_cache[token] = tx 
     28        return redirect_to(h.url_for('transaction', id=token)) 
    2229     
    2330    def create(self): 
  • sandbox/mscott/SchevoPylonsNav/trunk/schevopylonsnav/lib/app_globals.py

    r2929 r2936  
     1from random import randint 
     2 
     3from lrucache import LRUCache 
     4 
     5 
     6def random_token(): 
     7    return randint(0, 9999999) 
     8 
     9 
    110class Globals(object): 
    211 
     
    2635             
    2736        """ 
    28         pass 
     37        self.tx_cache = LRUCache(size=2048) 
     38        self.cache_tokens = set() 
    2939         
    3040    def __del__(self): 
     
    3444        """ 
    3545        pass 
     46 
     47    def new_cache_token(self, cache): 
     48        cache_tokens = self.cache_tokens 
     49        while True: 
     50            # Search for an unused token. 
     51            t = random_token() 
     52            while t in cache_tokens: 
     53                t = random_token() 
     54            # Place a 'hold' on the token. 
     55            cache_tokens.add(t) 
     56            if t in cache: 
     57                # Release hold. 
     58                cache_tokens.remove(t) 
     59                # Start over. 
     60                continue 
     61            # Place the token in the cache and release hold. 
     62            cache[t] = None 
     63            cache_tokens.remove(t) 
     64            return t 
  • sandbox/mscott/SchevoPylonsNav/trunk/schevopylonsnav/tests/functional/test_extent_transactions.py

    r2935 r2936  
    99        assert 'Create' in response 
    1010 
    11     def test_create(self): 
     11    def test_get_create(self): 
    1212        response = self.app.get( 
    1313            url_for('extent_transaction', db_id='db', extent_id='Foo', 
    1414            id='create')) 
    1515        assert 'Call' in response 
     16 
     17    def test_call_create(self): 
     18        response = self.app.post( 
     19            url_for('extent_call_transaction', db_id='db', extent_id='Foo', 
     20            id='create')) 
     21        assert response.status == 302 
     22        # response = response.follow() 
  • sandbox/mscott/SchevoPylonsNav/trunk/setup.py

    r2932 r2936  
    2727    'SchevoWsgi==dev,>=0.1a1dev-r2820', 
    2828    'Mako', 
     29    'lrucache', 
    2930    ], 
    3031     
    3132    dependency_links = [ 
    3233    'http://schevo.org/wiki/ThirdPartyEggs', 
     34    'http://evan.prodromou.name/Software/Python/LRUCache', 
    3335    ], 
    3436