'Ensure the Activity Location is a Project Location with the
Activity\'s Activity Types in (as a minimum).
@ToDo: deployment_setting to allow project Locations to be
read-only & have data editable only at the Activity level'

@staticmethod
def project_activity_activity_type_onaccept(form):

    db = current.db
    form_vars_get = form.vars.get
    activity_id = form_vars_get('activity_id')
    atable = db.project_activity
    activity = db((atable.id == activity_id)).select(atable.project_id, atable.location_id, limitby=(0, 1)).first()
    try:
        project_id = activity.project_id
        location_id = activity.location_id
    except:
        return
    if ((not project_id) or (not location_id)):
        return
    s3db = current.s3db
    ltable = s3db.project_location
    query = ((ltable.project_id == project_id) & (ltable.location_id == location_id))
    location = db(query).select(ltable.id, limitby=(0, 1)).first()
    if location:
        pl_id = location.id
    else:
        pl_id = ltable.insert(project_id=project_id, location_id=location_id)
    activity_type_id = form_vars_get('activity_type_id')
    latable = s3db.project_activity_type_location
    query = ((latable.project_location_id == pl_id) & (latable.activity_type_id == activity_type_id))
    exists = db(query).select(latable.id, limitby=(0, 1)).first()
    if (not exists):
        latable.insert(project_location_id=pl_id, activity_type_id=activity_type_id)
