Changeset 506

Show
Ignore:
Timestamp:
08/05/07 01:14:23 (1 year ago)
Author:
brian
Message:

taking out our before_update (which was only for issuing warnings/errors)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pagoda/trunk/Pagoda/pagoda/models/revision_mapper.py

    r505 r506  
    237237        session._register_persistent(instance) 
    238238 
    239     def before_update(self, mapper, connection, instance): 
    240         """ 
    241         Inspect the column changes that triggered this update, and 
    242         raise an exception if a key has been changed, issue warnings if 
    243         content columns have been changed, and perform updates if metadata 
    244         columns have been changed. 
    245          
    246         """ 
    247         # `original_data` is a mapping of the column names and their values 
    248         # before any modifications of `instance` were made. 
    249         original_data = instance._state['original'].data 
    250          
    251         def is_key_column(column): 
    252             """ 
    253             Determine if `column` is, or points to, a primary key of 
    254             one of the shared tables involved in the revision model. 
    255             """ 
    256             key_tables = [revision_table, content_table, node_table] 
    257             return ( 
    258                 column.primary_key or ( 
    259                     column.foreign_key and  
    260                     column.foreign_key.column.table in key_tables 
    261                 ) 
    262             ) 
    263          
    264         def is_content_column(column): 
    265             """Determine if `column` is from a revisioned content table.""" 
    266             node_table = get_column_table(mapper.c.node_revision_id) 
    267             generic_table = get_column_table(mapper.c.generic_revision_id) 
    268             localized_table = get_column_table(mapper.c.localized_revision_id) 
    269             content_tables = [node_table, generic_table, localized_table] 
    270             return get_column_table(column) in content_tables 
    271          
    272         # For each column in `instance`, determine if it was modified, 
    273         # and raise an exception or issue warnings if the column is a key 
    274         # or metadata, respectively. 
    275         for column_name, original_value in original_data.iteritems(): 
    276             new_value = getattr(instance, column_name, None) 
    277             # Check if the column was modified... 
    278             if new_value != original_value: 
    279                 column = mapper.c[column_name] 
    280                 if is_key_column(column): 
    281                     raise KeyModifiedError( 
    282                         "Cannot modify key column %s!" % column.name 
    283                     ) 
    284                 elif is_content_column(column): 
    285                     import warnings 
    286                     warnings.warn( 
    287                         "Content column %s was modified and will be " 
    288                         "updated, are you sure you didn't mean to make " 
    289                         "a new revision?" % column.name, 
    290                         ContentModifiedWarning 
    291                     ) 
    292          
    293         return EXT_PASS 
    294  
    295239def revision_mapper(ctx, class_, *args, **kwargs): 
    296240    """ 

Log in as guest/pagoda to create tickets