'After DB I/O'

@staticmethod
def asset_log_onaccept(form):

    request = current.request
    get_vars = request.get_vars
    status = get_vars.get('status', None)
    if (not status):
        if (not current.response.s3.asset_import):
            return
        db = current.db
        form_vars = form.vars
        asset_id = form_vars.asset_id
        status = int(form_vars.status)
        if (status == ASSET_LOG_ASSIGN):
            (type == 'person')
        new = True
    else:
        form_vars = form.vars
        status = int((form_vars.status or status))
        db = current.db
        ltable = db.asset_log
        row = db((ltable.id == form_vars.id)).select(ltable.asset_id, limitby=(0, 1)).first()
        try:
            asset_id = row.asset_id
        except:
            return
        current_log = asset_get_current_log(asset_id)
        type = get_vars.get('type', None)
        log_time = current_log.datetime
        current_time = form_vars.get('datetime', None).replace(tzinfo=None)
        new = (log_time <= current_time)
    if new:
        atable = db.asset_asset
        aitable = db.asset_item
        tracker = S3Tracker()
        asset_tracker = tracker(atable, asset_id)
        if (status == ASSET_LOG_SET_BASE):
            site_id = form_vars.get('site_id', None)
            stable = db.org_site
            location_id = db((stable.site_id == site_id)).select(stable.location_id, limitby=(0, 1)).first().location_id
            asset_tracker.set_base_location(location_id)
            db((aitable.asset_id == asset_id)).update(location_id=location_id)
        elif (status == ASSET_LOG_ASSIGN):
            if (type == 'person'):
                if form_vars.check_in_to_person:
                    asset_tracker.check_in(db.pr_person, form_vars.person_id, timestmp=request.utcnow)
                    locations = asset_tracker.get_location(_fields=[db.gis_location.id])
                    try:
                        db((aitable.asset_id == asset_id)).update(location_id=locations[0].id)
                    except:
                        pass
                else:
                    location_id = asset_tracker.set_location(form_vars.person_id, timestmp=request.utcnow)
                    db((aitable.asset_id == asset_id)).update(location_id=location_id)
                db((atable.id == asset_id)).update(assigned_to_id=form_vars.person_id)
            elif (type == 'site'):
                asset_tracker.check_in(db.org_site, form_vars.site_id, timestmp=request.utcnow)
                locations = asset_tracker.get_location(_fields=[db.gis_location.id])
                try:
                    db((aitable.asset_id == asset_id)).update(location_id=locations[0].id)
                except:
                    pass
            elif (type == 'organisation'):
                site_id = form_vars.get('site_id', None)
                if site_id:
                    asset_tracker.check_in(db.org_site, site_id, timestmp=request.utcnow)
                    locations = asset_tracker.get_location(_fields=[db.gis_location.id])
                    try:
                        db((aitable.asset_id == asset_id)).update(location_id=locations[0].id)
                    except:
                        pass
                else:
                    asset_tracker.check_out()
        elif (status == ASSET_LOG_RETURN):
            location_id = asset_tracker.set_location(asset_tracker, timestmp=request.utcnow)
            db((aitable.asset_id == asset_id)).update(location_id=location_id)
        db((atable.id == asset_id)).update(cond=form_vars.cond)
    return
