示例#1
0
def lastuserauth():
    Workspace.update_from_user(g.user,
                               db.session,
                               make_user_profiles=False,
                               make_org_profiles=False)
    db.session.commit()
    return redirect(get_next_url())
示例#2
0
def workspace_new():
    # Step 1: Get a list of organizations this user owns
    existing = Workspace.query.filter(
        Workspace.userid.in_(g.user.organizations_owned_ids())).all()
    existing_ids = [e.userid for e in existing]
    # Step 2: Prune list to organizations without a workspace
    new_workspaces = []
    for org in g.user.organizations_owned():
        if org['userid'] not in existing_ids:
            new_workspaces.append((org['userid'], org['title']))
    if not new_workspaces:
        return render_message(
            title=u"No organizations found",
            message=Markup(
                u"You do not have any organizations that do not already have a workspace. "
                u'Would you like to <a href="%s">create a new organization</a>?'
                % lastuser.endpoint_url('/organizations/new')))
    eligible_workspaces = []
    for orgid, title in new_workspaces:
        if Team.query.filter_by(orgid=orgid).first() is not None:
            eligible_workspaces.append((orgid, title))
    if not eligible_workspaces:
        return render_message(
            title=u"No organizations available",
            message=Markup(
                u"To create a workspace for an organization, you must first allow this app to "
                u"access the list of teams in your organization. "
                u'<a href="%s">Do that here</a>.' %
                lastuser.endpoint_url('/apps/' + lastuser.client_id)))

    # Step 3: Ask user to select organization
    form = NewWorkspaceForm()
    form.workspace.choices = eligible_workspaces
    if request.method == 'GET':
        form.workspace.data = new_workspaces[0][0]
    if form.validate_on_submit():
        # Step 4: Make a workspace
        org = [
            org for org in g.user.organizations_owned()
            if org['userid'] == form.workspace.data
        ][0]
        workspace = Workspace(name=org['name'],
                              title=org['title'],
                              userid=org['userid'],
                              currency=form.currency.data,
                              timezone=app.config.get('TIMEZONE', ''))
        db.session.add(workspace)
        db.session.commit()
        flash(u"Created a workspace for %s" % workspace.title, "success")
        return render_redirect(url_for('workspace_edit',
                                       workspace=workspace.name),
                               code=303)
    return render_form(form=form,
                       title="Create a workspace for your organization...",
                       submit="Next",
                       formid="workspace_new",
                       cancel_url=url_for('index'),
                       ajax=False)
示例#3
0
def lastusernotify(user):
    Workspace.update_from_user(user,
                               db.session,
                               make_user_profiles=False,
                               make_org_profiles=False)
    db.session.commit()
示例#4
0
文件: login.py 项目: Anenth/kharcha
def lastusernotify(user):
    Workspace.update_from_user(user, db.session, make_user_profiles=False, make_org_profiles=False)
    db.session.commit()
示例#5
0
文件: login.py 项目: Anenth/kharcha
def lastuserauth():
    Workspace.update_from_user(g.user, db.session, make_user_profiles=False, make_org_profiles=False)
    db.session.commit()
    return redirect(get_next_url())