2021-01-16 22:15:10 +08:00
|
|
|
from flask import Flask
|
|
|
|
|
from flask import request
|
|
|
|
|
import config
|
|
|
|
|
import database
|
2021-02-03 16:08:40 +08:00
|
|
|
import utils
|
2021-01-19 22:20:11 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
app = Flask(__name__)
|
|
|
|
|
calendar_db = database.CalendarDatabase()
|
2021-02-08 16:22:04 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# region: API Route
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# region: Common
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/common/salt', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_common_saltHandle():
|
2021-01-31 13:50:20 +08:00
|
|
|
return SmartDbCaller(calendar_db.common_salt,
|
2021-03-08 21:56:03 +08:00
|
|
|
(('username', str, False), ),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/common/login', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_common_loginHandle():
|
2021-03-08 21:56:03 +08:00
|
|
|
# construct client data first
|
|
|
|
|
clientUa = request.user_agent.string
|
|
|
|
|
if request.headers.getlist("X-Forwarded-For"):
|
|
|
|
|
clientIp = request.headers.getlist("X-Forwarded-For")[0]
|
|
|
|
|
else:
|
|
|
|
|
clientIp = request.remote_addr
|
|
|
|
|
|
2021-01-31 13:50:20 +08:00
|
|
|
return SmartDbCaller(calendar_db.common_login,
|
2021-02-01 20:34:40 +08:00
|
|
|
(('username', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('password', str, False),
|
|
|
|
|
('clientUa', str, False),
|
|
|
|
|
('clientIp', str, False)),
|
|
|
|
|
{
|
|
|
|
|
'clientUa': clientUa,
|
|
|
|
|
'clientIp': clientIp
|
|
|
|
|
})
|
2021-01-20 22:57:41 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/common/webLogin', methods=['POST'])
|
2021-01-20 22:57:41 +08:00
|
|
|
def api_common_webLoginHandle():
|
2021-03-08 21:56:03 +08:00
|
|
|
# construct client data first
|
|
|
|
|
clientUa = request.user_agent.string
|
|
|
|
|
if request.headers.getlist("X-Forwarded-For"):
|
|
|
|
|
clientIp = request.headers.getlist("X-Forwarded-For")[0]
|
|
|
|
|
else:
|
|
|
|
|
clientIp = request.remote_addr
|
|
|
|
|
|
2021-01-31 13:50:20 +08:00
|
|
|
return SmartDbCaller(calendar_db.common_webLogin,
|
2021-02-01 20:34:40 +08:00
|
|
|
(('username', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('password', str, False),
|
|
|
|
|
('clientUa', str, False),
|
|
|
|
|
('clientIp', str, False)),
|
|
|
|
|
{
|
|
|
|
|
'clientUa': clientUa,
|
|
|
|
|
'clientIp': clientIp
|
|
|
|
|
})
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/common/logout', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_common_logoutHandle():
|
2021-01-31 13:50:20 +08:00
|
|
|
return SmartDbCaller(calendar_db.common_logout,
|
2021-03-08 21:56:03 +08:00
|
|
|
(('token', str, False), ),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/common/tokenValid', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_common_tokenValidHandle():
|
2021-01-31 13:50:20 +08:00
|
|
|
return SmartDbCaller(calendar_db.common_tokenValid,
|
2021-03-08 21:56:03 +08:00
|
|
|
(('token', str, False), ),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# endregion
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# region: Calendar
|
|
|
|
|
|
|
|
|
|
@app.route('/calendar/getFull', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_calendar_getFullHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.calendar_getFull,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('startDateTime', int, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('endDateTime', int, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/calendar/getList', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_calendar_getListHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.calendar_getList,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('startDateTime', int, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('endDateTime', int, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/calendar/getDetail', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_calendar_getDetailHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.calendar_getDetail,
|
|
|
|
|
(('token', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('uuid', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/calendar/update', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_calendar_updateHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.calendar_update,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('uuid', str, False),
|
|
|
|
|
('belongTo', str, True),
|
|
|
|
|
('title', str, True),
|
|
|
|
|
('description', str, True),
|
|
|
|
|
('eventDateTimeStart', int, True),
|
|
|
|
|
('eventDateTimeEnd', int, True),
|
|
|
|
|
('loopRules', str, True),
|
|
|
|
|
('timezoneOffset', int, True),
|
2021-03-08 21:56:03 +08:00
|
|
|
('lastChange', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/calendar/add', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_calendar_addHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.calendar_add,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('belongTo', str, False),
|
|
|
|
|
('title', str, False),
|
|
|
|
|
('description', str, False),
|
|
|
|
|
('eventDateTimeStart', int, False),
|
|
|
|
|
('eventDateTimeEnd', int, False),
|
|
|
|
|
('loopRules', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('timezoneOffset', int, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/calendar/delete', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_calendar_deleteHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.calendar_delete,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('uuid', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('lastChange', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# endregion
|
|
|
|
|
|
|
|
|
|
# region: Collection
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/collection/getFullOwn', methods=['POST'])
|
2021-01-31 13:50:20 +08:00
|
|
|
def api_collection_getFullOwnHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.collection_getFullOwn,
|
2021-03-08 21:56:03 +08:00
|
|
|
(('token', str, False), ),
|
|
|
|
|
None)
|
2021-01-31 13:50:20 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/collection/getListOwn', methods=['POST'])
|
2021-01-31 13:50:20 +08:00
|
|
|
def api_collection_getListOwnHandle():
|
2026-04-28 13:17:54 +08:00
|
|
|
return SmartDbCaller(calendar_db.collection_getListOwn,
|
2021-03-08 21:56:03 +08:00
|
|
|
(('token', str, False), ),
|
|
|
|
|
None)
|
2021-01-31 13:50:20 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/collection/getDetailOwn', methods=['POST'])
|
2021-01-31 13:50:20 +08:00
|
|
|
def api_collection_getDetailOwnHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.collection_getDetailOwn,
|
|
|
|
|
(('token', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('uuid', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/collection/addOwn', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_collection_addOwnHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.collection_addOwn,
|
|
|
|
|
(('token', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('name', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/collection/updateOwn', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_collection_updateOwnHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.collection_updateOwn,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('uuid', str, False),
|
|
|
|
|
('name', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('lastChange', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/collection/deleteOwn', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_collection_deleteOwnHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.collection_deleteOwn,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('uuid', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('lastChange', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
|
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/collection/getSharing', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_collection_getSharingHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.collection_getSharing,
|
|
|
|
|
(('token', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('uuid', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/collection/deleteSharing', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_collection_deleteSharingHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.collection_deleteSharing,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('uuid', str, False),
|
|
|
|
|
('target', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('lastChange', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/collection/addSharing', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_collection_addSharingHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.collection_addSharing,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('uuid', str, False),
|
|
|
|
|
('target', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('lastChange', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
|
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/collection/getShared', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_collection_getSharedHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.collection_getShared,
|
2021-03-08 21:56:03 +08:00
|
|
|
(('token', str, False), ),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# endregion
|
|
|
|
|
|
|
|
|
|
# region: Todo
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/todo/getFull', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_todo_getFullHandle():
|
2021-01-31 13:50:20 +08:00
|
|
|
return SmartDbCaller(calendar_db.todo_getFull,
|
2021-03-08 21:56:03 +08:00
|
|
|
(('token', str, False), ),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/todo/getList', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_todo_getListHandle():
|
2021-01-31 13:50:20 +08:00
|
|
|
return SmartDbCaller(calendar_db.todo_getList,
|
2021-03-08 21:56:03 +08:00
|
|
|
(('token', str, False), ),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/todo/getDetail', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_todo_getDetailHandle():
|
2021-01-31 13:50:20 +08:00
|
|
|
return SmartDbCaller(calendar_db.todo_getDetail,
|
2021-02-01 20:34:40 +08:00
|
|
|
(('token', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('uuid', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/todo/add', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_todo_addHandle():
|
2021-01-31 13:50:20 +08:00
|
|
|
return SmartDbCaller(calendar_db.todo_add,
|
2021-03-08 21:56:03 +08:00
|
|
|
(('token', str, False), ),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/todo/update', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_todo_updateHandle():
|
2021-01-31 13:50:20 +08:00
|
|
|
return SmartDbCaller(calendar_db.todo_update,
|
2021-02-01 20:34:40 +08:00
|
|
|
(('token', str, False),
|
|
|
|
|
('uuid', str, False),
|
|
|
|
|
('data', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('lastChange', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/todo/delete', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_todo_deleteHandle():
|
2021-01-31 13:50:20 +08:00
|
|
|
return SmartDbCaller(calendar_db.todo_delete,
|
2021-02-01 20:34:40 +08:00
|
|
|
(('token', str, False),
|
|
|
|
|
('uuid', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('lastChange', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# endregion
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# region: Admin
|
|
|
|
|
|
|
|
|
|
@app.route('/admin/get', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_admin_getHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.admin_get,
|
2021-03-08 21:56:03 +08:00
|
|
|
(('token', str, False), ),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/admin/add', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_admin_addHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.admin_add,
|
|
|
|
|
(('token', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('username', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/admin/update', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_admin_updateHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.admin_update,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('username', str, False),
|
|
|
|
|
('password', str, True),
|
2021-03-08 21:56:03 +08:00
|
|
|
('isAdmin', utils.Str2Bool, True)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/admin/delete', methods=['POST'])
|
2021-01-16 22:15:10 +08:00
|
|
|
def api_admin_deleteHandle():
|
2021-02-02 20:49:01 +08:00
|
|
|
return SmartDbCaller(calendar_db.admin_delete,
|
|
|
|
|
(('token', str, False),
|
2021-03-08 21:56:03 +08:00
|
|
|
('username', str, False)),
|
|
|
|
|
None)
|
|
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# endregion
|
|
|
|
|
|
|
|
|
|
# region: Profile
|
2021-03-08 21:56:03 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/profile/isAdmin', methods=['POST'])
|
2021-03-08 21:56:03 +08:00
|
|
|
def api_profile_isAdminHandle():
|
|
|
|
|
return SmartDbCaller(calendar_db.profile_isAdmin,
|
|
|
|
|
(('token', str, False), ),
|
|
|
|
|
None)
|
|
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/profile/changePassword', methods=['POST'])
|
2021-03-08 21:56:03 +08:00
|
|
|
def api_profile_changePasswordHandle():
|
|
|
|
|
return SmartDbCaller(calendar_db.profile_changePassword,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('password', str, False)),
|
|
|
|
|
None)
|
|
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/profile/getToken', methods=['POST'])
|
2021-03-08 21:56:03 +08:00
|
|
|
def api_profile_getTokenHandle():
|
|
|
|
|
return SmartDbCaller(calendar_db.profile_getToken,
|
|
|
|
|
(('token', str, False), ),
|
|
|
|
|
None)
|
|
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
@app.route('/profile/deleteToken', methods=['POST'])
|
2021-03-08 21:56:03 +08:00
|
|
|
def api_profile_deleteTokenHandle():
|
|
|
|
|
return SmartDbCaller(calendar_db.profile_deleteToken,
|
|
|
|
|
(('token', str, False),
|
|
|
|
|
('deleteToken', str, False)),
|
|
|
|
|
None)
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# endregion
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# endregion
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2026-05-11 22:20:06 +08:00
|
|
|
# region: Misc Functions
|
2021-01-16 22:15:10 +08:00
|
|
|
|
2021-03-08 21:56:03 +08:00
|
|
|
def SmartDbCaller(dbMethod, paramTuple, extraDict):
|
2021-01-31 13:50:20 +08:00
|
|
|
result = (False, 'Invalid parameter', None)
|
2021-02-01 20:34:40 +08:00
|
|
|
optCount = 0
|
2021-01-31 13:50:20 +08:00
|
|
|
paramList = []
|
2021-02-01 20:34:40 +08:00
|
|
|
optParamDict = {}
|
2021-03-08 21:56:03 +08:00
|
|
|
# for each item,
|
|
|
|
|
# item[0] is field name.
|
|
|
|
|
# item[1] is type.
|
|
|
|
|
# item[2] is whether it is optional field
|
|
|
|
|
realForm = request.form.to_dict()
|
|
|
|
|
if extraDict is not None:
|
|
|
|
|
realForm.update(extraDict)
|
2021-01-31 13:50:20 +08:00
|
|
|
for item in paramTuple:
|
2021-03-08 21:56:03 +08:00
|
|
|
cache = item[1](realForm.get(item[0], None))
|
2021-02-01 20:34:40 +08:00
|
|
|
if item[2]:
|
|
|
|
|
# optional param
|
|
|
|
|
if cache is not None:
|
|
|
|
|
optParamDict[item[0]] = cache
|
|
|
|
|
optCount += 1
|
|
|
|
|
else:
|
|
|
|
|
if cache is None:
|
|
|
|
|
break
|
|
|
|
|
paramList.append(cache)
|
2021-01-31 13:50:20 +08:00
|
|
|
else:
|
2021-02-01 20:34:40 +08:00
|
|
|
# at least one opt param
|
|
|
|
|
if optCount == 0 or len(optParamDict) != 0:
|
|
|
|
|
result = dbMethod(*paramList, **optParamDict)
|
2021-01-31 13:50:20 +08:00
|
|
|
|
|
|
|
|
return ConstructResponseBody(result)
|
2021-01-20 22:57:41 +08:00
|
|
|
|
|
|
|
|
def ConstructResponseBody(returnedTuple):
|
|
|
|
|
return {
|
|
|
|
|
'success': returnedTuple[0],
|
2021-01-24 14:38:08 +08:00
|
|
|
'error': returnedTuple[1],
|
|
|
|
|
'data': returnedTuple[2]
|
2021-01-20 22:57:41 +08:00
|
|
|
}
|
|
|
|
|
|
2021-01-16 22:15:10 +08:00
|
|
|
def run():
|
2021-01-25 20:42:06 +08:00
|
|
|
calendar_db.open()
|
2026-04-28 13:17:54 +08:00
|
|
|
app.run(port=config.get_config().web.port)
|
2021-01-25 20:42:06 +08:00
|
|
|
calendar_db.close()
|
2026-05-11 22:20:06 +08:00
|
|
|
|
|
|
|
|
# endregion
|