Example #1
0
def insert_trigger_for_paths(f, given_path_id):
    path_id = int(given_path_id)
    local_f = f
    if (dict != type(local_f)):
        local_f = local_f.as_dict()
    # delete all steps_inactive_locations data for this path
    old_steps_list = [s['step_id'] for s
                      in db(db.path2steps.path_id == given_path_id
                            ).select(db.path2steps.step_id).as_list()]
    db(db.steps_inactive_locations.step_id.belongs(old_steps_list)).delete()
    new_steps_list = []
    if 'steps' in local_f:
        step_ids = local_f['steps']
        for step_id in step_ids:
            new_steps_list.append(step_id)
            if db(db.steps.id == step_id).count() > 0:
                db.path2steps.insert(step_id=step_id, path_id=path_id)
            else:
                simple_obj_print(step_id, "orphan step:")
            db.commit()
    old_steps_list.extend(new_steps_list)
    for step_id in old_steps_list:
        step_locs = db.steps[step_id].as_dict()['locations']
        create_or_update_steps_inactive_locations({'locations': step_locs},
                                                  step_id)
Example #2
0
def after_update_trigger_for_locations(s, f):
    local_f = f
    if (dict != type(local_f)):
        local_f = local_f.as_dict()
    simple_obj_print(local_f, 'new rochelle local_f is: ')
    if (('loc_active' in local_f) and (local_f['loc_active'])):
        for r in s.select():
            db(db.steps_inactive_locations.loc_id == r.id).delete()
        db.commit()
    # just set to inactive
    if (('loc_active' in local_f) and (not local_f['loc_active'])):
        # get all steps
        steps = db(db.steps.id > 0
                   ).select(db.steps.id, db.steps.locations).as_list()
        for r in s.select():
            for step in steps:
                while True:
                    locs = step['locations']
                    if (not locs):
                        break
                    if not(r.id in locs):
                        break
                    create_or_update_steps_inactive_locations({'locations':
                                                               locs},
                                                              step['id'])
                    break
Example #3
0
def insert_trigger_for_steps(f, given_step_id):
    # given_step_id is of <class 'gluon.dal.Reference'>
    step_id = int(given_step_id)
    local_f = f
    if (dict != type(local_f)):
        local_f = local_f.as_dict()
    if 'tags' in local_f:
        tag_ids = local_f['tags']
        for tag_id in tag_ids:
            if db(db.tags.id == tag_id).count() > 0:
                db.step2tags.insert(tag_id=tag_id, step_id=step_id)
            else:
                simple_obj_print(tag_id, "orphan tag:")
        db.commit()
    create_or_update_steps_inactive_locations(f, given_step_id)
Example #4
0
def create_or_update_steps_inactive_locations(f, given_step_id):
    step_id = int(given_step_id)
    local_f = f
    if (dict != type(local_f)):
        local_f = local_f.as_dict()
    # delete everything for this step first
    db((db.steps_inactive_locations.step_id == step_id)).delete()
    if 'locations' in local_f:
        while True:
            loc_ids = local_f['locations']
            if (not loc_ids):
                break
            bad_loc_ids = []
            on_to_the_next = True
            for loc_id in loc_ids:
                if db((db.locations.id == loc_id) &
                      (db.locations.loc_active == 'T')
                      ).count() == 1:
                    on_to_the_next = False
                    break
                else:
                    bad_loc_ids.append(loc_id)
            if not on_to_the_next:
                break
            for loc_id in bad_loc_ids:
                db((db.steps_inactive_locations.loc_id == loc_id) &
                   (db.steps_inactive_locations.step_id == step_id)
                   ).delete()
                loc_data = {}
                loc_data['step_id'] = step_id
                loc_data['loc_id'] = loc_id
                get_steps_inactive_locations_fields(loc_data)
                simple_obj_print(loc_data, "troy: loc data")
                db.steps_inactive_locations.insert(
                    loc_id=loc_data['loc_id'],
                    step_id=loc_data['step_id'],
                    step_desc=loc_data['step_desc'],
                    loc_desc=loc_data['loc_desc'],
                    in_paths=loc_data['in_paths'])
            break  # from while true
    db.commit()