Exemplo n.º 1
0
 def test_check_for_recent_found(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     limit = pytz.utc.localize(datetime.utcnow())
     Dispatcher.create(
         campaign_id=d.campaign_id,
         created_at=limit,
         account_id=d.account_id,
         user_id=d.user_id,
         list_id=d.list_id
     )
     limit = limit - timedelta(minutes=5) # so d doesn't trip it
     d.update(created_at=limit)
     self.assertEqual(d.check_for_recent(d.campaign_id), True)
Exemplo n.º 2
0
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))