33from partner_programs .models import PartnerProgramUserProfile
44from project_rates .models import Criteria , ProjectScore
55
6-
76logger = logging .getLogger ()
87
98
@@ -23,16 +22,14 @@ class ProjectScoreDataPreparer:
2322 "Класс_курс" : "ОШИБКА" ,
2423 }
2524
26- EXPERT_ERROR_FIELDS = {
27- "Фамилия эксперта" : "ОШИБКА"
28- }
25+ EXPERT_ERROR_FIELDS = {"Фамилия эксперта" : "ОШИБКА" }
2926
3027 def __init__ (
3128 self ,
3229 user_profiles : dict [int , PartnerProgramUserProfile ],
3330 scores : dict [int , list [ProjectScore ]],
3431 project_id : int ,
35- program_id : int
32+ program_id : int ,
3633 ):
3734 self ._project_id = project_id
3835 self ._user_profiles = user_profiles
@@ -41,35 +38,54 @@ def __init__(
4138
4239 def get_project_user_info (self ) -> dict [str , str ]:
4340 try :
44- user_program_profile : PartnerProgramUserProfile = self ._user_profiles .get (self ._project_id )
45- user_program_profile_json : dict = user_program_profile .partner_program_data if user_program_profile else {}
41+ user_program_profile : PartnerProgramUserProfile = self ._user_profiles .get (
42+ self ._project_id
43+ )
44+ user_program_profile_json : dict = (
45+ user_program_profile .partner_program_data if user_program_profile else {}
46+ )
4647
4748 user_info : dict [str , str ] = {
48- "Фамилия" : user_program_profile .user .last_name if user_program_profile else '' ,
49- "Имя" : user_program_profile .user .first_name if user_program_profile else '' ,
50- "Отчество" : user_program_profile .user .patronymic if user_program_profile else '' ,
49+ "Фамилия" : (
50+ user_program_profile .user .last_name if user_program_profile else ""
51+ ),
52+ "Имя" : (
53+ user_program_profile .user .first_name if user_program_profile else ""
54+ ),
55+ "Отчество" : (
56+ user_program_profile .user .patronymic if user_program_profile else ""
57+ ),
5158 "Email" : (
52- user_program_profile_json .get ('email' ) if user_program_profile_json .get ('email' )
59+ user_program_profile_json .get ("email" )
60+ if user_program_profile_json .get ("email" )
5361 else user_program_profile .user .email
5462 ),
55- "Регион_РФ" : user_program_profile_json .get ('region' , '' ),
56- "Учебное_заведение" : user_program_profile_json .get ('education_type' , '' ),
57- "Название_учебного_заведения" : user_program_profile_json .get ('institution_name' , '' ),
58- "Класс_курс" : user_program_profile_json .get ('class_course' , '' ),
63+ "Регион_РФ" : user_program_profile_json .get ("region" , "" ),
64+ "Учебное_заведение" : user_program_profile_json .get ("education_type" , "" ),
65+ "Название_учебного_заведения" : user_program_profile_json .get (
66+ "institution_name" , ""
67+ ),
68+ "Класс_курс" : user_program_profile_json .get ("class_course" , "" ),
5969 }
6070 return user_info
6171 except Exception as e :
62- logger .error (f"Prepare export rates data about user error: { str (e )} " , exc_info = True )
72+ logger .error (
73+ f"Prepare export rates data about user error: { str (e )} " , exc_info = True
74+ )
6375 return self .USER_ERROR_FIELDS
6476
6577 def get_project_expert_info (self ) -> dict [str , str ]:
6678 try :
6779 project_scores : list [ProjectScore ] = self ._scores .get (self ._project_id , [])
6880 first_score = project_scores [0 ] if project_scores else None
69- expert_last_name : dict [str , str ] = {"Фамилия эксперта" : first_score .user .last_name if first_score else '' }
81+ expert_last_name : dict [str , str ] = {
82+ "Фамилия эксперта" : first_score .user .last_name if first_score else ""
83+ }
7084 return expert_last_name
7185 except Exception as e :
72- logger .error (f"Prepare export rates data about expert error: { str (e )} " , exc_info = True )
86+ logger .error (
87+ f"Prepare export rates data about expert error: { str (e )} " , exc_info = True
88+ )
7389 return self .EXPERT_ERROR_FIELDS
7490
7591 def get_project_scores_info (self ) -> dict [str , str ]:
@@ -78,16 +94,29 @@ def get_project_scores_info(self) -> dict[str, str]:
7894 project_scores : list [ProjectScore ] = self ._scores .get (self ._project_id , [])
7995 score_info_with_out_comment : dict [str , str ] = {
8096 score .criteria .name : score .value
81- for score in project_scores if score .criteria .name != "Комментарий"
97+ for score in project_scores
98+ if score .criteria .name != "Комментарий"
8299 }
83100 project_scores_dict .update (score_info_with_out_comment )
84- comment = next ((score for score in project_scores if score .criteria .name == "Комментарий" ), None )
101+ comment = next (
102+ (
103+ score
104+ for score in project_scores
105+ if score .criteria .name == "Комментарий"
106+ ),
107+ None ,
108+ )
85109 if comment is not None :
86110 project_scores_dict ["Комментарий" ] = comment .value
87111 return project_scores_dict
88112 except Exception as e :
89- logger .error (f"Prepare export rates data about project_scores error: { str (e )} " , exc_info = True )
113+ logger .error (
114+ f"Prepare export rates data about project_scores error: { str (e )} " ,
115+ exc_info = True ,
116+ )
90117 return {
91118 criteria .name : "ОШИБКА"
92- for criteria in Criteria .objects .filter (partner_program__id = self ._program_id )
119+ for criteria in Criteria .objects .filter (
120+ partner_program__id = self ._program_id
121+ )
93122 }
0 commit comments