コード例 #1
0
ファイル: profile.py プロジェクト: kungfuhub/datakungfu-web
def new_pass():
    form = NewPassword(request.form)
    phone = get_argument("phone")
    email = get_argument("email")
    repeat = get_argument("repeat")
    if repeat:
        if email:
            UserProxy.verify(email=email)
        elif phone:
            UserProxy.verify(phone=phone)
        return render_template('input/new_pass.html', form=form)

    if form.validate_on_submit():
        try:
            code = form.code.data
            if email:
                user = UserProxy.signup_verify_code(email=email, code=code)
            elif phone:
                user = UserProxy.signup_verify_code(phone=phone, code=code)

            session["user_obj"] = user.set_default()
            login_user(user, remember=True)

            user.set_properties({password:form.password.data})

            if not user.is_active():
                return redirect(url_for('signup'))

            return redirect(url_for('welcome'))
        except HTTPError, e:
            make_error_response(e)
コード例 #2
0
ファイル: profile.py プロジェクト: kungfuhub/datakungfu-web
def change_fullname():
    password = get_argument("password")
    fullname = get_argument("fullname")
    print "len(fullname): ", len(fullname)
    try:
        g.user.set_properties_with_password(pwd=password, fullname=fullname)
        return json.dumps({"success": True})
    except HTTPError, e:
        make_error_response(e)
コード例 #3
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def article_publish( art_id ):
    try:
        article = Article({ "uuid": art_id })
        result = article.publish()
        return jsonify(result)
    except HTTPError, e:
        return make_error_response(e)
コード例 #4
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def articles( ):
    try:
        art_name = _( DEFAULT_ARTICLE_TITLE )
        article = ArticleProxy.create_article( art_name )
        return jsonify(article.json())
    except HTTPError, e:
        return make_error_response(e)
コード例 #5
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def unsubscribe_from_leaf( leaf_id ):
    try:
        if g.user is not None and g.user.is_active():
            ArticleProxy.unsubscribe(leaf_id)
        return make_response()
    except HTTPError, e:
        return make_error_response(e)
コード例 #6
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def article_member_delete(art_id, user_id):
    try:
        article = Article({'uuid': art_id})
        article.delete_member(user_id)
        return make_response()
    except HTTPError, e:
        return make_error_response(e)
コード例 #7
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def article_members(art_id):
    if request.method == 'GET':
        try:
            article = ArticleProxy.get_by_id(art_id)
            result = article.get_members_json()
            return jsonify(result)
        except HTTPError, e:
            return make_error_response(e)
コード例 #8
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def article_invite_members(art_id):
    try:
        article = Article({'uuid': art_id})
        members = get_argument('members', [])
        article.invite_members(members)
        return make_response()
    except HTTPError, e:
        return make_error_response(e)
コード例 #9
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def deactivate_block( art_id, branch_id, commit_id, block_id ):
    # print     art_id, block_id
    article = Article( {"uuid": art_id, "selected_branch" : {'uuid': branch_id}, "selected_commit" : {'uuid': commit_id }} )
    try:
        article.deactivate_block(block_id)
        return make_response()
    except HTTPError, e:
        return make_error_response(e)
コード例 #10
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def get_commit_json(commit_id):
    try:
        result = {}
        article = ArticleProxy.get_by_leaf_id(commit_id)
        result['article'] = article.json()
        return jsonify(result)
    except HTTPError, e:
        return make_error_response(e)
コード例 #11
0
ファイル: profile.py プロジェクト: kungfuhub/datakungfu-web
def forgot( ):
    email_form = SignupEmailForm( request.form )
    phone_form = SignupPhoneForm( request.form )
    try:
        if email_form.validate_on_submit( ):
            email = email_form.email.data
            UserProxy.verify( email = email )
            return redirect( url_for( 'new_pass', email = email ) )
        elif phone_form.validate_on_submit():
            import re
            reg = re.compile('[^\d]')
            phone = phone_form.customer_phone.data
            phone ="+%s"%re.sub(reg, "", phone)
            UserProxy.verify( phone = phone )
            return redirect( url_for( 'new_pass', phone = phone ) )
    except HTTPError, e:
        make_error_response(e)
コード例 #12
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def leaf_diffs(leaf_id):
    try:
        src_commit_id = get_argument('src_commit_uuid', None)
        article = ArticleProxy.get_diffs(leaf_id, src_commit_id)
        result = {}
        result['article'] = article.json()
        return jsonify(result)
    except HTTPError, e:
        return make_error_response(e)
コード例 #13
0
ファイル: topics.py プロジェクト: kungfuhub/datakungfu-web
def topic( topic_id, type = "top", range = "day" ):
    # type = top | recent | users
    #range = day | week | month | ever
    topic = articles = users = None
    articles = [ ]
    users = [ ]
    try:
        topic = TopicProxy.get( topic_id )
        if type == "top":
            articles = topic.get_top_articles_in_time( range )
        elif type == "recent":
            articles = topic.get_recent_articles_in_time( range )
        elif type == "users":
            users = topic.get_top_users_in_time( range )
        elif type == "organizations":
            users = topic.get_top_users_in_time( range )
    except HTTPError, e:
        make_error_response(e)
コード例 #14
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def article_blocks_delete( art_id, branch_id, commit_id):
    # print     art_id, block_id
    article = Article( {"uuid": art_id, "selected_branch" : {'uuid': branch_id}, "selected_commit" : {'uuid': commit_id }} )
    block_uuids = get_argument('block_uuids')
    try:
        result = article.delete_blocks(block_uuids)
        return jsonify(result)
    except HTTPError, e:
        return make_error_response(e)
