def process_insert(record): """ Process a single insert record from changes.json. """ playground = Playground() new_data = {} for key, value in record['playground'].items(): if key not in ['id', 'features']: new_data[key] = value setattr(playground, key, value) playground.save() revisions = [] for key, value in new_data.items(): revisions.append({'field': key, 'from': '', 'to': new_data[key]}) for feature in record['playground']['features']: PlaygroundFeature.create(slug=feature, playground=playground) revisions.append({'field': feature, 'from': 0, 'to': 1}) return (playground, revisions)
def process_insert(record): """ Process a single insert record from changes.json. """ playground = Playground() new_data = {} for key, value in record['playground'].items(): if key not in ['id', 'features']: new_data[key] = value setattr(playground, key, value) playground.save() revisions = [] for key, value in new_data.items(): revisions.append({ 'field': key, 'from': '', 'to': new_data[key] }) for feature in record['playground']['features']: PlaygroundFeature.create( slug=feature, playground=playground ) revisions.append({'field': feature, 'from': 0, 'to': 1}) return (playground, revisions)
def process_insert(record): """ Process a single insert record from changes.json. """ playground = Playground() record_dict = {} # Loop through each of the key/value pairs in the playground record. for key, value in record['playground'].items(): # Ignore some keys because they aren't really what we want to update. if key not in ['id', 'features']: # Update the record_dict with our new key/value pair. record_dict[key] = value setattr(playground, key, value) playground.save() # Create a list of revisions that were applied. revisions = [] # Our old data was captured up top. It's called old_ # This is the new It's just the record_dict from above. new_data = record_dict # Loop over the key/value pairs in the new data we have. for key, value in new_data.items(): # Set up an intermediate data structure for the revision. revision_dict = {} # Set up the data for this revision. revision_dict['field'] = key revision_dict['from'] = '' revision_dict['to'] = new_data[key] # Append it to the revisions list. revisions.append(revision_dict) # Check to see if we have any incoming features. try: features = record['playground']['features'] except KeyError: features = [] for feature in features: PlaygroundFeature.create( slug=feature, playground=playground ) revisions.append({'field': feature, 'from': 0, 'to': 1}) return (playground, revisions)
def process_insert(record): """ Process a single insert record from changes.json. """ playground = Playground() record_dict = {} # Loop through each of the key/value pairs in the playground record. for key, value in record['playground'].items(): # Ignore some keys because they aren't really what we want to update. if key not in ['id', 'features']: # Update the record_dict with our new key/value pair. record_dict[key] = value setattr(playground, key, value) playground.save() # Create a list of revisions that were applied. revisions = [] # Our old data was captured up top. It's called old_ # This is the new It's just the record_dict from above. new_data = record_dict # Loop over the key/value pairs in the new data we have. for key, value in new_data.items(): # Set up an intermediate data structure for the revision. revision_dict = {} # Set up the data for this revision. revision_dict['field'] = key revision_dict['from'] = '' revision_dict['to'] = new_data[key] # Append it to the revisions list. revisions.append(revision_dict) # Check to see if we have any incoming features. try: features = record['playground']['features'] except KeyError: features = [] for feature in features: PlaygroundFeature.create(slug=feature, playground=playground) revisions.append({'field': feature, 'from': 0, 'to': 1}) return (playground, revisions)