def update(campaign_id=None): form = CampaignForm(request.form) list_id = request.form.get('list_id', None) form = setup_campaign_select_choices(form, list_id) campaign = Campaign.find_by_id(campaign_id) if form.validate_on_submit(): params = { 'name': form.name.data, 'from_email_dd': form.from_email_dd.data, 'from_name_dd': form.from_name_dd.data, 'reply_to_dd': form.reply_to_dd.data, 'to_email_dd': form.to_email_dd.data, 'to_name_dd': form.to_name_dd.data, 'from_email_ov': form.from_email_ov.data, 'from_name_ov': form.from_name_ov.data, 'reply_to_ov': form.reply_to_ov.data, 'to_email_ov': form.to_email_ov.data, 'to_name_ov': form.to_name_ov.data, 'selector_col_name': form.selector_col_name.data } if campaign.selector_col_name and campaign.selector_col_name != params['selector_col_name']: flash("Selector column changed, all emails have had selector values removed.", 'warning') for email in campaign.emails: email.update(selector_col_val=None) campaign.update(**params) flash('Campaign Updated') return redirect(url_for('campaign.edit', campaign_id=campaign.id)) flash_errors(form) list_form = CampaignListForm() list_form.list_id.choices = [('','')] + [(str(h.id), h.name) for h in List.find_all()] return render_template('campaign/edit.html', form=form, campaign=campaign, list_form=list_form)
def submit(list_id=None): l = List.find_by_id(list_id) form = ListForm(request.form) if form.validate_on_submit(): if l: l.update(name=form.name.data) flash('List Updated') return redirect(url_for('list_.index')) else: l = List.create(name=form.name.data, account_id=current_user.account_id) if l: flash('List Created') return redirect(url_for('list_.edit', list_id=l.id)) else: page = int(request.args.get('page', 1)) flash_errors(form) pagination = List.find_all_desc().paginate(page=page, per_page=20) return render_template('list/index.html', form=form, list=l, user=current_user, pagination=pagination)
def submit_dispatch(campaign_id): campaign = Campaign.find_by_id(campaign_id) if campaign_id else None if not campaign: return abort(404) form = DispatcherConfirmForm(request.form) form.send_at.data = datetime.strptime(form.send_at.data, '%Y-%m-%d %H:%M:%S') if form.send_at.data else None if form.validate_on_submit(): params = { 'campaign_id': campaign.id, 'account_id': current_user.account_id, 'user_id': current_user.id, 'list_id': campaign.list_id, 'import_data': campaign.list_.import_data } if form.submit_send_at.data: params['send_at'] = form.send_at.data params['state'] = 15 scheduled = 1 else: params['send_at'] = None scheduled = 0 d = Dispatcher.create(**params) if d and d.id: if not d.send_at: d.send() # fire emails => celery return redirect(url_for('campaign.success', campaign_id=campaign_id, scheduled=scheduled)) else: flash('There was an error beginning the send, none have been sent.', 'warning') else: flash_errors(form) return redirect(url_for('campaign.edit', campaign_id=campaign_id))
def submit_default_from(): form = DefaultFromEmail(request.form) if form.validate_on_submit(): current_user.account.update( **{'default_from_email': form.default_from_email.data}) flash("Default From address updated") else: flash_errors(form) return redirect(url_for('account.index'))
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 footer(): account = current_user.account form = FooterForm(obj=account) if not form.footer_html.data: form.footer_html.data = DEFAULT_FOOTER if request.method == 'POST': if form.validate_on_submit(): account.update( **{ 'footer_html': form.footer_html.data, 'footer_text': form.footer_text.data }) flash("Updated") else: flash_errors(form) return render_template('account/footer.html', user=current_user, form=form, auto_text=account.auto_text)
def update(campaign_id=None, email_id=None): campaign = Campaign.find_by_id(campaign_id) if campaign_id else None if not campaign: return abort(404) email = Email.find_by_id(email_id) if not email: return abort(404) form = EditEmailForm(request.form) if campaign.list_id: keys = campaign.list_.get_import_data_keys() form.selector_col_val.choices = campaign.list_.get_unique_col_values( campaign.selector_col_name, True) else: keys = [] if form.validate_on_submit(): params = { 'name': form.name.data, 'subject': form.subject.data, 'preheader': form.preheader.data, 'html': form.html.data, 'text': form.text.data, 'selector_col_val': json.dumps(filter(None, form.selector_col_val.data)) } email.update(**params) flash('Email Updated') return redirect( url_for('email.edit', email_id=email.id, campaign_id=campaign.id)) flash_errors(form) return render_template('email/new.html', form=form, campaign=campaign, email=email, keys=keys)
def create(campaign_id=None): campaign = Campaign.find_by_id(campaign_id) if campaign_id else None if not campaign: return abort(404) form = NewEmailForm(request.form) if campaign.list_id: keys = campaign.list_.get_import_data_keys() form.selector_col_val.choices = campaign.list_.get_unique_col_values( campaign.selector_col_name, True) else: keys = [] templates = Template.get_all_choices() if form.validate_on_submit(): params = { 'name': form.name.data, 'subject': form.subject.data, 'preheader': form.preheader.data, 'selector_col_val': form.selector_col_val.data } if form.template.data: params['html'] = Template.get_html(form.template.data) params['account_id'] = current_user.account_id params['campaign_id'] = campaign.id email = Email.create(**params) if email: flash('Email Created') return redirect( url_for('email.edit', email_id=email.id, campaign_id=campaign.id)) flash_errors(form) return render_template('email/new.html', form=form, campaign=campaign, keys=keys, templates=templates)
def confirm_dispatch(campaign_id): campaign = Campaign.find_by_id(campaign_id) if campaign_id else None if not campaign: return abort(404) form = DispatcherForm(request.form) display_time = form.send_at.data.strftime('%m-%d-%Y %I:%M %p') form.send_at.data = form.send_at.data + timedelta(hours=7) # localize utc if not form.validate_on_submit(): flash_errors(form) return redirect(url_for('campaign.dispatcher', campaign_id=campaign.id)) current_form=DispatcherConfirmForm() if form.data.get('submit_now'): current_form.send_at.data = display_time = None else: current_form.send_at.data = form.send_at.data return render_template('campaign/confirm_dispatch.html', campaign=campaign, form=current_form, display_time=display_time )