|
10 | 10 | from ...app_context import AppContext |
11 | 11 | from ...consts import ( |
12 | 12 | ButtonValues, |
13 | | - GetTasksReportData, |
14 | 13 | PlainTextUserAction, |
15 | | - BoardListAlias, |
16 | 14 | ) |
17 | 15 | from ...db.db_client import DBClient |
18 | 16 | from ...db.db_objects import Reminder |
|
23 | 21 |
|
24 | 22 | logger = logging.getLogger(__name__) |
25 | 23 |
|
26 | | -SECTIONS = [ |
27 | | - ("Идеи для статей", BoardListAlias.TOPIC_SUGGESTION_1), |
28 | | - ("Готовая тема", BoardListAlias.TOPIC_READY_2), |
29 | | - ("Уже пишу", BoardListAlias.DRAFT_N_PROGRESS_3, True), |
30 | | - ("Передано на редактуру", BoardListAlias.DRAFT_COMPLETED_4), |
31 | | - ("На редактуре", BoardListAlias.PENDING_EDITOR_5), |
32 | | - ("Проверка качества SEO", BoardListAlias.PENDING_SEO_EDITOR_6), |
33 | | - ("Отредактировано", BoardListAlias.APPROVED_EDITOR_7), |
34 | | - ("Отобрано на финальную проверку", BoardListAlias.PENDING_CHIEF_EDITOR_8), |
35 | | - ("Отобрано для публикации", BoardListAlias.PUBLISH_BACKLOG_9), |
36 | | - ("Готово для вёрстки", BoardListAlias.PUBLISH_IN_PROGRESS_10), |
37 | | -] |
38 | | - |
39 | 24 |
|
40 | 25 | def handle_stateless_message(update, tg_context): |
41 | 26 | """ |
@@ -110,117 +95,6 @@ def handle(self) -> Optional[PlainTextUserAction]: |
110 | 95 | raise NotImplementedError |
111 | 96 |
|
112 | 97 |
|
113 | | -def _generate_rubric_summary(update, rubric_name: str) -> None: |
114 | | - try: |
115 | | - app_context = AppContext() |
116 | | - pc = app_context.planka_client |
117 | | - labels = pc.get_labels() |
118 | | - rubric_label = next( |
119 | | - ( |
120 | | - lbl |
121 | | - for lbl in labels |
122 | | - if lbl.name.strip().lower() == rubric_name.strip().lower() |
123 | | - ), |
124 | | - None, |
125 | | - ) |
126 | | - if not rubric_label: |
127 | | - logger.warning( |
128 | | - f"_generate_rubric_summary: Рубрика не найдена: {rubric_name}" |
129 | | - ) |
130 | | - reply( |
131 | | - load( |
132 | | - "rubric_not_found", |
133 | | - rubric_name=rubric_name, |
134 | | - ), |
135 | | - update, |
136 | | - ) |
137 | | - return |
138 | | - |
139 | | - try: |
140 | | - lists = pc.get_lists() |
141 | | - except Exception as e: |
142 | | - logger.error( |
143 | | - f"_generate_rubric_summary: не удалось получить lists: {e}", |
144 | | - exc_info=True, |
145 | | - ) |
146 | | - reply(load("failed_get_board_lists"), update) |
147 | | - return |
148 | | - |
149 | | - message_parts = [ |
150 | | - load( |
151 | | - "rubric_report_job__intro", |
152 | | - rubric=rubric_name, |
153 | | - ) |
154 | | - ] |
155 | | - |
156 | | - had_errors = False |
157 | | - |
158 | | - for column_name, alias, *meta_flag in SECTIONS: |
159 | | - need_meta = bool(meta_flag and meta_flag[0]) |
160 | | - heading = load(alias.value) |
161 | | - target_list = next( |
162 | | - (lst for lst in lists if lst.name.strip().startswith(column_name)), None |
163 | | - ) |
164 | | - |
165 | | - if not target_list: |
166 | | - message_parts.append(f"<b>{heading}</b> (0)") |
167 | | - message_parts.append("") |
168 | | - continue |
169 | | - |
170 | | - try: |
171 | | - cards = pc.get_cards(list_ids=[target_list.id]) |
172 | | - except Exception: |
173 | | - had_errors = True |
174 | | - message_parts.append(f"<b>{heading}</b> (0)") |
175 | | - message_parts.append("") |
176 | | - continue |
177 | | - |
178 | | - filtered = [ |
179 | | - card |
180 | | - for card in cards |
181 | | - if any(lbl.id == rubric_label.id for lbl in card.labels) |
182 | | - ] |
183 | | - |
184 | | - filtered.sort(key=lambda c: c.due or datetime.max) |
185 | | - |
186 | | - count = len(filtered) |
187 | | - message_parts.append(f"<b>{heading}</b> ({count})") |
188 | | - |
189 | | - if not filtered: |
190 | | - message_parts.append("(пусто)") |
191 | | - else: |
192 | | - for card in filtered: |
193 | | - link = f'<a href="{card.url}">{card.name}</a>' |
194 | | - if need_meta: |
195 | | - due_str = ( |
196 | | - card.due.strftime("%d.%m.%Y") if card.due else "без срока" |
197 | | - ) |
198 | | - try: |
199 | | - fields = pc.get_custom_fields(card.id) |
200 | | - authors = ( |
201 | | - ", ".join(fields.authors) |
202 | | - if fields.authors |
203 | | - else "неизвестно" |
204 | | - ) |
205 | | - except Exception: |
206 | | - authors = "неизвестно" |
207 | | - message_parts.append(f"- {link}") |
208 | | - message_parts.append(f" • Дедлайн: {due_str}") |
209 | | - message_parts.append(f" • Автор: {authors}") |
210 | | - else: |
211 | | - message_parts.append(f"- {link}") |
212 | | - |
213 | | - message_parts.append("") |
214 | | - |
215 | | - if had_errors: |
216 | | - message_parts.append(load("partial_data_error ")) |
217 | | - |
218 | | - reply("\n".join(message_parts), update, parse_mode="HTML") |
219 | | - |
220 | | - except Exception: |
221 | | - reply(load("failed_try_later"), update) |
222 | | - |
223 | | - |
224 | 98 | def _show_reminder_edit_options( |
225 | 99 | reminder: Reminder, update: telegram.Update, command_data: dict |
226 | 100 | ): |
@@ -312,32 +186,6 @@ def _handle_task_report_helper(command_data, add_labels, update): |
312 | 186 | return None |
313 | 187 |
|
314 | 188 |
|
315 | | -class GetRubricsChooseRubricHandler(BaseUserMessageHandler): |
316 | | - def handle(self) -> Optional[PlainTextUserAction]: |
317 | | - try: |
318 | | - idx = int(self.user_input) - 1 |
319 | | - rubrics = self.command_data.get( |
320 | | - GetTasksReportData.LISTS |
321 | | - ) or self.tg_context.chat_data.get("available_rubrics", []) |
322 | | - if not (0 <= idx < len(rubrics)): |
323 | | - raise ValueError |
324 | | - except Exception: |
325 | | - reply( |
326 | | - load( |
327 | | - "invalid_rubric_number", |
328 | | - max=len(rubrics), |
329 | | - ), |
330 | | - self.update, |
331 | | - ) |
332 | | - return PlainTextUserAction.GET_RUBRICS__CHOOSE_RUBRIC |
333 | | - |
334 | | - selected = rubrics[idx] |
335 | | - _generate_rubric_summary(self.update, selected) |
336 | | - |
337 | | - self.tg_context.chat_data.pop(consts.LAST_ACTIONABLE_COMMAND, None) |
338 | | - return None |
339 | | - |
340 | | - |
341 | 189 | class GetTasksReportEnterBoardNumberHandler(BaseUserMessageHandler): |
342 | 190 | def handle(self) -> Optional[PlainTextUserAction]: |
343 | 191 | planka_client = PlankaClient() |
|
0 commit comments