def category(): data = request.json if request.method == 'GET': ct = [] for c in list(categorias.find()): c['_id'] = str(c['_id']) ct.append(c) return jsonify(ct) elif request.method == 'POST': categorias.insert_one({'descripcion': data['descripcion']}) return jsonify(data)
def getstatus(): data = request.json if request.method == 'GET': pers = [] filtros = {} if request.args.get('category'): filtros['category'] = ObjectId(request.args.get('category')) if request.args.get('status'): filtros['status'] = ObjectId(request.args.get('status')) for c in list(personas.find(filtros)): c['_id'] = str(c['_id']) categ = list(categorias.find({'_id': c['category']})) c['category'] = categ[0]['descripcion'] if len(categ) > 0 else str( c['category']) stat = list(categorias.find({'_id': c['status']})) c['status'] = categ[0]['descripcion'] if len(stat) > 0 else str( c['status']) pers.append(c) return jsonify(pers)
def get_personas(): p = [] for _p in list( personas.find({}, {'_id', 'doc_id', 'category', 'status', 'client'})): categ = list(categorias.find({'_id': _p['category']})) _p['category'] = categ[0]['descripcion'] if len(categ) > 0 else str( _p['category']) stat = list(estatus.find({'_id': _p['status']})) _p['status'] = stat[0]['descripcion'] if len(stat) > 0 else str( _p['status']) _p['_id'] = str(_p['_id']) p.append(_p) return jsonify(p)
def personsEdit(id): data = request.json if request.method == 'PUT': myquery = {"_id": ObjectId(id)} dataSet = {} if data['category'] and categorias.find({'_id': data['category']}): dataSet['category'] = ObjectId(data['category']) if data['status'] and estatus.find({'_id': data['status']}): dataSet['status'] = ObjectId(data['status']) newvalues = {"$set": dataSet} personas.update_one(myquery, newvalues) return jsonify(data) elif request.method == 'DELETE': personas.delete_one({"_id": ObjectId(id)}) return jsonify(data)
def status(): data = request.json if request.method == 'GET': ct = [] filtros = {} if request.args.get('category'): filtros['category'] = ObjectId(request.args.get('category')) for c in list(estatus.find(filtros)): c['_id'] = str(c['_id']) categ = list(categorias.find({'_id': c['category']})) c['category'] = categ[0]['descripcion'] if len(categ) > 0 else str( c['category']) ct.append(c) return jsonify(ct) elif request.method == 'POST': estatus.insert_one({ 'category': ObjectId(data['category']), 'descripcion': data['descripcion'] }) return jsonify(data)