Create a participant.

    This route will be hit very early on as any nodes the participant creates
    will be defined in reference to the participant object.
    You must specify the worker_id, hit_id, assignment_id and mode in the url.

def create_participant(worker_id, hit_id, assignment_id, mode):
    """Create a participant.

    This route will be hit very early on as any nodes the participant creates
    will be defined in reference to the participant object.
    You must specify the worker_id, hit_id, assignment_id and mode in the url.
    """
    # check this worker hasn't already taken part
    parts = models.Participant.query.filter_by(worker_id=worker_id).all()
    if parts:
        print "participant already exists!"
        return Response(status=200)

    # make the participant
    participant = models.Participant(worker_id=worker_id,
                                     assignment_id=assignment_id,
                                     hit_id=hit_id,
                                     mode=mode)
    session.add(participant)
    session.commit()

    # make a psiturk participant too, for now
    from psiturk.models import Participant as PsiturkParticipant
    psiturk_participant = PsiturkParticipant(workerid=worker_id,
                                             assignmentid=assignment_id,
                                             hitid=hit_id)
    session_psiturk.add(psiturk_participant)
    session_psiturk.commit()

    # return the data
    return success_response(field="participant",
                            data=participant.__json__(),
                            request_type="participant post")