Skip to content

Commit

Permalink
Telebot update: Add cmdtrans decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
mitshel committed Apr 7, 2018
1 parent ee4de82 commit 98b05b5
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 137 deletions.
Binary file modified opds_catalog/locale/ru/LC_MESSAGES/django.mo
Binary file not shown.
125 changes: 71 additions & 54 deletions opds_catalog/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-03 22:20+0300\n"
"POT-Creation-Date: 2018-04-07 16:38+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -259,6 +259,76 @@ msgstr "секция"
msgid "subsection"
msgstr "подсекция"

#: .\opds_catalog\management\commands\sopds_telebot.py:45
#, python-format
msgid ""
"Hello %s!\n"
"Unfortunately you do not have access to information. Please contact the bot "
"administrator."
msgstr ""
"Здравствуйте %s!\n"
"К сожалению у Вас отсутствует доступ к информации. Обратитесь к "
"администратору бота."

#: .\opds_catalog\management\commands\sopds_telebot.py:46
#, python-format
msgid "Denied access for user: %s"
msgstr "Отказ в доступе для пользователя: %s"

#: .\opds_catalog\management\commands\sopds_telebot.py:65
#, python-format
msgid ""
"%(subtitle)s\n"
"Hello %(username)s! To search for a book, enter part of her title or author:"
msgstr ""
"%(subtitle)s\n"
"Здравствуйте %(username)s! Для поиска книги, введите часть ее наименования "
"или автора:"

#: .\opds_catalog\management\commands\sopds_telebot.py:168
#, python-format
msgid "(doubles:%s) "
msgstr "(дубликатов:%s) "

#: .\opds_catalog\management\commands\sopds_telebot.py:187
msgid "Too short for search, please try again."
msgstr "Слишком короткая строка для поиска, попробуйте еще раз."

#: .\opds_catalog\management\commands\sopds_telebot.py:189
#, python-format
msgid "I'm searching for the book: %s"
msgstr "Выполняю поиск книги: %s"

#: .\opds_catalog\management\commands\sopds_telebot.py:201
msgid "No results were found for your query, please try again."
msgstr "По Вашему запросу ничего не найдено, попробуйте еще раз."

#: .\opds_catalog\management\commands\sopds_telebot.py:206
#, python-format
msgid ""
"Found %s books.\n"
"I create list, after a few seconds, select the file to download:"
msgstr ""
"Найдено %s книг(и). \n"
"Формирую список, через несколько секунд выберите нужную для скачивания:"

#: .\opds_catalog\management\commands\sopds_telebot.py:244
#: .\opds_catalog\management\commands\sopds_telebot.py:281
msgid ""
"The book on the link you specified is not found, try to repeat the book "
"search first."
msgstr ""
"Книга по указанной Вами ссылке не найдена, попробуйте повторить поиск книги "
"сначала."

#: .\opds_catalog\management\commands\sopds_telebot.py:250
msgid "Annotation:"
msgstr "Аннотация:"

#: .\opds_catalog\management\commands\sopds_telebot.py:313
msgid "There was a technical error, please contact the Bot administrator."
msgstr "Возникла техническая ошибка, обратитесь к администратору Бота."

#: .\opds_catalog\sopdscan.py:233
msgid "Unknown author"
msgstr "Неизвестный автор"
Expand All @@ -268,59 +338,6 @@ msgstr "Неизвестный автор"
msgid "All books by %(full_name)s"
msgstr "Все книги автора %(full_name)s"

#~ msgid ""
#~ "Hello %s!\n"
#~ "Unfortunately you do not have access to information. Please contact the "
#~ "bot administrator."
#~ msgstr ""
#~ "Здравствуйте %s!\n"
#~ "К сожалению у Вас отсутствует доступ к информации. Обратитесь к "
#~ "администратору бота."

#~ msgid "Denied access for user: %s"
#~ msgstr "Отказ в доступе для пользователя: %s"

#~ msgid ""
#~ "%(subtitle)s\n"
#~ "Hello %(username)s! To search for a book, enter part of her title or "
#~ "author:"
#~ msgstr ""
#~ "%(subtitle)s\n"
#~ "Здравствуйте %(username)s! Для поиска книги, введите часть ее "
#~ "наименования или автора:"

#~ msgid "(doubles:%s) "
#~ msgstr "(дубликатов:%s) "

#~ msgid "Too short for search, please try again."
#~ msgstr "Слишком короткая строка для поиска, попробуйте еще раз."

