Beispiel #1
0
def newcampaign():
    """
    Create a new campaign. 

    MTurk jobs are spawned after the campaign is created.
    """
    form = NewCampaignForm(request.form)
    if request.method == 'POST' and form.validate():
        # Add the campaign itself
        campaign = Campaign(form.title.data, 
                            form.question.data, 
                            form.terms_per_quiz.data, 
                            form.reward.data, 
                            form.times_per_term.data)
        db.session.add(campaign)

        # Add the options 
        options = re.split(r'[\n\r]+', form.options.data)
        for option in options:
            if len(option) > 0:
                campaign_option = CampaignOption(campaign, option)
                db.session.add(campaign_option)

        # Add the terms
        terms = re.split(r'[\n\r]+', form.terms.data)
        for term in terms:
            if len(term) > 0:
                campaign_term = CampaignTerm(campaign, term)
                db.session.add(campaign_term)

        # Save everything to the db
        db.session.commit()
        return redirect(url_for('campaigndetails',id=campaign.id))
    return render_template('newcampaign.html',form=form)
Beispiel #2
0
def clonecampaign(id):
    """
    Clone a campaign from an existing campaign
    """
    campaign = Campaign.query.filter_by(id=id).first_or_404()
    form = NewCampaignForm(request.form, obj=campaign)

    allterms = [str(term.term) for term in campaign.terms]

    results = campaign.get_results()
    inconclusiveterms = [str(answer.term) for answer in results if answer.is_inconclusive()]

    if request.method == 'POST' and form.validate():
        # Add the campaign itself
        campaign = Campaign(form.title.data, 
                            form.question.data, 
                            form.terms_per_quiz.data, 
                            form.reward.data, 
                            form.times_per_term.data)
        db.session.add(campaign)

        # Add the options 
        options = re.split(r'[\n\r]+', form.options.data)
        for option in options:
            if len(option) > 0:
                campaign_option = CampaignOption(campaign, option)
                db.session.add(campaign_option)

        # Add the terms
        terms = re.split(r'[\n\r]+', form.terms.data)
        for term in terms:
            if len(term) > 0:
                campaign_term = CampaignTerm(campaign, term)
                db.session.add(campaign_term)

        # Save everything to the db
        db.session.commit()
        return redirect(url_for('campaigndetails',id=campaign.id))

    return render_template('clonecampaign.html',
                           original_campaign=campaign,
                           allterms=allterms,
                           inconclusiveterms=inconclusiveterms,
                           form=form)