Coverage for chalicelib/utils/email_helper.py: 15%

60 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 12:56 +0000

1from chalicelib.utils.TimeUTC import TimeUTC 

2from chalicelib.utils.email_handler import __get_html_from_file, send_html 

3 

4 

5def send_team_invitation(recipient, client_id, sender_name, invitation_link): 

6 BODY_HTML = __get_html_from_file("chalicelib/utils/html/invitation.html", 

7 formatting_variables={"invitationLink": invitation_link, 

8 "clientId": client_id, 

9 "sender": sender_name}) 

10 SUBJECT = "Welcome to OpenReplay" 

11 send_html(BODY_HTML, SUBJECT, recipient) 

12 

13 

14def send_forgot_password(recipient, invitation_link): 

15 BODY_HTML = __get_html_from_file("chalicelib/utils/html/reset_password.html", 

16 formatting_variables={"invitationLink": invitation_link}) 

17 SUBJECT = "Password recovery" 

18 send_html(BODY_HTML, SUBJECT, recipient) 

19 

20 

21def send_assign_session(recipient, message, link): 

22 BODY_HTML = __get_html_from_file("chalicelib/utils/html/assignment.html", 

23 formatting_variables={"message": message, 

24 "now": TimeUTC.to_human_readable(TimeUTC.now()), 

25 "link": link}) 

26 SUBJECT = "assigned session" 

27 send_html(BODY_HTML, SUBJECT, recipient) 

28 

29 

30def alert_email(recipients, subject, data): 

31 BODY_HTML = __get_html_from_file("chalicelib/utils/html/alert_notification.html", formatting_variables=data) 

32 send_html(BODY_HTML=BODY_HTML, SUBJECT=subject, recipient=recipients) 

33 

34 

35def __get_color(idx): 

36 return "#3EAAAF" if idx == 0 else "#77C3C7" if idx == 1 else "#9ED4D7" if idx == 2 else "#99d59a" 

37 

38 

39def weekly_report2(recipients, data): 

40 data["o_tr_u"] = "" 

41 data["o_tr_d"] = "" 

42 for d in data["days_partition"]: 

43 data[ 

44 "o_tr_u"] += f"""<td valign="bottom" style="padding:0 5px 0 0;width:14%;font-weight:300;margin:0;text-align:left"> 

45 <table style="width:100%;font-weight:300;margin-bottom:0;border-collapse:collapse"> 

46 <tbody> 

47 <tr style="font-weight:300"> 

48 <td height="{d["value"]}px" title="{d["issues_count"]}" style="font-size:0;padding:0;font-weight:300;margin:0;line-height:0;background-color:#C5E5E7;text-align:left">&nbsp;</td> 

49 </tr> 

50 </tbody></table> 

51 </td>""" 

52 data[ 

53 "o_tr_d"] += f"""<td title="{d["day_long"]}, midnight" style="font-size:10px;color:#333333;padding:3px 5px 0 0;width:14%;font-weight:300;margin:0;text-align:center">{d["day_short"]}</td>""" 

54 

55 data[ 

56 "past_week_issues_status"] = f'<img src="img/weekly/arrow-{"increase" if data["past_week_issues_evolution"] > 0 else "decrease"}.png" width="15px" height="10px" style="font-weight:300;vertical-align:middle">' 

57 data["week_decision"] = "More" if data["past_week_issues_evolution"] > 0 else "Fewer" 

58 data["past_week_issues_evolution"] = abs(data["past_week_issues_evolution"]) 

59 data[ 

60 "past_month_issues_status"] = f'<img src="img/weekly/arrow-{"increase" if data["past_month_issues_evolution"] > 0 else "decrease"}.png" width="15px" height="10px" style="font-weight:300;vertical-align:middle">' 

61 data["month_decision"] = "More" if data["past_month_issues_evolution"] > 0 else "Fewer" 

62 data["past_month_issues_evolution"] = abs(data["past_month_issues_evolution"]) 

63 data["progress_legend"] = [] 

64 data["progress_tr"] = "" 

65 for idx, i in enumerate(data["issues_by_type"]): 

66 color = __get_color(idx) 

67 data["progress_legend"].append( 

68 f"""<td style="padding:0;font-weight:300;margin:0;text-align:left;"> 

69 <span style="white-space:nowrap;"><span style="border-radius:50%;font-weight:300;vertical-align:bottom;color:#fff;width:16px;height:16px;margin:0 8px;display:inline-block;background-color:{color}"></span>{i["count"]}</span><span style="font-weight:300;margin-left:5px;margin-right:0px;white-space:nowrap;">{i["type"]}</span> 

70 </td>""") 

71 data[ 

72 "progress_tr"] += f'<td width="{i["value"]}%" title="{i["count"]} {i["type"]}" style="padding:0;font-weight:300;margin:0;background-color:{color};text-align:left">&nbsp;</td>' 

73 

74 data["progress_legend"] = '<tr style="font-weight:300;font-size:13px;">' + "".join( 

75 data["progress_legend"]) + "</tr>" 

76 data["breakdown_list"] = "" 

77 color_breakdown = {} 

78 data["breakdown_list_other"] = "" 

