From eaed8c04867ada143f24f62b919ca3d131e18bd7 Mon Sep 17 00:00:00 2001 From: Ilya Ilchenko Date: Fri, 16 Jul 2021 08:55:50 +0300 Subject: [PATCH] :rainbow: move constants and library imports from the eval method it was copy-pasted from sync module, where telegram is a demo and we don't require to installing telegram package close #294 --- sync_telegram/__manifest__.py | 2 +- sync_telegram/doc/changelog.rst | 8 +++++++- sync_telegram/models/sync_project.py | 26 ++++++++++---------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sync_telegram/__manifest__.py b/sync_telegram/__manifest__.py index 4205db06..498370e8 100644 --- a/sync_telegram/__manifest__.py +++ b/sync_telegram/__manifest__.py @@ -7,7 +7,7 @@ "summary": """Telegram integration powered by Sync Studio""", "category": "Discuss", "images": ["images/sync_telegram.jpg"], - "version": "14.0.3.2.1", + "version": "14.0.3.2.2", "application": False, "author": "IT Projects Labs, Ilya Ilchenko", "support": "help@itpp.dev", diff --git a/sync_telegram/doc/changelog.rst b/sync_telegram/doc/changelog.rst index 6ab3ba08..0f37af07 100644 --- a/sync_telegram/doc/changelog.rst +++ b/sync_telegram/doc/changelog.rst @@ -1,7 +1,13 @@ +`3.2.2` +------- + +- **Improvement:** code clean up + `3.2.1` ------- -**Improvement:** In cases when there are many subscribed partners channel name was too long +- **Improvement:** In cases when there are many subscribed partners channel name was too long + `3.2.0` ------- diff --git a/sync_telegram/models/sync_project.py b/sync_telegram/models/sync_project.py index 37d6e690..557ae207 100644 --- a/sync_telegram/models/sync_project.py +++ b/sync_telegram/models/sync_project.py @@ -7,13 +7,23 @@ import logging import requests +from lxml.html.clean import Cleaner +from telegram import ( # pylint: disable=missing-manifest-dependency; disabled because pre-commit cannot find external dependency in manifest. https://github.com/itpp-labs/DINAR/issues/91 + Bot, + Update, +) from odoo import api, fields, models +from odoo.tools import html2plaintext from odoo.addons.sync.models.sync_project import AttrDict _logger = logging.getLogger(__name__) +MAX_SIZE_IMAGE = 10485760 +MAX_SIZE_DOCUMENT = 52428800 +MAX_SIZE_TO_DOWNLOAD = 20971520 + class SyncProjectTelegram(models.Model): @@ -32,26 +42,10 @@ def _eval_context_telegram(self, secrets, eval_context): * telegram.setWebhook * telegram.parse_data """ - from lxml.html.clean import Cleaner - - from odoo.tools import html2plaintext - - try: - # https://github.com/python-telegram-bot/python-telegram-bot - from telegram import ( # pylint: disable=missing-manifest-dependency - Bot, - Update, - ) - except (ImportError, IOError) as err: - _logger.debug(err) log_transmission = eval_context["log_transmission"] log = eval_context["log"] - MAX_SIZE_IMAGE = 10485760 - MAX_SIZE_DOCUMENT = 52428800 - MAX_SIZE_TO_DOWNLOAD = 20971520 - if secrets.TELEGRAM_BOT_TOKEN: bot = Bot(token=secrets.TELEGRAM_BOT_TOKEN) else: