'- Link alert_id for non-template area
- for external alerts (from import feed or rss), make sure the
locations are only imported if we set polygons to be imported'

@staticmethod
def cap_area_location_onaccept(form):

    form_vars = form.vars
    area_id = form_vars.get('area_id', None)
    if (not area_id):
        return
    db = current.db
    alert_id = form_vars.get('alert_id', None)
    if (not alert_id):
        atable = db.cap_area
        row = db((atable.id == area_id)).select(atable.alert_id, limitby=(0, 1)).first()
        alert_id = (row.alert_id or None)
    if alert_id:
        location_default = current.deployment_settings.get_cap_area_default()
        if ('polygon' not in location_default):
            table = current.s3db.cap_alert
            row = db((table.id == alert_id)).select(table.external, limitby=(0, 1)).first()
            if row.external:
                db((db.cap_area_location.id == form_vars['id'])).delete()
                return
        db((db.cap_area_location.id == form_vars['id'])).update(alert_id=alert_id)