79 for idx, i in enumerate(data["issues_breakdown_list"]): 

80 if idx < len(data["issues_breakdown_list"]) - 1 or i["type"].lower() != "others": 

81 color = __get_color(idx) 

82 color_breakdown[i["type"]] = color 

83 data["breakdown_list"] += f"""<tr style="font-weight:300"> 

84 <td style="font-size:14px;padding:5px 0;font-weight:300;margin:0;text-align:left;white-space:nowrap;"><span style="vertical-align: middle;border-radius:50%;width:1em;font-weight:300;display:inline-block;background-color:{color};height:1em"></span>&nbsp;&nbsp;{i["type"]}</td> 

85 <td style="font-size:14px;padding:5px 0;font-weight:300;margin:0;text-align:left"><a href="%(frontend_url)s" style="color:#394EFF;font-weight:300;text-decoration:none" target="_blank" data-saferedirecturl="#">{i["sessions_count"]}</a></td> 

86 <td style="font-size:14px;padding:5px 0;font-weight:300;margin:0;text-align:left"><img src="img/weekly/arrow-{"increase" if i["last_week_sessions_evolution"] > 0 else "decrease"}.png" width="10px" height="7px" style="font-weight:300;vertical-align:middle;margin-right: 3px;"> {abs(i["last_week_sessions_evolution"])}%</td> 

87 <td style="font-size:14px;padding:5px 0;font-weight:300;margin:0;text-align:left"><img src="img/weekly/arrow-{"increase" if i["last_month_sessions_evolution"] > 0 else "decrease"}.png" width="10px" height="7px" style="font-weight:300;vertical-align:middle;margin-right: 3px;"> {abs(i["last_month_sessions_evolution"])}%</td> 

88 </tr>""" 

89 else: 

90 data["breakdown_list_other"] = f"""<tfoot style="font-weight:300"> 

91 <tr style="font-weight:300"> 

92 <td style="font-size:14px;padding:5px 0;font-weight:300;margin:0;text-align:left;white-space:nowrap;"><span style="vertical-align: middle;border-radius:50%;width:1em;font-weight:300;display:inline-block;background-color:#999999;height:1em"></span>&nbsp;&nbsp;{i["type"]}</td> 

93 <td style="font-size:14px;padding:5px 0;font-weight:300;margin:0;text-align:left"><a href="%(frontend_url)s" style="color:#394EFF;font-weight:300;text-decoration:none" target="_blank" data-saferedirecturl="#">{i["sessions_count"]}</a></td> 

94 <td style="font-size:14px;padding:5px 0;font-weight:300;margin:0;text-align:left"><img src="img/weekly/arrow-{"increase" if i["last_week_sessions_evolution"] > 0 else "decrease"}.png" width="10px" height="7px" style="font-weight:300;vertical-align:middle;margin-right: 3px;"> {abs(i["last_week_sessions_evolution"])}%</td> 

95 <td style="font-size:14px;padding:5px 0;font-weight:300;margin:0;text-align:left"><img src="img/weekly/arrow-{"increase" if i["last_month_sessions_evolution"] > 0 else "decrease"}.png" width="10px" height="7px" style="font-weight:300;vertical-align:middle;margin-right: 3px;"> {abs(i["last_month_sessions_evolution"])}%</td> 

96 </tr> 

97 </tfoot>""" 

98 data["b_tr_u"] = "" 

99 data["b_tr_d"] = "" 

100 for i in data["issues_breakdown_by_day"]: 

101 data[ 

102 "b_tr_d"] += f"""<td title="{i["day_long"]}" style="font-size:14px;color:#333333;padding:10px 0 0;width:14%;border-right:10px solid #fff;font-weight:300;margin:0;text-align:center"> 

103 {i["day_short"]} 

104 </td>""" 

105 if len(i["partition"]) > 0: 

106 sup_partition = "" 

107 for j in i["partition"]: 

108 sup_partition += f'<tr style="font-weight:300"><td height="{j["value"]}" title="{j["count"]} {j["type"]}" style="font-size:0;padding:0;border-right:none;font-weight:300;margin:0;line-height:0;background-color:{color_breakdown[j["type"]]};text-align:left"></td></tr>' 

109 else: 

110 sup_partition = '<tr style="font-weight:300"><td height="3" style="font-size:0;padding:0;border-right:none;font-weight:300;margin:0;line-height:0;background-color:#999999;text-align:left"></td></tr>' 

111 data[ 

112 "b_tr_u"] += f"""<td valign="bottom" style="font-size:0;font-weight:300;padding:0;width:14%;border-right:10px solid #fff;height:110px;margin:0;text-align:left"> 

113 <table style="width:100%;font-weight:300;margin-bottom:0;border-collapse:collapse"> 

114 <tbody>{sup_partition}</tbody> 

115 </table> 

116 </td>""" 

117 BODY_HTML = __get_html_from_file("chalicelib/utils/html/Project-Weekly-Report.html", formatting_variables=data) 

118 SUBJECT = "OpenReplay Project Weekly Report" 

119 send_html(BODY_HTML=BODY_HTML, SUBJECT=SUBJECT, recipient=recipients)