How to use set_status method in lisa

Best Python code snippet using lisa_python

characters.py

Source:characters.py Github

copy

Full Screen

...7class CharacterController(BaseAPIController):8 def get(self):9 current_show = self.get_current_show()10 if not current_show:11 self.set_status(400)12 self.finish({'message': 'No show loaded'})13 return14 show_id = current_show['id']15 character_schema = CharacterSchema()16 if show_id:17 with self.make_session() as session:18 show = session.query(Show).get(show_id)19 if show:20 characters = [character_schema.dump(c) for c in show.character_list]21 self.set_status(200)22 self.finish({'characters': characters})23 else:24 self.set_status(404)25 self.finish({'message': '404 show not found'})26 else:27 self.set_status(404)28 self.write({'message': '404 show not found'})29 async def post(self):30 current_show = self.get_current_show()31 if not current_show:32 self.set_status(400)33 await self.finish({'message': 'No show loaded'})34 return35 show_id = current_show['id']36 if show_id:37 with self.make_session() as session:38 show: Show = session.query(Show).get(show_id)39 if show:40 data = escape.json_decode(self.request.body)41 name = data.get('name', None)42 if not name:43 self.set_status(400)44 await self.finish({'message': 'Name missing'})45 return46 description = data.get('description', None)47 played_by = data.get('played_by', None)48 if played_by:49 cast_member = session.query(Cast).get(played_by)50 if not cast_member:51 self.set_status(404)52 await self.finish({'message': '404 cast member found'})53 return54 session.add(Character(show_id=show.id, name=name, description=description,55 played_by=played_by))56 session.commit()57 self.set_status(200)58 await self.finish({'message': 'Successfully added cast member'})59 await self.application.ws_send_to_all('NOOP', 'GET_CHARACTER_LIST', {})60 else:61 self.set_status(404)62 await self.finish({'message': '404 show not found'})63 else:64 self.set_status(404)65 await self.finish({'message': '404 show not found'})66 async def patch(self):67 current_show = self.get_current_show()68 if not current_show:69 self.set_status(400)70 await self.finish({'message': 'No show loaded'})71 return72 show_id = current_show['id']73 if show_id:74 with self.make_session() as session:75 show: Show = session.query(Show).get(show_id)76 if show:77 data = escape.json_decode(self.request.body)78 character_id = data.get('id', None)79 if not character_id:80 self.set_status(400)81 await self.finish({'message': 'ID missing'})82 return83 entry: Character = session.get(Character, character_id)84 if entry:85 name = data.get('name', None)86 if not name:87 self.set_status(400)88 await self.finish({'message': 'Name missing'})89 return90 entry.name = name91 description = data.get('description', None)92 entry.description = description93 played_by = data.get('played_by', None)94 if played_by:95 cast_member = session.query(Cast).get(played_by)96 if not cast_member:97 self.set_status(404)98 await self.finish({'message': '404 cast member found'})99 return100 entry.played_by = played_by101 session.commit()102 self.set_status(200)103 await self.finish({'message': 'Successfully updated character'})104 await self.application.ws_send_to_all('NOOP', 'GET_CHARACTER_LIST', {})105 else:106 self.set_status(404)107 await self.finish({'message': '404 character not found'})108 return109 else:110 self.set_status(404)111 await self.finish({'message': '404 show not found'})112 else:113 self.set_status(404)114 await self.finish({'message': '404 show not found'})115 async def delete(self):116 current_show = self.get_current_show()117 if not current_show:118 self.set_status(400)119 await self.finish({'message': 'No show loaded'})120 return121 show_id = current_show['id']122 if show_id:123 with self.make_session() as session:124 show: Show = session.query(Show).get(show_id)125 if show:126 data = escape.json_decode(self.request.body)127 character_id = data.get('id', None)128 if not character_id:129 self.set_status(400)130 await self.finish({'message': 'ID missing'})131 return132 entry: Character = session.get(Character, character_id)133 if entry:134 session.delete(entry)135 session.commit()136 self.set_status(200)137 await self.finish({'message': 'Successfully deleted character'})138 await self.application.ws_send_to_all('NOOP', 'GET_CHARACTER_LIST', {})139 else:140 self.set_status(404)141 await self.finish({'message': '404 character not found'})142 else:143 self.set_status(404)144 await self.finish({'message': '404 show not found'})145 else:146 self.set_status(404)147 await self.finish({'message': '404 show not found'})148@ApiRoute('show/character/group', ApiVersion.v1)149class CharacterGroupController(BaseAPIController):150 def get(self):151 current_show = self.get_current_show()152 if not current_show:153 self.set_status(400)154 self.finish({'message': 'No show loaded'})155 return156 show_id = current_show['id']157 character_group_schema = CharacterGroupSchema()158 if show_id:159 with self.make_session() as session:160 show = session.query(Show).get(show_id)161 if show:162 character_groups = [character_group_schema.dump(c)163 for c in show.character_group_list]164 self.set_status(200)165 self.finish({'character_groups': character_groups})166 else:167 self.set_status(404)168 self.finish({'message': '404 show not found'})169 else:170 self.set_status(404)171 self.write({'message': '404 show not found'})172 async def post(self):173 current_show = self.get_current_show()174 if not current_show:175 self.set_status(400)176 await self.finish({'message': 'No show loaded'})177 return178 show_id = current_show['id']179 if show_id:180 with self.make_session() as session:181 show = session.query(Show).get(show_id)182 if show:183 data = escape.json_decode(self.request.body)184 name = data.get('name', None)185 if not name:186 self.set_status(400)187 await self.finish({'message': 'Name missing'})188 return189 description = data.get('description', None)190 character_list = data.get('characters', [])191 character_model_list = []192 for character_id in character_list:193 character = session.query(Character).get(character_id)194 if not character:195 self.set_status(404)196 await self.finish({'message': f'Character {character_id} not found'})197 return198 character_model_list.append(character)199 session.add(CharacterGroup(200 show_id=show_id,201 name=name,202 description=description,203 characters=character_model_list))204 session.commit()205 self.set_status(200)206 await self.finish({'message': 'Successfully added new character group'})207 await self.application.ws_send_to_all('NOOP', 'GET_CHARACTER_GROUP_LIST', {})208 else:209 self.set_status(404)210 await self.finish({'message': '404 show not found'})211 return212 else:213 self.set_status(404)214 self.write({'message': '404 show not found'})215 async def delete(self):216 current_show = self.get_current_show()217 if not current_show:218 self.set_status(400)219 await self.finish({'message': 'No show loaded'})220 return221 show_id = current_show['id']222 if show_id:223 with self.make_session() as session:224 show: Show = session.query(Show).get(show_id)225 if show:226 data = escape.json_decode(self.request.body)227 character_group_id = data.get('id', None)228 if not character_group_id:229 self.set_status(400)230 await self.finish({'message': 'ID missing'})231 return232 entry: CharacterGroup = session.get(CharacterGroup, character_group_id)233 if entry:234 session.delete(entry)235 session.commit()236 self.set_status(200)237 await self.finish({'message': 'Successfully deleted character group'})238 await self.application.ws_send_to_all('NOOP',239 'GET_CHARACTER_GROUP_LIST',240 {})241 else:242 self.set_status(404)243 await self.finish({'message': '404 character not found'})244 else:245 self.set_status(404)246 await self.finish({'message': '404 show not found'})247 else:248 self.set_status(404)249 await self.finish({'message': '404 show not found'})250 async def patch(self):251 current_show = self.get_current_show()252 if not current_show:253 self.set_status(400)254 await self.finish({'message': 'No show loaded'})255 return256 show_id = current_show['id']257 if show_id:258 with self.make_session() as session:259 show: Show = session.query(Show).get(show_id)260 if show:261 data = escape.json_decode(self.request.body)262 character_group_id = data.get('id', None)263 if not character_group_id:264 self.set_status(400)265 await self.finish({'message': 'ID missing'})266 return267 entry: CharacterGroup = session.get(CharacterGroup, character_group_id)268 if entry:269 name = data.get('name', None)270 if not name:271 self.set_status(400)272 await self.finish({'message': 'Name missing'})273 return274 entry.name = name275 entry.description = data.get('description', None)276 character_list = data.get('characters', [])277 character_model_list = []278 for character_id in character_list:279 character = session.query(Character).get(character_id)280 if not character:281 self.set_status(404)282 await self.finish({283 'message': f'Character {character_id} not found'284 })285 return286 character_model_list.append(character)287 entry.characters = character_model_list288 session.commit()289 self.set_status(200)290 await self.finish({'message': 'Successfully updated character group'})291 await self.application.ws_send_to_all(292 'NOOP', 'GET_CHARACTER_GROUP_LIST', {})293 else:294 self.set_status(404)295 await self.finish({'message': '404 character group not found'})296 return297 else:298 self.set_status(404)299 await self.finish({'message': '404 show not found'})300 else:301 self.set_status(404)...

