12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- from werkzeug.security import generate_password_hash
- from hub import methods, Global
- def default_data_insert():
- # --- check ---
- from default_data import data
- if not data.get('enable'):
- return
- config = data.get('config')
- # --- check UserRole&User ---
- d1 = {
- 'role': [],
- 'user': [],
- }
- for item in config.get('Role&User'):
- # --- insert role_info ---
- role_info = item.get('role_info')
- unique_dict = {
- 'role_type': role_info.get('role_type'),
- }
- mdb_role = Global.mdb.get_one('UserRole', unique_dict)
- # --- check ---
- if not mdb_role:
- update_dict = {
- 'role_type': role_info.get('role_type'),
- 'role_name': role_info.get('role_name'),
- 'switch_list': role_info.get('switch_list'),
- 'create_at': methods.now_ts(),
- }
- rid = Global.mdb.update_one('UserRole', unique_dict, update_dict)
- d1['role'].append(rid)
- else:
- rid = str(mdb_role.get('_id'))
- d1['role'].append(rid)
- # --- insert users_info ---
- users_info = item.get('users_info')
- for user in users_info:
- unique_dict = {'username': user.get('username')}
- mdb_user = Global.mdb.get_one('UserInfo', unique_dict)
- # --- check ---
- if not mdb_user:
- update_dict = {
- 'password': generate_password_hash(user.get('password')),
- 'role_type': role_info.get('role_type'),
- 'create_at': methods.now_ts(),
- }
- uid = Global.mdb.update_one('UserInfo', unique_dict, update_dict)
- d1['user'].append(uid)
- else:
- uid = str(mdb_user.get('_id'))
- d1['user'].append(uid)
- methods.debug_log('default_data_insert.default_data_insert.60', f"#d1: {d1}")
- # --- check ---
- # unique_dict = {'name': 'CameraConfig'}
- # item = Global.mdb.get_one('GlobalVariable', unique_dict)
- # data = item.get('args', {})
- # data['camera_rtsp'] = config.get('GlobalVariable', {}).get('CameraConfig', {}).get('camera_rtsp', '')
- # data['camera_ipv4'] = config.get('GlobalVariable', {}).get('CameraConfig', {}).get('camera_ipv4', '')
- # data['camera_user'] = config.get('GlobalVariable', {}).get('CameraConfig', {}).get('camera_user', '')
- # data['camera_pass'] = config.get('GlobalVariable', {}).get('CameraConfig', {}).get('camera_pass', '')
- # update_dict = {'args': data}
- # Global.mdb.update_one('GlobalVariable', unique_dict, update_dict)
- # methods.debug_log('default_data_insert.default_data_insert', f"m-68: {data}")
|