コード例 #15
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def article_blocks_move(art_id, branch_id, commit_id):
    article = Article( { "uuid": art_id, "selected_branch" : {'uuid': branch_id}, "selected_commit" : {'uuid': commit_id }} )
    block_uuids = get_argument('block_uuids')
    prev_block_uuid = get_argument('prev_block_uuid')
    try:
        params = {
            "block_uuids": block_uuids,
            "prev_block_uuid": prev_block_uuid
        }
        res = article.move_blocks(**params)
        return jsonify(res)
    except HTTPError, e:
        return make_error_response(e)
コード例 #16
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def leaf_pull(dest_leaf_id):
    src_block_commit_uuid_pairs = get_argument('src_block_commit_uuid_pairs')
    dest_prev_block_uuid = get_argument('dest_prev_block_uuid')
    try:
        params = {
            "src_block_commit_uuid_pairs": src_block_commit_uuid_pairs,
            "dest_leaf_id": dest_leaf_id,
            "dest_prev_block_uuid": dest_prev_block_uuid
        }
        res = ArticleProxy.pull_blocks(**params)
        return jsonify(res)
    except HTTPError, e:
        return make_error_response(e)
コード例 #17
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def article(art_id):
    try:
        result = {}
        article = Article( { "uuid": art_id } )
        if request.method == 'DELETE':
            result = article.delete( )
        elif request.method == 'PATCH':
            title = get_argument('title')
            description = get_argument('description')
            result = article.update( title=title, description=description )
        return jsonify(result)
    except HTTPError, e:
        return make_error_response(e)
コード例 #18
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def article_block_update( art_id, branch_id, commit_id, block_id ):
    article = Article( { "uuid": art_id, "selected_branch" : {'uuid': branch_id}, "selected_commit" : {'uuid': commit_id }} )
    try:
        type = get_argument("type")
        subtype = get_argument("subtype")
        content = get_argument("content")
        title = get_argument("title")
        caption = get_argument("caption")
        metadata = get_argument("metadata")
        status = get_argument("status")
        weight = get_argument("weight")
        result = article.update_block(block_id, type=type, subtype=subtype, title=title, content=content, caption=caption, metadata=metadata, status=status, weight=weight)
        return jsonify(result)
    except HTTPError, e:
        return make_error_response(e)
コード例 #19
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def leaf_json(leaf_id):
    try:
        result = {}
        article = ArticleProxy.get_by_leaf_id(leaf_id)
        res = article.get_commits()
        result['article'] = article.json()
        result['article']['commits'] = res.get('commits')
        result['article']['commits_count'] = res.get('count')
        result['article']['commits_offset'] = res.get('offset')
        result['article']['commits_limit'] = res.get('limit')
        if g.user is not None and g.user.is_active():
            ArticleProxy.subscribe(article.uuid)
            ArticleProxy.subscribe(article.selected_commit['uuid'])
            result['user'] = g.user.json()
            result['user']['role'] = article.user_role
        else:
            result['user'] = {}
            result['user']['role'] = None
        return jsonify(result)
    except HTTPError, e:
        return make_error_response(e)
コード例 #20
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
def article_commits( art_id):
    try:
        branch_id = get_argument("branch")
        article = Article( {"uuid": art_id, "selected_branch" : {'uuid': branch_id }} )
        if request.method == 'GET':
            res = article.get_commits()
            result = {}
            result['article'] = article.json()
            result['article']['commits'] = res['commits']
            result['article']['commits_count'] = res['count']
            result['article']['commits_offset'] = res['offset']
            result['article']['commits_limit'] = res['limit']
            return jsonify(result)
        elif request.method == 'POST':
            src_commit_id = get_argument("src_commit")
            title = get_argument("title")
            description = get_argument("description")
            result = article.create_commit(src_commit_id, title, description)
            result["success"] = True
            return jsonify(result)
    except HTTPError, e:
        return make_error_response(e)
コード例 #21
0
ファイル: profile.py プロジェクト: kungfuhub/datakungfu-web
def get_profile(username=None):
    if username is not None:
        leaves = []
        collaborators = []
        organizations = []
        user = None
        recents = []
        try:
            user = UserProxy.get_by_username(username)

            # organizations = user.load_organizations()
            # need new method to get leaf collaborators
            articles = user.get_articles()
            collaborators = user.get_collaborators()
            result = user.json()
            result['articles'] = articles['articles']
            result['articles_count'] = articles['count']
            result['collaborators'] = collaborators['collaborators']
            result['collaborators_count'] = collaborators['count']
            return jsonify(result)
        except HTTPError, e:
            return make_error_response(e)
コード例 #22
0
ファイル: tree.py プロジェクト: kungfuhub/datakungfu-web
        try:
            article = ArticleProxy.get_by_id(art_id)
            result = article.get_members_json()
            return jsonify(result)
        except HTTPError, e:
            return make_error_response(e)
    if request.method == 'PUT':
        try:
            article = ArticleProxy.get_by_id(art_id)

            article.set_members(request.form)
            result = {"success": True}
            return json.dumps(result)

        except HTTPError, e:
            return make_error_response(e)


@app.route('/articles/<art_id>/members/<user_id>', methods=['DELETE'])
@login_required
def article_member_delete(art_id, user_id):
    try:
        article = Article({'uuid': art_id})
        article.delete_member(user_id)
        return make_response()
    except HTTPError, e:
        return make_error_response(e)


@app.route( '/articles/<art_id>/publish', methods = [ 'POST' ] )
@login_required