Esempio n. 1
0
 def post(self):
     """创建一个条目"""
     name = request.form.get('name', '')
     if name:
         item = create_or_raise(ItemM, name=name)
         db.session.add(item)
         db.session.commit()
         return {'status': 201, 'message': 'Created', 'data': item}, 201
     else:
         raise MissingFormData()
Esempio n. 2
0
 def post(self):
     """创建一个分类"""
     name = request.form.get('name', '')
     if name:
         category = create_or_raise(CategoryM, name=name)
         return {
             'status': 201,
             'message': 'Created',
             'data': category
         }, 201
     else:
         raise MissingFormData()
Esempio n. 3
0
 def post(self, category_id):
     """在一个分类下创建一个条目"""
     name = request.form.get('name', '')
     if name:
         category = get_or_raise(CategoryM, id=category_id)
         item = create_or_raise(ItemM, name=name)
         item.category = category
         db.session.add(item)
         db.session.commit()
         return {'status': 201, 'message': 'Created', 'data': item}, 201
     else:
         raise MissingFormData()
Esempio n. 4
0
 def delete(self, record_id):
     """在一条记录下删除一个标签"""
     tag_id = request.args.get('id', type=int)
     if tag_id:
         record = get_or_raise(RecordM, id=record_id)
         tag = get_or_raise(TagM, id=tag_id)
         record.tags.remove(tag)
         db.session.add(record)
         db.session.commit()
         return {'status': 200, 'message': 'OK', 'data': None}
     else:
         raise MissingFormData()
Esempio n. 5
0
 def post(self, record_id):
     """在一条记录下创建一个标签"""
     name = request.form.get('name', '')
     if name:
         record = get_or_raise(RecordM, id=record_id)
         tag = get_or_create(TagM, name=name)
         tag.records.append(record)
         db.session.add(tag)
         db.session.commit()
         return {'status': 201, 'message': 'Created', 'data': tag}, 201
     else:
         raise MissingFormData()
Esempio n. 6
0
 def put(self, item_id):
     """更新一个条目的信息"""
     item = ItemM.query.get(item_id)
     if item is None:
         abort(404)
     name = request.form.get('name', '')
     if name:
         if item.name == name:
             raise RedundantUpdate()
         else:
             item.name = name
             db.session.add(item)
             db.session.commit()
             return {'status': 200, 'message': 'OK', 'data': item}
     else:
         raise MissingFormData()
Esempio n. 7
0
 def put(self, category_id):
     """更新一个分类的信息"""
     category = CategoryM.query.get(category_id)
     if category is None:
         abort(404)
     name = request.form.get('name', '')
     if name:
         if category.name == name:
             raise RedundantUpdate()
         else:
             category.name = name
             db.session.add(category)
             db.session.commit()
             return {
                 'status': 200,
                 'message': 'OK',
                 'data': category
             }
     else:
         raise MissingFormData()
Esempio n. 8
0
 def put(self, record_id):
     """更新一条记录的信息"""
     record = RecordM.query.get(record_id)
     if record is None:
         abort(404)
     finish_stamp = request.form.get('finish', type=int)
     remark = request.form.get('remark')
     if finish_stamp:
         finish = datetime.fromtimestamp(finish_stamp / 1000)
         record.finish = finish
         db.session.add(record)
         db.session.commit()
         return {'status': 200, 'message': 'OK', 'data': record}
     elif remark:
         if record.remark == remark:
             raise RedundantUpdate()
         else:
             record.remark = remark
             db.session.add(record)
             db.session.commit()
             return {'status': 200, 'message': 'OK', 'data': record}
     else:
         raise MissingFormData()