Full Screen

Full Screen

reportcreater.py

Source:reportcreater.py Github

copy

Full Screen

...34 35 def create_report(self):36 if self.parent.report_parameters.report_file_name is None:37 myutils.save_param(myconstants.PARAMETER_FILENAME_OF_LAST_REPORT, "")38 self.parent._mainwindow.ui.set_status("Необходимо выбрать отчётную форму.")39 self.parent._mainwindow.ui.enable_buttons()40 return False41 if self.parent.report_parameters.raw_file_name is None:42 myutils.save_param(myconstants.PARAMETER_FILENAME_OF_LAST_REPORT, "")43 self.parent._mainwindow.ui.set_status("Необходимо выбрать файл, выгруженный из DES.LM для формирования отчёта.")44 self.parent._mainwindow.ui.enable_buttons()45 return False46 47 self.start_timer()48 self.parent._mainwindow.ui.clear_status()49 send_df_2_xls(self.parent.report_parameters)50 51 return True52 def start_timer(self):53 self.start_prog_time = time.time()54 def show_timer(self):55 end_prog_time = time.time()56 duration_in_seconds = int(end_prog_time - self.start_prog_time)57 self.parent._mainwindow.ui.set_status("Время выполнения: {0:0>2}:{1:0>2}".format(duration_in_seconds // 60, duration_in_seconds % 60))58@thread59def send_df_2_xls(report_parameters):60 # Определим ключевые параметры в переменные,61 # чтобы не указывать полную ссылку каждый раз62 raw_file_name = report_parameters.raw_file_name63 report_file_name = report_parameters.report_file_name64 report_prepared_name = report_parameters.report_prepared_name65 p_delete_vip = report_parameters.p_delete_vip66 p_delete_not_prod_units = report_parameters.p_delete_not_prod_units67 p_delete_without_fact = report_parameters.p_delete_without_fact68 p_curr_month_half = report_parameters.p_curr_month_half69 p_delete_pers_data = report_parameters.p_delete_pers_data70 p_delete_vacation = report_parameters.p_delete_vacation71 p_virtual_FTE = report_parameters.p_virtual_FTE72 p_save_without_formulas = report_parameters.p_save_without_formulas73 p_delete_rawdata_sheet = report_parameters.p_delete_rawdata_sheet74 ui_handle = report_parameters.parent._mainwindow.ui75 # ----------------------------------------------------76 num_poz = 177 ui_handle.set_status(myconstants.TEXT_LINES_SEPARATOR)78 ui_handle.set_status(f"{num_poz}. Выбран отчет:\n>> {report_file_name}")79 num_poz += 180 ui_handle.set_status(f"{num_poz}. Выбран файл с данными:\n>> {raw_file_name}")81 num_poz += 182 if p_delete_vip:83 ui_handle.set_status(f"{num_poz}. Данные о VIP удалены.")84 num_poz += 185 if p_curr_month_half:86 ui_handle.set_status(f"{num_poz}. В текущем месяце для расчета FTE использована половина нормы.")87 num_poz += 188 if p_delete_without_fact:89 ui_handle.set_status(f"{num_poz}. Исключены строки с фактом равным нулю.")90 num_poz += 191 ui_handle.set_status(f"{num_poz}. {'В отчете включено только производство.' if p_delete_not_prod_units else 'В отчет включены производство и управленцы.'}")92 num_poz += 193 ui_handle.set_status(f"{num_poz}. Персональные данные (больничные листы): {'исключены из отчета.' if p_delete_pers_data else 'оставлены в отчете.'}")94 num_poz += 195 ui_handle.set_status(f"{num_poz}. Вакансии: {'удалены из отчета.' if p_delete_vacation else 'оставлены в отчете.'}")96 num_poz += 197 ui_handle.set_status(f"{num_poz}. Искусственно добавлены FTE: {'да (если есть).' if p_virtual_FTE else 'нет.'}")98 num_poz += 199 if p_save_without_formulas:100 ui_handle.set_status(f"{num_poz}. Все формулы заменены их значениями (быстрее открывается и меньше размер файла).")101 num_poz += 1102 if p_delete_rawdata_sheet:103 ui_handle.set_status(f"{num_poz}. Удалены закладки с данными (дополнительное уменьшение размера файла).")104 num_poz += 1105 else:106 ui_handle.set_status(f"{num_poz}. Сохранены формулы (возможно медленное открытие и больше размер файла).")107 num_poz += 1108 109 ui_handle.set_status(f"{num_poz}. Округление до: {myconstants.ROUND_FTE_VALUE}-го знака после запятой")110 num_poz += 1111 112 ui_handle.set_status(myconstants.TEXT_LINES_SEPARATOR)113 ui_handle.set_status("Проверим структуру файла, содержащего форму отчёта.")114 try:115 shutil.copyfile(report_file_name, report_prepared_name)116 except (OSError, shutil.Error):117 ui_handle.set_status("Не удалось скопировать файл с формой отчёта.")118 ui_handle.set_status(f"проверьте, пожалуйста, не открыт ли у Вас файл: \n>> {report_prepared_name}")119 ui_handle.set_status("Формирование отчёта не возможно.")120 myutils.save_param(myconstants.PARAMETER_FILENAME_OF_LAST_REPORT, "")121 ui_handle.enable_buttons()122 return False123 pythoncom.CoInitializeEx(0)124 125 oExcel = MyExcel(report_parameters)126 if oExcel.not_ready:127 # Что-то пошло не так.128 return False129 report_df = prepare_data(raw_file_name, p_delete_vip, p_delete_not_prod_units, p_delete_without_fact, p_curr_month_half, p_delete_pers_data, p_delete_vacation, ui_handle)130 ui_handle.set_status(f"Таблица для загрузки полностью подготовлена (всего строк данных: {report_df.shape[0]})")131 ui_handle.set_status("Начинаем перенос строк в Excel:")132 data_sheet = oExcel._wb.Sheets[myconstants.RAW_DATA_SHEET_NAME]133 ulist_sheet = oExcel._wb.Sheets[myconstants.UNIQE_LISTS_SHEET_NAME]134 data_array = report_df.to_numpy()135 data_sheet.Range(data_sheet.Cells(2, 1), data_sheet.Cells(len(data_array) + 1, len(data_array[0]))).Value = data_array 136 137 ui_handle.set_status("Строки в Excel скопированы.")138 ui_handle.set_status("Формируем списки с уникальными значениями.")139 140 # Запоним списки уникальными значениями141 column = 1142 values_dict = dict()143 while True:144 uniq_col_name = ulist_sheet.Cells(1, column).value145 if (type(uniq_col_name) != str) and (uniq_col_name is not None):146 ui_handle.set_status("")147 ui_handle.set_status("")148 ui_handle.set_status("[Ошибка в структуре отчета]")149 ui_handle.set_status("")150 ui_handle.set_status("В файле для выбранной формы на листе для уникальных списков в стороке 1:1 " + \151 "в качестве наименований списков должны быть символьные значения. Формирование отчёта остановлено.")152 return False153 154 if uniq_col_name is not None and uniq_col_name.replace(" ", "") != "":155 values_dict[uniq_col_name] = column156 column += 1157 else:158 break159 full_column_list = report_df.columns.tolist()160 columns_4_unique_list = [column for column in values_dict.keys() if column in full_column_list]161 if len(columns_4_unique_list) == 0:162 ui_handle.set_status("")163 ui_handle.set_status("")164 ui_handle.set_status("[Ошибка в структуре отчета]")165 ui_handle.set_status("")166 ui_handle.set_status("В файле для выбранной формы на листе для уникальных списков не указан " + \167 "уникальный список из возможного перечня. Формирование отчёта остановлено.")168 myutils.save_param(myconstants.PARAMETER_FILENAME_OF_LAST_REPORT, "")169 return False170 ui_handle.set_status(f"Всего списков c уникальными данными: {len(columns_4_unique_list)} шт.")171 ui_handle.set_status("")172 for index, one_column in enumerate(columns_4_unique_list):173 unique_elements_list = sorted(report_df[one_column].unique())174 ui_handle.change_last_status_line(f"{index + 1} из {len(columns_4_unique_list)} ({one_column}): {len(unique_elements_list)}")175 data_array = [[one_uelement] for one_uelement in unique_elements_list]176 ulist_sheet.Range(177 ulist_sheet.Cells(2, values_dict[one_column]), ulist_sheet.Cells(len(data_array) + 1, values_dict[one_column])\178 ).Value = data_array179 180 if len(columns_4_unique_list) == 1:181 ui_handle.change_last_status_line(f"Значений в списке {len(unique_elements_list)} шт.")182 else:183 ui_handle.change_last_status_line("Собраны и сохранены списки с уникальными значениями.")184 oExcel.report_prepared = True185 return True...

Full Screen

Full Screen

acts.py

Source:acts.py Github

copy

Full Screen

...7class ActController(BaseAPIController):8 def get(self):9 current_show = self.get_current_show()10 if not current_show:11 self.set_status(400)12 self.finish({'message': 'No show loaded'})13 return14 show_id = current_show['id']15 act_schema = ActSchema()16 if show_id:17 with self.make_session() as session:18 show = session.query(Show).get(show_id)19 if show:20 acts = [act_schema.dump(c) for c in show.act_list]21 self.set_status(200)22 self.finish({'acts': acts})23 else:24 self.set_status(404)25 self.finish({'message': '404 show not found'})26 else:27 self.set_status(404)28 self.write({'message': '404 show not found'})29 async def post(self):30 current_show = self.get_current_show()31 if not current_show:32 self.set_status(400)33 await self.finish({'message': 'No show loaded'})34 return35 show_id = current_show['id']36 if show_id:37 with self.make_session() as session:38 show = session.query(Show).get(show_id)39 if show:40 data = escape.json_decode(self.request.body)41 name: str = data.get('name', None)42 if not name:43 self.set_status(400)44 await self.finish({'message': 'Name missing'})45 return46 interval_after: bool = data.get('interval_after', None)47 if interval_after is None:48 self.set_status(400)49 await self.finish({'message': 'Interval after missing'})50 return51 previous_act_id: int = data.get('previous_act_id', None)52 session.add(Act(show_id=show.id, name=name, interval_after=interval_after,53 previous_act_id=previous_act_id))54 session.commit()55 self.set_status(200)56 await self.finish({'message': 'Successfully added act'})57 await self.application.ws_send_to_all('NOOP', 'GET_ACT_LIST', {})58 else:59 self.set_status(404)60 await self.finish({'message': '404 show not found'})61 else:62 self.set_status(404)63 await self.finish({'message': '404 show not found'})64 async def patch(self):65 current_show = self.get_current_show()66 if not current_show:67 self.set_status(400)68 await self.finish({'message': 'No show loaded'})69 return70 show_id = current_show['id']71 if show_id:72 with self.make_session() as session:73 show = session.query(Show).get(show_id)74 if show:75 data = escape.json_decode(self.request.body)76 act_id = data.get('id', None)77 if not act_id:78 self.set_status(400)79 await self.finish({'message': 'ID missing'})80 return81 entry: Act = session.get(Act, act_id)82 if entry:83 name = data.get('name', None)84 if not name:85 self.set_status(400)86 await self.finish({'message': 'Name missing'})87 return88 entry.name = name89 interval_after: bool = data.get('interval_after', None)90 if interval_after is None:91 self.set_status(400)92 await self.finish({'message': 'Interval after missing'})93 return94 entry.interval_after = interval_after95 previous_act_id: int = data.get('previous_act_id', None)96 if previous_act_id:97 if previous_act_id == act_id:98 self.set_status(400)99 await self.finish({'message': 'Previous act cannot be current act'})100 return101 previous_act: Act = session.query(Act).get(previous_act_id)102 if not previous_act:103 self.set_status(400)104 await self.finish({'message': 'Previous act not found'})105 return106 act_indexes = [act_id]107 current_act: Act = previous_act108 while current_act is not None and current_act.previous_act is not None:109 if current_act.previous_act.id in act_indexes:110 self.set_status(400)111 await self.finish({112 'message': 'Previous act cannot form a circular '113 'dependency between acts'114 })115 return116 current_act = current_act.previous_act117 entry.previous_act_id = previous_act_id118 session.commit()119 self.set_status(200)120 await self.finish({'message': 'Successfully updated act'})121 await self.application.ws_send_to_all('NOOP', 'GET_ACT_LIST', {})122 else:123 self.set_status(404)124 await self.finish({'message': '404 act not found'})125 return126 else:127 self.set_status(404)128 await self.finish({'message': '404 show not found'})129 else:130 self.set_status(404)131 await self.finish({'message': '404 show not found'})132 async def delete(self):133 current_show = self.get_current_show()134 if not current_show:135 self.set_status(400)136 await self.finish({'message': 'No show loaded'})137 return138 show_id = current_show['id']139 if show_id:140 with self.make_session() as session:141 show: Show = session.query(Show).get(show_id)142 if show:143 data = escape.json_decode(self.request.body)144 act_id = data.get('id', None)145 if not act_id:146 self.set_status(400)147 await self.finish({'message': 'ID missing'})148 return149 entry: Act = session.get(Act, act_id)150 if entry:151 session.delete(entry)152 session.commit()153 self.set_status(200)154 await self.finish({'message': 'Successfully deleted act'})155 await self.application.ws_send_to_all('NOOP', 'GET_ACT_LIST', {})156 else:157 self.set_status(404)158 await self.finish({'message': '404 act not found'})159 else:160 self.set_status(404)161 await self.finish({'message': '404 show not found'})162 else:163 self.set_status(404)164 await self.finish({'message': '404 show not found'})165@ApiRoute('show/act/first_scene', ApiVersion.v1)166class FirstSceneController(BaseAPIController):167 async def post(self):168 current_show = self.get_current_show()169 if not current_show:170 self.set_status(400)171 await self.finish({'message': 'No show loaded'})172 return173 show_id = current_show['id']174 if show_id:175 with self.make_session() as session:176 show = session.query(Show).get(show_id)177 if show:178 data = escape.json_decode(self.request.body)179 act_id: int = data.get('act_id', None)180 if not act_id:181 self.set_status(400)182 await self.finish({'message': 'Act ID missing'})183 return184 if 'scene_id' not in data:185 self.set_status(400)186 await self.finish({'message': 'Scene ID missing'})187 return188 scene_id: int = data.get('scene_id', None)189 if scene_id:190 scene: Scene = session.query(Scene).get(scene_id)191 if not scene:192 self.set_status(404)193 await self.finish({'message': '404 scene not found'})194 return195 if scene.previous_scene_id:196 self.set_status(400)197 await self.finish({198 'message': 'First scene cannot already have previous scene'199 })200 return201 act: Act = session.query(Act).get(act_id)202 if not act:203 self.set_status(404)204 await self.finish({'message': 'Act not found'})205 return206 act.first_scene_id = scene_id207 session.commit()208 self.set_status(200)209 await self.finish({'message': 'Successfully set first scene'})210 await self.application.ws_send_to_all('NOOP', 'GET_ACT_LIST', {})211 else:212 self.set_status(404)213 await self.finish({'message': '404 show not found'})214 else:215 self.set_status(404)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful