Exemplo n.º 1
0
def project_add():
    form = ProjectForm()

    if form.validate_on_submit():
        project = Project()

        form.populate_obj(project)
        try:
            form.create_subscription_for(project)
        except Exception:
            logger.exception('Intercom subscription error')
            flash('Can\'t create subscription on Intercom\'s events. '
                  'Probably you provide an incorrect APP_ID or API_KEY.',
                  'danger')
            return locals()

        project.user_id = current_user.id
        project.save()
        handle_intercom_users.delay(project.id)

        flash('Project has been added', 'success')

        msg = 'Job for import existing users has been started.'

        if app.config['AWIS_USER_LIMIT_FOR_PROJECT'] > 0:
            msg = ('%s With limit is %s valid emails per project '
                   'for purpose of debugging'
                   ) % (msg, app.config['AWIS_USER_LIMIT_FOR_PROJECT'])

        flash(msg, 'success')

        return redirect(url_for('accounts.projects_list'))

    return locals()