Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
 def form_to_dao(self, playground_id):
   playground = None
   if playground_id is not None  and len(playground_id) > 1:
     playground = self.playgroundDao.get_record(long(playground_id))
   else:
     playground = Playground()
   playground.name = self.form.name.data
   playground.sport = self.form.sport.data.lower()
   #Create an automatic alias for the playground
   playground.alias = utils.slugify(self.form.name.data)
   playground.description = self.form.description.data
   playground.featured = self.form.featured.data
   self.form.address.locality.data = self.form.locality.data   #for locality from basic info to address
   self.form.address.city.data = self.form.city.data   #for city from basic info to address
   playground = cms_utils.form_to_dao_address(self.form, playground)
   playground = cms_utils.form_to_dao_contact_info(self.form, playground)
   return playground
Exemplo n.º 4
0
 def form_to_dao_ground(self, alias_name, **update):
     try:
         playground = Playground()
         playground.name = update['name']
         #Create an automatic alias for the playground
         playground.alias = alias_name
         playground.description = update['description']
         playground.sport = update['sport']
         playground = self.form_to_dao_address_import(playground, **update)
         playground = self.form_to_dao_contact_info_import(
             playground, **update)
         #if playground.photos is None:
         #playground.photos = []
         #self.upload_photos(playground.photos)
     except StandardError as e:
         logger.error('Error occured, %s, for %s:%s' %
                      (str(e), type, update['name']))
         raise
     return playground
Exemplo n.º 5
0
 def test_no_value(self):
     with pytest.raises(Exception) as e_info:
         obj = Playground()
Exemplo n.º 6
0
 def setUp(self):
     self.obj_1 = Playground(5)