#~ msgid "I'm searching for the book: %s"
#~ msgstr "Выполняю поиск книги: %s"

#~ msgid "No results were found for your query, please try again."
#~ msgstr "По Вашему запросу ничего не найдено, попробуйте еще раз."

#~ msgid ""
#~ "Found %s books.\n"
#~ "I create list, after a few seconds, select the file to download:"
#~ msgstr ""
#~ "Найдено %s книг(и). \n"
#~ "Формирую список, через несколько секунд выберите нужную для скачивания:"

#~ msgid ""
#~ "The book on the link you specified is not found, try to repeat the book "
#~ "search first."
#~ msgstr ""
#~ "Книга по указанной Вами ссылке не найдена, попробуйте повторить поиск "
#~ "книги сначала."

#~ msgid "Annotation:"
#~ msgstr "Аннотация:"

#~ msgid "There was a technical error, please contact the Bot administrator."
#~ msgstr "Возникла техническая ошибка, обратитесь к администратору Бота."

#~ msgid "Book name:"
#~ msgstr "Название:"

Expand Down
17 changes: 15 additions & 2 deletions opds_catalog/management/commands/sopds_telebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@

query_delimiter = "####"

def cmdtrans(func):
def wrapper(self, bot, update):
translation.activate(config.SOPDS_LANGUAGE)
result = func(self, bot, update)
translation.deactivate()
return result

return wrapper


def CheckAuthDecorator(func):
def wrapper(self, bot, update):

if not config.SOPDS_TELEBOT_AUTH:
return func(self, bot, update)

Expand Down Expand Up @@ -60,7 +68,6 @@ def add_arguments(self, parser):
parser.add_argument('--daemon',action='store_true', dest='daemonize', default=False, help='Daemonize server')

def handle(self, *args, **options):
translation.activate(config.SOPDS_LANGUAGE)
self.pidfile = os.path.join(main_settings.BASE_DIR, config.SOPDS_TELEBOT_PID)
action = options['command']
self.logger = logging.getLogger('')
Expand Down Expand Up @@ -96,6 +103,7 @@ def handle(self, *args, **options):
pid = open(self.pidfile, "r").read()
self.restart(pid)

@cmdtrans
@CheckAuthDecorator
def startCommand(self, bot, update):
bot.sendMessage(chat_id=update.message.chat_id, text=_("%(subtitle)s\nHello %(username)s! To search for a book, enter part of her title or author:")%
Expand Down Expand Up @@ -176,6 +184,7 @@ def BookPager(self, books, page_num, query):

return {'message':response, 'buttons':markup}

@cmdtrans
@CheckAuthDecorator
def getBooks(self, bot, update):
query=update.message.text
Expand Down Expand Up @@ -208,6 +217,7 @@ def getBooks(self, bot, update):
response = self.BookPager(books, 1, query)
bot.send_message(chat_id=update.message.chat_id, text=response['message'], parse_mode='HTML', reply_markup=response['buttons'])

@cmdtrans
@CheckAuthDecorator
def getBooksPage(self, bot, update):
callback_query = update.callback_query
Expand All @@ -224,6 +234,7 @@ def getBooksPage(self, bot, update):
bot.edit_message_text(chat_id=callback_query.message.chat_id, message_id=callback_query.message.message_id, text=response['message'], parse_mode='HTML', reply_markup=response['buttons'])
return

@cmdtrans
@CheckAuthDecorator
def downloadBooks(self, bot, update):
book_id_set=re.findall(r'\d+$',update.message.text)
Expand Down Expand Up @@ -260,6 +271,7 @@ def downloadBooks(self, bot, update):
self.logger.info("Send download buttons.")
return

@cmdtrans
@CheckAuthDecorator
def getBookFile(self, bot, update):
callback_query = update.callback_query
Expand Down Expand Up @@ -315,6 +327,7 @@ def getBookFile(self, bot, update):

return

@cmdtrans
@CheckAuthDecorator
def botCallback(self, bot, update):
query = update.callback_query
Expand Down
Binary file not shown.
79 changes: 0 additions & 79 deletions opds_catalog/management/locale/ru/LC_MESSAGES/django.po

This file was deleted.

Binary file modified sopds/locale/ru/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion sopds/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-03 22:20+0300\n"
"POT-Creation-Date: 2018-04-07 16:38+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
Binary file modified sopds_web_backend/locale/ru/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion sopds_web_backend/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-03 22:20+0300\n"
"POT-Creation-Date: 2018-04-07 16:38+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down

0 comments on commit 98b05b5

Please sign in to comment.