Esempio n. 1
0
def task_delete():
    if request.method == 'POST' and request.form['id'] and request.form['user_id']:
        task = db_session.query(Task).get(request.form['id']) 
        if task and task.user_id == int(request.form['user_id']) :
            db_session.delete(task)
            db_session.commit()
            return jsonify(error=0, code='success', message='删除成功', id=task.id)

    return jsonify(error=1, code='failed', message='删除失败')
Esempio n. 2
0
def rel_update():
    if request.method == 'POST' and request.form['id'] and request.form['user_id']:
        rel = db_session.query(UserRelation).get(request.form['id'])
        if rel and rel.to_user_id == int(request.form['user_id']):
            if request.form.has_key('status'):
                rel.status = request.form['status']
            db_session.commit()
            return jsonify(error=0, code='success', from_user_id=rel.from_user_id, to_user_id=rel.to_user_id, status=rel.status)
    
    return jsonify(error=1, code='failed', message='参数传递不正确')
Esempio n. 3
0
def create():
    form=GroupForm(request.form)
    if request.method=='POST' and form.validate():
        group = Group(title=form.title.data,
                      company_id=g.company.id,
                     )
        db_session.add(group)
        db_session.commit()
        #return redirect(url_for('group'))
    return render_template('group/create.html', form=form)
Esempio n. 4
0
def task_create():
    if request.form['user_id'] and request.form['title']:
        task = Task(title = request.form['title'], 
                    user_id = request.form['user_id'], 
                    to_user_id = request.form['to_user_id'] if request.form.has_key('to_user_id') else 0,
                    note = request.form['note'] if request.form.has_key('note') else '', 
                    priority = request.form['priority'] if request.form.has_key('priority') else 1, 
                    end_time = request.form['end_time'] if request.form.has_key('end_time') else '',
                    ) 
        db_session.add(task)
        db_session.commit()
        return jsonify(error=0, code='success', message='添加成功')
    return jsonify(error=1, code='failed', message='输入数据不合法')
Esempio n. 5
0
def rel_create():
    if request.method == "POST" and request.form['user_id'] and request.form['username']:
        user = db_session.query(User).filter_by(username=request.form['username']).first() 
        if user is None:
            return jsonify(error=1, code='empty', message='用户名不存在')
        user_relations = db_session.query(UserRelation).filter_by(from_user_id=request.form['user_id']).filter_by(to_user_id=user.id).first()
        if user_relations is None:
            from_user = db_session.query(User).get(request.form['user_id'])
            rel = UserRelation(from_user_id=request.form['user_id'], to_user_id=user.id, status=0, from_user_name=from_user.username, to_user_name=request.form['username'])
            db_session.add(rel)
            db_session.commit()
            return jsonify(error=0, code='success', from_user_id=rel.from_user_id, to_user_id=rel.to_user_id, status=rel.status)

        return jsonify(error=0, code='success', from_user_id=request.form['user_id'], to_user_id=user_relations.to_user_id, status=user_relations.status)
    return jsonify(error=1, code='failed', message='参数传递不正确')
Esempio n. 6
0
def register():
    form = RegistrationForm(request.form)
    if request.method == "POST" and form.validate():
        user = User(
            form.username.data,
            form.password.data,
            is_active=1,
            realname=request.form["realname"] if request.form.has_key("realname") else "",
        )
        result = User.query.filter_by(username=user.username).first()
        if result:
            return redirect(url_for("user.register"))
        db_session.add(user)
        db_session.commit()
        session["user_id"] = user.id
        flash("Thanks for registering")
        return redirect(url_for("company.create"))
    return render_template("user/register.html", form=form)
Esempio n. 7
0
def create():
    form = CompanyForm(request.form)
    if request.method=='POST' and g.user.id and form.validate():
        company = Company(user_id=g.user.id,
                          name=form.name.data,
                          scale=form.scale.data,
                          contact_name=form.contact_name.data,
                          telephone=form.telephone.data,
                          website=form.website.data,
                          address=form.address.data,
                          postcode=form.postcode.data,
                        )
        db_session.add(company)
        db_session.commit()
        if company.id:
            g.db.execute(users.update().values({users.c.company_id: company.id}).where(users.c.id==g.user.id))
            return redirect(url_for('home.index'))
    return render_template('company/create.html',form=form)
Esempio n. 8
0
def task_update():
    if request.method == 'POST' and request.form['id']:
        task = db_session.query(Task).get(request.form['id']) 
        if task:
            if request.form.has_key('status') : 
                task.status = request.form['status']
            if request.form.has_key('title'):
                task.title = request.form['title']
            if request.form.has_key('note'):
                task.note = request.form['note']
            if request.form.has_key('priority'):
                task.priority = request.form['priority']
            if request.form.has_key('end_time'):
                task.end_time = request.form['end_time']
            if request.form.has_key('to_user_id'):
                task.to_user_id = request.form['to_user_id']
            if request.form.has_key('description'):
                task.description = request.form['description']
            db_session.commit()
            return jsonify(error=0, code='success', message='修改成功', id=task.id)
    
    return jsonify(error=1, code='failed', message='修改失败')
Esempio n. 9
0
def register():
    username = request.form['username']
    password = request.form['password']
    if username and password:
        user = User(username, 
                    password, 
                    realname = request.form['realname'] if request.form.has_key('realname') else '',
                    company_id = request.form['company_id'] if request.form.has_key('company_id') else 0,
                   )
        result = User.query.filter_by(username = user.username).first() 

        if result:
            return jsonify(error=1, code='username_exists', message='用户名已经存在')
        else:
            db_session.add(user)
            db_session.commit()
            if request.form.has_key('company_name'):
                row = g.db.execute(select([companies.c.id], and_(companies.c.name==request.form['company_name']))).fetchone()
                company_id = g.db.execute(companies.insert(), name=request.form['company_name'], user_id=user.id).inserted_primary_key[0] if row is None else row['id']
                g.db.execute(users.update().values({users.c.company_id: company_id, users.c.is_active: 1}).where(users.c.id==user.id))
            return jsonify(error=0, code='success', message='成功注册', user_id = user.id, company_id=user.company_id)

    return jsonify(error=1, code = 'no_username_or_password', message='没有输入用户名或密码')