示例#1
0
文件: views.py 项目: archiechen/miami
def create_task():
    if current_user.teams.count() == 0:
        abort(403)
    jsons = json.loads(request.data)
    if jsons.get('id', 0):
        task = Task.query.get_or_404(jsons.get('id'))
        task.title = jsons.get('title', '')
        task.detail = jsons.get('detail', '')
        db.session.commit()
        return jsonify(object=task.toJSON()), 200
    else:
        status = jsons.get('status', 'NEW')
        if status not in ['NEW', 'READY']:
            abort(403)
        price = jsons.get('price', 0)
        if status == 'READY' and price == 0:
            abort(403)
        team_id=int(jsons.get('team_id',0))
        task = Task(jsons.get('title'), jsons.get(
            'detail',''), priority=jsons.get('priority', 100), status=status, price=price, team=Team.query.get(team_id) if team_id else current_user.teams[0])
        for category_name in jsons.get('categories', '').split(','):
            if not category_name:
                category_name=u'未分类'
            category = Category.query.filter(Category.name == category_name).first()
            if category:
                task.categories.append(category)
            else:
                task.categories.append(Category(category_name))
        db.session.add(task)
        db.session.commit()
        return jsonify(object=task.toJSON()), 201
示例#2
0
def create_task():
    if current_user.teams.count() == 0:
        abort(403)
    jsons = json.loads(request.data)
    if jsons.get('id', 0):
        task = Task.query.get_or_404(jsons.get('id'))
        task.title = jsons.get('title', '')
        task.detail = jsons.get('detail', '')
        db.session.commit()
        return jsonify(object=task.toJSON()), 200
    else:
        status = jsons.get('status', 'NEW')
        if status not in ['NEW', 'READY']:
            abort(403)
        price = jsons.get('price', 0)
        if status == 'READY' and price == 0:
            abort(403)
        team_id = int(jsons.get('team_id', 0))
        task = Task(
            jsons.get('title'),
            jsons.get('detail', ''),
            priority=jsons.get('priority', 100),
            status=status,
            price=price,
            team=Team.query.get(team_id) if team_id else current_user.teams[0])
        for category_name in jsons.get('categories', '').split(','):
            if not category_name:
                category_name = u'未分类'
            category = Category.query.filter(
                Category.name == category_name).first()
            if category:
                task.categories.append(category)
            else:
                task.categories.append(Category(category_name))
        db.session.add(task)
        db.session.commit()
        return jsonify(object=task.toJSON()), 201
示例#3
0
    def test_task_toJSON(self):
        team = Team('Log')
        team.id = 1
        task = Task('title1',
                    'detail',
                    status='DONE',
                    price=1,
                    estimate=4,
                    team=team)
        task.id = 1
        task.owner = User('Mike')

        self.assertEquals(
            {
                'id': 1,
                'title': 'title1',
                'detail': 'detail',
                'status': 'DONE',
                'price': 1,
                'estimate': 4,
                'priority': 100,
                'time_slots': [],
                'consuming': '0',
                'created_time': 'just now',
                'last_updated': 'just now',
                'team': {
                    'name': 'Log',
                    'color': '2a33d8',
                    'id': 1
                },
                'owner': {
                    'name': 'Mike',
                    'gravater': '91f376c4b36912e5075b6170d312eab5'
                },
                'partner': {}
            }, task.toJSON())
示例#4
0
    def test_task_toJSON(self):
        team = Team('Log')
        team.id = 1
        task = Task('title1', 'detail', status='DONE', price=1, estimate=4, team=team)
        task.id = 1
        task.owner = User('Mike')

        self.assertEquals({'id': 1, 'title': 'title1', 'detail': 'detail', 'status': 'DONE', 'price': 1, 'estimate': 4,'priority': 100,'time_slots': [], 'consuming': '0','created_time': 'just now', 'last_updated': 'just now', 'team': {
                          'name': 'Log', 'color': '2a33d8', 'id':1}, 'owner': {'name': 'Mike', 'gravater': '91f376c4b36912e5075b6170d312eab5'}, 'partner': {}}, task.toJSON())