'Validation callback for work assignments:
- a worker can only be assigned once to the same job
@param form: the FORM'

@staticmethod
def assignment_onvalidation(form):

    db = current.db
    s3db = current.s3db
    table = s3db.work_assignment
    form_vars = form.vars
    if ('id' in form_vars):
        record_id = form_vars.id
    elif hasattr(form, 'record_id'):
        record_id = form.record_id
    else:
        record_id = None
    try:
        job_id = form_vars.job_id
    except AttributeError:
        job_id = None
    try:
        person_id = form_vars.person_id
    except AttributeError:
        person_id = None
    if ((job_id is None) or (person_id is None)):
        if record_id:
            query = ((table.id == record_id) & (table.deleted != True))
            record = db(query).select(table.job_id, table.person_id, limitby=(0, 1)).first()
            if record:
                job_id = record.job_id
                person_id = record.person_id
        else:
            if (job_id is None):
                job_id = table.job_id.default
            if (person_id is None):
                person_id = table.person_id.default
    if (job_id and person_id):
        query = (((table.job_id == job_id) & (table.person_id == person_id)) & (table.deleted != True))
        if record_id:
            query = ((table.id != record_id) & query)
        duplicate = db(query).select(table.id, limitby=(0, 1)).first()
        if duplicate:
            msg = current.T('This    person    is    already    assigned    to    the    job')
            form.errors['person_id'] = msg
