@app.route("<STR_LIT>", methods=["<STR_LIT:GET>"])<EOL>@nocache<EOL>def advertisement():
if not ("<STR_LIT>" in request.args and "<STR_LIT>" in request.args):<EOL><INDENT>raise ExperimentError("<STR_LIT>")<EOL><DEDENT>config = _config()<EOL>browser = ValidatesBrowser(config)<EOL>if not browser.is_supported(request.user_agent.string):<EOL><INDENT>raise ExperimentError("<STR_LIT>")<EOL><DEDENT>hit_id = request.args["<STR_LIT>"]<EOL>assignment_id = request.args["<STR_LIT>"]<EOL>app_id = config.get("<STR_LIT:id>", "<STR_LIT>")<EOL>mode = config.get("<STR_LIT>")<EOL>debug_mode = mode == "<STR_LIT>"<EOL>worker_id = request.args.get("<STR_LIT>")<EOL>participant = None<EOL>if worker_id is not None:<EOL><INDENT>already_participated = bool(<EOL>models.Participant.query.filter(<EOL>models.Participant.assignment_id != assignment_id<EOL>)<EOL>.filter(models.Participant.worker_id == worker_id)<EOL>.count()<EOL>)<EOL>if already_participated and not debug_mode:<EOL><INDENT>raise ExperimentError("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>participant = (<EOL>models.Participant.query.filter(models.Participant.hit_id == hit_id)<EOL>.filter(models.Participant.assignment_id == assignment_id)<EOL>.filter(models.Participant.worker_id == worker_id)<EOL>.one()<EOL>)<EOL><DEDENT>except exc.SQLAlchemyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>recruiter_name = request.args.get("<STR_LIT>")<EOL>if recruiter_name:<EOL><INDENT>recruiter = recruiters.by_name(recruiter_name)<EOL><DEDENT>else:<EOL><INDENT>recruiter = recruiters.from_config(config)<EOL>recruiter_name = recruiter.nickname<EOL><DEDENT>if should_show_thanks_page_to(participant):<EOL><INDENT>return render_template(<EOL>"<STR_LIT>",<EOL>hitid=hit_id,<EOL>assignmentid=assignment_id,<EOL>workerid=worker_id,<EOL>external_submit_url=recruiter.external_submission_url,<EOL>mode=config.get("<STR_LIT>"),<EOL>app_id=app_id,<EOL>)<EOL><DEDENT>if participant and participant.status == "<STR_LIT>":<EOL><INDENT>raise ExperimentError("<STR_LIT>")<EOL><DEDENT>return render_template(<EOL>"<STR_LIT>",<EOL>recruiter=recruiter_name,<EOL>hitid=hit_id,<EOL>assignmentid=assignment_id,<EOL>workerid=worker_id,<EOL>mode=config.get("<STR_LIT>"),<EOL>app_id=app_id,<EOL>)<EOL>
This is the url we give for the ad for our 'external question'.  The ad has
to display two different things: This page will be called from within
mechanical turk, with url arguments hitId, assignmentId, and workerId.
If the worker has not yet accepted the hit:
    These arguments will have null values, we should just show an ad for
    the experiment.
If the worker has accepted the hit:
    These arguments will have appropriate values and we should enter the
    person in the database and provide a link to the experiment popup.