'After DB I/O'

@staticmethod
def cap_info_onaccept(form):

    if ('vars' in form):
        form_vars = form.vars
    elif ('id' in form):
        form_vars = form
    elif hasattr(form, 'vars'):
        form_vars = form.vars
    else:
        form_vars = form
    info_id = form_vars.id
    if (not info_id):
        return
    db = current.db
    atable = db.cap_alert
    itable = db.cap_info
    info = db((itable.id == info_id)).select(itable.language, itable.alert_id, itable.event, itable.event_type_id, itable.event_code, itable.audience, limitby=(0, 1)).first()
    if info:
        alert_id = info.alert_id
        irows = db((itable.alert_id == alert_id)).select(itable.language)
        if (len(irows) > 2):
            db((itable.id == info_id)).delete()
            current.session.error = current.T('An    alert    can    contain    maximum    of    two    info    segments!    Please    edit    already    created    info    segments!')
            redirect(URL(c='cap', f='alert', args=[alert_id, 'info']))
        else:
            if (len(irows) == 2):
                if (irows[0]['language'] == irows[1]['language']):
                    db((itable.id == info_id)).delete()
                    current.session.error = current.T('Please    edit    already    created    info    segment    with    same    language!')
                    redirect(URL(c='cap', f='alert', args=[alert_id, 'info']))
            if (not all(((language in [key for key in current.deployment_settings.get_L10n_languages()]) for language in [irow.language for irow in irows]))):
                db((itable.id == info_id)).delete()
                current.session.error = current.T('An    alert    cannot    contain    other    than    English    and    Local    Language!    Check    your    selection!')
                redirect(URL(c='cap', f='alert', args=[alert_id, 'info']))
        set_ = db((itable.id == info_id))
        if (alert_id and cap_alert_is_template(alert_id)):
            set_.update(is_template=True)
        if (not info.event):
            set_.update(event=current.db.cap_info.event_type_id.represent(info.event_type_id))
        event_code = info.event_code
        if (event_code and (('|{' in event_code) or ('||' in event_code))):
            fstring = json_formatter(event_code)
            set_.update(event_code=fstring)
        audience = info.audience
        if ((not audience) or (audience == current.messages['NONE'])):
            set_.update(audience=None)
        if (info.language == 'en'):
            set_.update(language='en-US')
        row = db((atable.id == alert_id)).select(atable.scope, limitby=(0, 1)).first()
        if (row and (row.scope == 'Public')):
            fn = 'public'
        else:
            fn = 'alert'
        web = ('%s%s' % (current.deployment_settings.get_base_public_url(), URL(c='cap', f=fn, args=[alert_id])))
        form_vars_get = form_vars.get
        form_effective = form_vars_get('effective', current.request.now)
        form_expires = form_vars_get('expires', cap_expirydate())
        form_onset = form_vars_get('onset', form_effective)
        idata = {'priority': form_vars_get('priority', None), 'urgency': form_vars_get('urgency', None), 'severity': form_vars_get('severity', None), 'certainty': form_vars_get('certainty', None), 'effective': form_effective, 'onset': form_onset, 'expires': form_expires, 'web': web, 'event_type_id': form_vars_get('event_type_id', None), 'category': form_vars_get('category', None), 'response_type': form_vars_get('response_type', None)}
        query = ((itable.deleted != True) & (itable.alert_id == alert_id))
        rows = db(query).select(itable.id)
        for row in rows:
            if (int(row.id) == int(info_id)):
                row.update_record(web=web, effective=form_effective, expires=form_expires, onset=form_onset)
            else:
                row.update_record(**idata)
