def category_get(): d = dict() for record in categories_db.find({"user": get_user()}): record.pop("_id", None) d[record["indef"]] = record app.logger.debug(d) if not d: default_data = { "gains": { "indef" : "gains", "parent" : "#", "name" : "Приобретения", "type" : "gains", "sum" : 0, "opened": True }, "incomes": { "indef" : "incomes", "parent" : "#", "name" : "Доходы", "type" : "incomes", "sum" : 0, "opened" : True }} d = default_data for indef in default_data: category = {"user": get_user()} for cat_field in default_data[indef]: category[cat_field] = default_data[indef][cat_field] categories_db.insert(category) return jsonify(**d)
def bills_get(): d = dict() for record in bills_db.find({"user": get_user()}): record.pop("_id", None) d[record["indef"]] = record app.logger.debug(d) return jsonify(**d)
def transaction_put(): indef = request.form.get('indef', None) req = {"indef": indef} if not indef: return jsonify(result="Fail") transaction = {"user": get_user()} if "visible" in request.form: bill["visible"] = request.form.get("visible", type=int) bills_db.update(req, {"$set": bill}) return jsonify(result="Success")
def bill_post(): username = get_user() indef = request.form.get('indef', None) name = request.form.get('name', None) summa = request.form.get('sum', None, type=int) bill = {"user": username, "indef": indef, "name": name, "visible": 1, "sum": summa} if not indef and not name and not summa: return jsonify(result="Fail") bills_db.insert(bill) return jsonify(result="Success")
def bill_put(): indef = request.form.get('indef', None) req = {"indef": indef} if not indef: return jsonify(result="Fail") bill = {"user": get_user()} if "name" in request.form: bill["name"] = request.form.get("name") if "sum" in request.form: bill["sum"] = request.form.get("sum", type=int) if "visible" in request.form: bill["visible"] = request.form.get("visible", type=int) bills_db.update(req, {"$set": bill}) return jsonify(result="Success")
def bill_post(): username = get_user() indef = request.form.get('indef', None) name = request.form.get('name', None) summa = request.form.get('sum', None, type=int) bill = { "user": username, "indef": indef, "name": name, "visible": 1, "sum": summa } if not indef and not name and not summa: return jsonify(result="Fail") bills_db.insert(bill) return jsonify(result="Success")
def category_put(): indef = request.form.get('indef', None) req = {"indef": indef} if not indef: return jsonify(result="Fail") category = {"user": get_user()} if "name" in request.form: category["name"] = request.form.get("name") if "sum" in request.form: category["sum"] = request.form.get("sum", type=int) categories_db.update(req, {"$set": category}) if "type" in request.form: categories_db.remove(req) return jsonify(result="Success")
def transaction_post(): username = get_user() indef = request.form.get('indef', None) fromIndef = request.form.get('from', None) fromClass = request.form.get('fromClass', None) toIndef = request.form.get('to', None) toClass = request.form.get('toClass', None) data = request.form.get('data', None) delta = request.form.get('delta', None, type=int) transaction = {"user": username, "indef": indef, "from": fromIndef, "fromClass": fromClass, "to": toIndef, "toClass": toClass, "delta": delta, "visible": 1, "data": data} if not indef: return jsonify(result="Fail") transactions_db.insert(transaction) return jsonify(result="Success")
def category_post(): username = get_user() indef = request.form.get('indef', None) parent = request.form.get('parent', "#") name = request.form.get('name', None) cat_type = request.form.get('type', None) summa = request.form.get('sum', None, type=int) opened = request.form.get('opened', False, type=bool) category = { "user": username, "indef": indef, "name": name, "parent": parent, "type": cat_type, "sum": summa, "opened": opened } if not indef and not name and not summa: return jsonify(result="Fail") categories_db.insert(category) return jsonify(result="Success")
def transaction_post(): username = get_user() indef = request.form.get('indef', None) fromIndef = request.form.get('from', None) fromClass = request.form.get('fromClass', None) toIndef = request.form.get('to', None) toClass = request.form.get('toClass', None) data = request.form.get('data', None) delta = request.form.get('delta', None, type=int) transaction = { "user": username, "indef": indef, "from": fromIndef, "fromClass": fromClass, "to": toIndef, "toClass": toClass, "delta": delta, "visible": 1, "data": data } if not indef: return jsonify(result="Fail") transactions_db.insert(transaction) return jsonify(result="Success")
def transaction_get(): d = dict() for record in transactions_db.find({"user": get_user()}): record.pop("_id", None) d[record["indef"]] = record return jsonify(**d)