def send_services(bot, message, page=1): services = Services.select().join(Buttons).paginate( page, config.SERVICES_PER_PAGE) msg = None if services.count() == 0: return user = TelegramUsers.get(TelegramUsers.telegram_id == message.from_user.id) for service in services: inline_keyboard = None if service.buttons: inline_keyboard = InlineKeyboardMarkup() for button in service.buttons: btn = InlineKeyboardButton(text=button.title( user.language_code), url=urljoin(config.USSD_URL, quote(button.ussd))) inline_keyboard.add(btn) if inline_keyboard: kwargs = {'reply_markup': inline_keyboard} else: kwargs = None text = f"<b>{service.title(user.language_code)}</b>\n" \ f"{service.description(user.language_code)}" msg = bot.send_message(message.chat.id, text=text, parse_mode='html', **kwargs) return msg
def get_report(): org_id = request.args['org_id'] session_org_id = session.get('org_id', None) if session.get('logged_in') is not None and str(session_org_id) == org_id: print 'Organization id: ', org_id service = Services.select().where(Services.org_id == org_id) print 'Services rows: ', len(service) services = [[items.service_type.name, items.extension] for items in service] i = IncomingLog.select().where(IncomingLog.org == org_id) org_name = i[0].org.name if request.method == 'POST': print request.form if 'commentform' in request.form: log_id = request.form['log_id'] comment = request.form['comment'] Comment.create(log_id=log_id, comment=comment) if 'status' in request.form: log_id = request.form['log_id'] status = request.form['status'] print status i = IncomingLog.update(status=status).where( IncomingLog.id == log_id) i.execute() if 'service' in request.args and 'extension' in request.args: service_name = str(request.args['service']) extension = str(request.args['extension']) reports = [] try: for i in IncomingLog.select().where( IncomingLog.org == org_id, IncomingLog.service == service_name, IncomingLog.extension == extension).order_by( IncomingLog.id.desc()): item = [] item.append(i.incoming_number) item.append(i.call_start_time) item.append(i.generalized_data_incoming.data) item.append(i.id) item.append(i.comment_set) item.append(i.status) org_name = i.org.name reports.append(item) return render_template('report.html', title='Report', output=reports, org_name=org_name, to=extension, org_id=org_id, services=services, service_name=service_name) except: flash('No reports available for this service!') return redirect(url_for('get_report', org_id=org_id)) else: return render_template('report.html', title='Report', org_id=org_id, services=services, org_name=org_name) else: return redirect(url_for('index'))