Exemplo n.º 1
0
def project_update(pk):
    project = Project.get_for_current_user_or_404(pk)
    form = ProjectForm(obj=project)

    if form.validate_on_submit():
        form.populate_obj(project)
        project.save()
        flash('Project has been updated', 'success')

        if form.intercom_api_key.is_changed or form.data['repeat_import']:
            handle_intercom_users.delay(project.id)
            flash('Job for importing existing users for a new '
                  'Intercom project started', 'success')

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

    return locals()
Exemplo n.º 2
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()