Coverage for server/bp/saxia.py: 37%

65 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2026-01-26 23:58 +0100

1 

2from flask import Blueprint, request, Response, url_for, render_template, redirect, render_template_string, send_file 

3import json 

4 

5def create_saxia_interface_bp(): 

6 bp = Blueprint('saxia_interface', __name__, url_prefix='/saxia') 

7 

8# bp.add_url_rule("/", endpoint="index") 

9 @bp.route("/index", methods=['GET']) 

10 def index(): 

11# return "Welcome to saxia !" 

12 return render_template('saxia/index.html') 

13 

14 @bp.route("/service") 

15 def service(): 

16 return "Welcome to saxia service !" 

17 

18 @bp.route("/tarif") 

19 def tarif(): 

20 return "Welcome to saxia tarif !" 

21 

22 @bp.route("/equipe") 

23 def equipe(): 

24 return "Welcome to saxia equipe !" 

25 

26 @bp.route("/conformite") 

27 def conformite(): 

28 return "Welcome to saxia conformite !" 

29 

30 @bp.route("/but") 

31 def but(): 

32 return "Welcome to saxia but !" 

33 

34 

35 # VR Duplicate with /api/v1/audit/load 

36 @bp.route("/conso") 

37 def api_v1_saxia_conso(): 

38 from server.safia import register_user_get_data 

39 user, data_needed, lss = register_user_get_data(request, list_data_needed=["project_id", "otp"]) 

40 from flask_login import current_user 

41 lss_test = current_user.lss 

42 project_id = request.args.get('project_id', None) 

43 

44 curr_project_id = data_needed["project_id"] 

45 if project_id != None: 

46 curr_project_id = project_id 

47 

48 auth = lss.lib_right.get_role_on_project(lss.get_user_id(), curr_project_id) 

49 is_admin = lss.lib_right.is_user_admin_config(lss.get_user_id()) 

50 if auth == None and is_admin == False: 

51 print(" We will select the first project where the user has right") 

52 list_pids = lss.lib_right.get_projects_with_access(lss.get_user_id()) 

53 if len(list_pids) > 0 and "id" in list_pids[0]: 

54 curr_project_id = list_pids[0]["id"] 

55 

56 if is_admin: 

57 user_id_input = request.args.get('user_id', None) 

58 if user_id_input != None: 

59 user_id = user_id_input 

60 else: 

61 user_id = lss.get_user_id() 

62 

63 result = {} 

64 

65 

66 

67 return "Welcome to saxia conso !" 

68 

69 

70 return bp 

71 

72 

73 

74 

75 

76def create_saxia_bo_bp(): 

77 bp = Blueprint('saxia_bo', __name__, url_prefix='/api/v1/saxia') 

78 

79# bp.add_url_rule("/", endpoint="index") 

80 @bp.route("duplicate_hash_id_treatment", methods=['POST', 'GET']) 

81 def duplicate_hash_id_treatment(): 

82 if request.method == 'POST': 

83 data_json = request.json 

84 else: 

85 data_json = request.args.to_dict() 

86 hash_id_treatment = data_json.get('hash_id_treatment', None) 

87 

88 from server.safia import lpgss_singleton 

89 

90 one_treatment = lpgss_singleton.load_data_audit(hash_id_treatment=hash_id_treatment, col_csv="hash_id_treatment,cdn") 

91 

92 from auth.lib_auth import create_id 

93 new_hash_id_treatment = create_id() 

94 ret = lpgss_singleton.duplicate_data_audit(hash_id_treatment = hash_id_treatment, 

95 new_hash_id_treatment = new_hash_id_treatment) 

96 

97 # copy data 

98 

99 print("to test") 

100 

101 res = {"new_hash_id_treatment": new_hash_id_treatment, 

102 "hash_id_treatment": hash_id_treatment, 

103 "ret" : ret} 

104 response = Response( 

105 response=json.dumps(res, indent=4, sort_keys=True, default=str), 

106 # json.dumps(res), 

107 status=200, 

108 mimetype='application/json' 

109 ) 

110 return response 

111 return bp 

112