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)
def create(campaign_id=None): form = NewCampaignForm(request.form) if form.validate_on_submit(): params = { 'name': form.name.data, 'account_id': current_user.account_id } c = Campaign.create(**params) if c: flash('Campaign Created') return redirect(url_for('campaign.edit', campaign_id=c.id)) flash_errors(form) return redirect(url_for('campaign.index'))
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)
def index(): page = int(request.args.get('page', 1)) pagination = Campaign.find_all_desc().paginate(page=page, per_page=20) form = NewCampaignForm() return render_template('campaign/index.html', user=current_user, pagination=pagination, form=form)