def _handle_start(self, bot, update, user_data, team): contacts = models.FlatContact.objects.filter(team_id=team.id)\ .select_related('flat', 'flat__house_block', 'flat__house_block__house')\ .all() reports = {} for contact in contacts: if contact.end_time is None: continue if contact.flat.house_block.house.id not in reports: reports[contact.flat.house_block.house.id] = { 'house': contact.flat.house_block.house, 'flats_count': 0, 'total_seconds': 0, 'statuses': {}, 'newspapers_count': 0, 'flyers_count': 0, 'registrations_count': 0, } report = reports[contact.flat.house_block.house.id] report['flats_count'] += 1 report['total_seconds'] += (contact.end_time - contact.start_time).total_seconds() if contact.status not in report['statuses']: report['statuses'][contact.status] = { 'flats_count': 0, 'total_seconds': 0 } report['statuses'][contact.status]['flats_count'] += 1 report['statuses'][contact.status]['total_seconds'] += ( contact.end_time - contact.start_time).total_seconds() report['newspapers_count'] += contact.newspapers_count report['flyers_count'] += contact.flyers_count report['registrations_count'] += contact.registrations_count lines = [] for report in reports.values(): lines.append('Команда: ' + team.show()) lines.append('Адрес: ' + report['house'].show()) lines.append('Всего: %d квартир (среднее время %dс)' % (report['flats_count'], report['total_seconds'] / report['flats_count'])) for status, stats in report['statuses'].items(): lines.append( ' %s: %d квартир (среднее время %dс)' % (models.FlatContact.Status.get_choice(status).label, stats['flats_count'], stats['total_seconds'] / stats['flats_count'])) lines.append('Газеты: %d' % report['newspapers_count']) lines.append('Листовки: %d' % report['flyers_count']) lines.append('Регистрации: %d' % report['registrations_count']) lines.append('') send_message_text(bot, update, 'Отчёт\n' + '\n'.join(lines), user_data=user_data, parse_mode='Markdown', reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton('<< Назад', callback_data=MENU) ]]))
def _handle_start(self, bot, update, user_data): send_message_text( bot, update, 'Укажите название добавляемой улицы/проспекта/переулка. ' 'Используйте сокращения ул., пр., пер. и другие. ' 'Например, *Вознесенский пр.* или *ул. Мира*', user_data=user_data, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton('<< Назад', callback_data=CHOOSE_STREET) ]]), parse_mode='Markdown')
def _handle_start(self, bot, update, user_data): house_block = models.HouseBlock.objects.select_related('house', 'house__street')\ .get(id=user_data['house_block_id']) send_message_text(bot, update, '%s.\n' 'Укажите номер квартиры, или диапозон квартир.\n' 'Например, *64* или *73-144*.' % house_block.show(), user_data=user_data, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton('<< Назад', callback_data=CHOOSE_FLAT) ]]), parse_mode='Markdown')
def _handle_start(self, bot, update, user_data): house = models.House.objects.select_related('street').get( id=user_data['house_id']) send_message_text( bot, update, 'Укажите номер добавляемого подъезда в %s.\n' 'Только номер, без символов #, № и др.' % house.show(), user_data=user_data, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton('<< Назад', callback_data=CHOOSE_HOUSE_BLOCK) ]]), parse_mode='Markdown')
def _handle_start(self, bot, update, user_data): street = models.Street.objects.get(id=user_data['street_id']) send_message_text(bot, update, 'Укажите номер добавляемого дома на %s.\n' 'Только номер, без слов "дом" и "д.". ' 'Например, 17, 16a, 22к1, 6стр1, 20/3.' % street.show(), user_data=user_data, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton('<< Назад', callback_data=CHOOSE_HOUSE) ]]), parse_mode='Markdown')
def _handle_report_start(self, bot, update, user_data, team): flat = models.Flat.objects.get(id=user_data['flat_id']) my_flat_contact = models.FlatContact.objects.filter( team_id=team.id, flat_id=flat.id).first() if not my_flat_contact: return CHOOSE_FLAT if 'report' not in user_data: user_data['report'] = my_flat_contact.get_report_as_dict() report = user_data['report'] if report['status'] is None: return FLAT_CONTACT_REPORT__SET_STATUS keyboard = [] for name in self._count_fields: keyboard.append([ InlineKeyboardButton('+ ' + self._human_name[name], callback_data='+' + name), InlineKeyboardButton('- ' + self._human_name[name], callback_data='-' + name) ]) keyboard.append([ InlineKeyboardButton('Изменить статус', callback_data=FLAT_CONTACT_REPORT__SET_STATUS) ]) keyboard.append([ InlineKeyboardButton( 'Изменить комментарий' if report['comment'] else 'Оставить комментарий', callback_data=FLAT_CONTACT_REPORT__SET_COMMENT) ]) keyboard.append([ InlineKeyboardButton( 'Изменить контакты' if report['contacts'] else 'Оставить контакты', callback_data=FLAT_CONTACT_REPORT__SET_CONTACTS) ]) keyboard.append( [InlineKeyboardButton('-- Сохранить --', callback_data=END)]) if my_flat_contact.end_time: keyboard.append( [InlineKeyboardButton('-- Отмена --', callback_data=CANCEL)]) send_message_text(bot, update, self._build_report_text(my_flat_contact, report), user_data=user_data, reply_markup=InlineKeyboardMarkup(keyboard), parse_mode='Markdown')
def _handle_report__set_status_start(self, bot, update, user_data, team): flat = models.Flat.objects.get(id=user_data['flat_id']) my_flat_contact = models.FlatContact.objects.filter( team_id=team.id, flat_id=flat.id).first() report = user_data['report'] keyboard = [] for status in models.FlatContact.Status.choices: data = '%s_%d' % (SET_FLAT_CONTACT_STATUS, status[0]) keyboard.append( [InlineKeyboardButton(status[1], callback_data=data)]) keyboard.append( [InlineKeyboardButton('-- Отмена --', callback_data=CANCEL)]) send_message_text(bot, update, self._build_report_text(my_flat_contact, report), user_data=user_data, reply_markup=InlineKeyboardMarkup(keyboard), parse_mode='Markdown')
def show_menu(bot, update, user_data, team): keyboard = [ [InlineKeyboardButton('Выбрать улицу', callback_data=CHOOSE_STREET)], [ InlineKeyboardButton('История обхода', callback_data=SHOW_CONTACTS_HISTORY) ], [InlineKeyboardButton('Отчёт', callback_data=SHOW_TEAM_FINAL_REPORT)], [ InlineKeyboardButton('<< Главное меню', callback_data=END_AGITATION_PROCESS) ] ] send_message_text(bot, update, team.show(markdown=True), reply_markup=InlineKeyboardMarkup(keyboard), user_data=user_data, parse_mode='Markdown')
def _handle_start(self, bot, update, user_data, team): flat = models.Flat.objects.get(id=user_data['flat_id']) my_flat_contact = models.FlatContact.objects.filter( team_id=team.id, flat_id=flat.id).first() another_flat_contact = None if not my_flat_contact: another_flat_contact = models.FlatContact.objects.filter(flat_id=flat.id) \ .filter(Q(status__isnull=False) | ~Q(status=models.FlatContact.Status.NONE)).first() if not another_flat_contact and True: # TODO user = models.User.find_by_telegram_id( update.effective_user.id) my_flat_contact = models.FlatContact(flat=flat, team=team, start_time=datetime.now(), created_by=user) my_flat_contact.save() keyboard = [] if another_flat_contact: text = '%s\nКто-то из волонтеров уже контактировал с этой квартирой' % flat.show( ) keyboard.append( [InlineKeyboardButton('<< Назад', callback_data=BACK)]) elif not my_flat_contact: text = flat.show() keyboard.append( [InlineKeyboardButton('<< Назад', callback_data=BACK)]) elif my_flat_contact.status is not None: text = my_flat_contact.show() keyboard.append([ InlineKeyboardButton('Изменить', callback_data=FLAT_CONTACT_REPORT) ]) keyboard.append( [InlineKeyboardButton('<< Назад', callback_data=BACK)]) else: return FLAT_CONTACT_REPORT send_message_text(bot, update, text, user_data=user_data, reply_markup=InlineKeyboardMarkup(keyboard), parse_mode='Markdown')
def _handle_start(self, bot, update, user_data): query_set = self._get_query_set(user_data) total_count = query_set.count() offset = self._get_offset(user_data) if offset < 0: offset = 0 if offset >= total_count: offset = max(0, total_count - self._page_size) self._set_offset(user_data, offset) objects = list(query_set[offset:][:self._page_size]) buttons = [ InlineKeyboardButton(obj.show(markdown=False, full=False), callback_data=str(obj.id)) for obj in objects ] keyboard = utils.chunks(buttons, self._keyboard_size[0]) keyboard += build_paging_buttons(offset, total_count, self._page_size, True) pattern = self._get_pattern(user_data) if pattern: keyboard.append([ InlineKeyboardButton('-- Сбросить фильтр "%s" --' % pattern, callback_data=CLEAR_FILTER) ]) if self._add_state_name: keyboard.append( [InlineKeyboardButton('+', callback_data=ADD_NEW_OBJECT)]) keyboard.append([ InlineKeyboardButton('< Назад', callback_data=RETURN_TO_BACK), InlineKeyboardButton('<< Меню', callback_data=MENU) ]) text = self._get_text(user_data) if self._can_filter: text += '\nВы можете сузить выбор, отправив сообщение с названием или его частью.' if self._add_state_name: text += '\nЕсли не получается найти нужный вам объект, можете его добавить, нажав на *+*.' send_message_text(bot, update, text, user_data=user_data, parse_mode='Markdown', reply_markup=InlineKeyboardMarkup(keyboard))
def _handle_start(self, bot, update, user_data, team): flat = models.Flat.objects.get(id=user_data['flat_id']) my_flat_contact = models.FlatContact.objects.filter( team_id=team.id, flat_id=flat.id).first() report = user_data['report'] keyboard = [] if report[self.field_name]: keyboard.append([ InlineKeyboardButton('Удалить %s' % self.human_field_name, callback_data=DELETE) ]) keyboard.append( [InlineKeyboardButton('-- Отмена --', callback_data=CANCEL)]) send_message_text( bot, update, '%s\n\n*Введите %s*' % (self.contactor._build_report_text( my_flat_contact, report), self.human_field_name), user_data=user_data, parse_mode='Markdown', reply_markup=InlineKeyboardMarkup(keyboard))