def main_web_menu(stylesheet_number: str) -> str: """Function create main web-page""" name = "Доступные действия в базе ремонтов Малахит-Екатеринбург" menu = [ (1, 'Операции с предприятиями'), (2, 'Операции с оборудованием'), (3, 'Операции с ремонтами'), (4, 'Операции с сотрудниками'), (5, 'Баг-трекер системы'), (6, 'Работа с заявками'), (7, 'Изменить тему оформления'), (8, 'Изменения в системе'), ] links_list = [ '/points', '/equips', '/works', '/workers', '/bugs', '/orders-and-customers', '/next-themes', '/changelog-page', ] table = uhtml.universal_table(name, ['№', 'выполнить:'], menu, True, links_list) return web_template.result_page(table, "", stylesheet_number)
def equips_menu(stylesheet_number) -> str: """Method create main EQUIP-page""" name = 'Действия с оборудованием' menu = [(1, 'Все зарегестрированное оборудование'), (2, 'Поиск по ID')] links_list = ['/all-equips', '/find-equip-to-id'] table = uhtml.universal_table(name, ['№', 'Доступное действие'], menu, True, links_list) return web_template.result_page(table, '/', str(stylesheet_number))
def add_work_method(data, method, stylesheet_number: str) -> str: """Method add new work in database""" if method == "POST": password = data[uhtml.PASSWORD] equip_id = data[uhtml.EQUIP_ID] query = data[uhtml.QUERY] work = data[uhtml.WORK] work_datetime = data[uhtml.WORK_DATETIME].replace("T", ' ') + ':00' pre_adr = '/work/' + str(equip_id) perfomer = data[uhtml.PERFORMER] if functions.is_valid_password(password): if work.replace(" ", "") == '': page = uhtml.data_is_not_valid() else: with Database() as base: connection, cursor = base insert_operations.create_new_work(cursor, equip_id, work_datetime, query, work, perfomer) connection.commit() page = uhtml.operation_completed() else: page = uhtml.pass_is_not_valid() else: page = "Method in Add Work not corrected!" pre_adr = '/' return web_template.result_page(page, pre_adr, str(stylesheet_number))
def upgrade_equip_method(data, method, stylesheet_number: str) -> str: """Upgrade database if all values is correct and return html-page""" pre_adr = '/all-equips' if method == "POST": equip_name = data[uhtml.EQUIP_NAME] equip_id = data[uhtml.EQUIP_ID] equip_model = data[uhtml.MODEL] equip_number = data[uhtml.SERIAL_NUM] equip_pre_id = data[uhtml.PRE_ID] password = data[uhtml.PASSWORD] if functions.is_superuser_password(password): if equip_name.replace(" ", '') == '': page = uhtml.data_is_not_valid() else: with Database() as base: connection, cursor = base update_operations.update_equip_information(cursor, equip_id, equip_name, equip_model, equip_number, equip_pre_id) connection.commit() page = uhtml.operation_completed() else: page = uhtml.pass_is_not_valid() else: page = "Method in Edit Point not corrected!" return web_template.result_page(page, pre_adr, str(stylesheet_number))
def equip_to_point_limit(point_id, page_num, stylesheet_number: str) -> str: """Method create table contain equips. Use limit view on page""" with Database() as base: _, cursor = base all_equips = select_operations.get_equip_in_point_limit(cursor, point_id, page_num) links_list = ['/work/{}'.format(equip[0]) for equip in all_equips] data = [[equip[i] for i in range(0, len(equip))] for equip in all_equips] for i, row in enumerate(data): extended_links = ['<a href="/edit-equip/{0}" title="Редактировать">{1}</a>'. format(row[0], EDIT_CHAR) + ' ' + ('<a href="/change-point/{0}" title="Переместить ' + 'на другой обьект">{1}</a>'). format(row[0], REMOVE_CHAR)] if row[0] != row[5]: extended_links[0] += ' ' + \ '<a href="/remove-table/{0}" title="' \ 'Таблица перемещений">{1}</a>'. \ format(row[0], TABLE_REMOVE_CHAR) data[i] = row[1:] + extended_links table1 = uhtml.universal_table(table_headers.equips_table_name, table_headers.equips_table, data, True, links_list) pages = uhtml.paging_table("/equip/{0}/page".format(point_id), functions. list_of_pages(select_operations. get_equip_in_point(cursor, str(point_id))), int(page_num)) table2 = uhtml.add_new_equip(point_id) if point_id != '0' else "" return web_template.result_page(table1 + pages + table2, '/all-points', str(stylesheet_number))
def find_work_like_date_paging(find_string: str, data_start: str, data_stop: str, page_num: str, stylesheet_number: str) -> str: """Create table contain result find from works and data""" with Database() as base: _, cursor = base date_start_correct = data_start.replace('T', ' ') date_stop_correct = data_stop.replace('T', ' ') pages_list = functions.list_of_pages( select_operations.get_all_works_like_word_and_date( cursor, find_string, date_start_correct, date_stop_correct)) works = select_operations.get_all_works_like_word_and_date_limit( cursor, find_string, date_start_correct, date_stop_correct, int(page_num)) works = functions.works_table_add_new_performer(works) result = uhtml.universal_table(table_headers.works_table_name, table_headers.works_table, [list(work) for work in works]) pages_table = uhtml.paging_table( '/find/work/{0}/{1}/{2}/page'.format(find_string, date_start_correct, date_stop_correct), pages_list, int(page_num)) return web_template.result_page(result + pages_table, '/find', str(stylesheet_number))
def all_bugs_in_work_table(stylesheet_number: str) -> str: """Method create page. contain all unclosed bugs""" with Database() as base: _, cursor = base bugs_list = select_operations.get_all_bugz_in_work_in_bugzilla(cursor) table = uhtml.universal_table(table_headers.bugs_table_name, table_headers.bugs_table, bugs_list) return web_template.result_page(table, '/bugs', str(stylesheet_number))
def works_menu(stylesheet_number: str) -> str: """Return main menu in WORKS section""" name = 'Действия с ремонтами и диагностиками' menu = [(1, 'Все зарегистрированные работы'), (2, 'Поиск работы по ID')] links_list = ['/all-works', '/find-work-to-id'] table = uhtml.universal_table(name, ['№', 'Доступное действие'], menu, True, links_list) return web_template.result_page(table, '/', str(stylesheet_number))
def edit_equip_method(equip_id: str, stylesheet_number: str) -> str: """Return page for edit equips information""" with Database() as base: _, cursor = base equip = select_operations.get_full_equip_information(cursor, str(equip_id)) page = uhtml.edit_equip_information([equip_id] + equip) return web_template.result_page(page, '/all-equips', str(stylesheet_number))
def bugs_menu(stylesheet_number: str) -> str: """Method create main bugs-page""" menu = [(1, 'Отобразить все'), (2, 'Отобразить незакрытые'), (3, 'Зарегистрировать проблемму')] headers = ['№', 'Выполнить'] links_list = ['/all-bugs', '/all-bugs-in-work', '/add-bug'] table = uhtml.universal_table('Возможные действия', headers, menu, True, links_list) return web_template.result_page(table, '/bugs', str(stylesheet_number))
def system_status_page(preview_page, stylesheet_number: str) -> str: """Function create System-Status Web-page""" current_status = system_status.SystemStatus.get_status() status_to_list = [[key, current_status[key]] for key in current_status] result = uhtml.universal_table(table_headers.all_workers_table_name, table_headers.system_status_table, status_to_list) return web_template.result_page(result, preview_page, str(stylesheet_number))
def orders_main_menu(stylesheet_number: str) -> str: """Function create main page in ORDERS section""" menu = [(1, 'Все заказчики'), (2, 'Все зарегистрированные заявки')] links = ['/all-customers-table', '/all-registred-orders'] table = uhtml.universal_table('Действия с заявками', ['№', 'Действие'], menu, True, links) preview_page = '/' return web_template.result_page(table, preview_page, str(stylesheet_number))
def all_registered_orders_table(stylesheet_number: str) -> str: """Function create page. contain list of all registered orders""" with Database() as base: _, cursor = base table = uhtml.universal_table(table_headers.orders_table_name, table_headers.orders_table, select_operations.get_all_orders(cursor)) return web_template.result_page(table, '/orders-and-customers', str(stylesheet_number))
def select_work_to_id_method(data, method, stylesheet_number: str) -> str: """Method return page, contain work likes WORK_ID""" pre_adr = '/works' if method == "POST": work_id = data['id'] if work_id == '0': return redirect('/all-works') with Database() as base: _, cursor = base work = select_operations.get_full_information_to_work( cursor, str(work_id)) work = functions.works_table_add_new_performer([work]) table1 = uhtml.universal_table(table_headers.works_table_name, table_headers.works_table, work) return web_template.result_page(table1, pre_adr, str(stylesheet_number)) else: return web_template.result_page("Method in Select Work not corrected!", pre_adr, str(stylesheet_number))
def select_point_to_equip_method(equip_id: str, stylesheet_number: str) -> str: """Create form to select new point to current equip""" with Database() as base: _, cursor = base equip = select_operations.get_full_equip_information(cursor, str(equip_id)) point_id = select_operations.get_point_id_from_equip_id(cursor, equip_id) equip = [equip_id] + equip page = uhtml.select_point_form(equip, point_id) return web_template.result_page(page, '/', str(stylesheet_number))
def select_equip_to_id_page(data, method, stylesheet_number: str) -> str: """Create page to select EQUIP from EQUIP_ID""" pre_adr = '/equips' if method == "POST": equip_id = data['id'] if equip_id == '0': return redirect('/all-equips') with Database() as base: _, cursor = base equip = select_operations.get_full_equip_information(cursor, str(equip_id)) links_list = ['/work/' + str(equip_id)] table1 = uhtml.universal_table(table_headers.equips_table_name, table_headers.equips_table, [equip], True, links_list) return web_template.result_page(table1, pre_adr, str(stylesheet_number)) else: return web_template.result_page("Method in Select Equip not corrected!", pre_adr, str(stylesheet_number))
def add_equip_method(data, method, stylesheet_number: str) -> str: """Create page from ADD NEW EQUIP""" if method == "POST": point_id = data[uhtml.POINT_ID] equip_name = data[uhtml.EQUIP_NAME] model = data[uhtml.MODEL] serial_num = data[uhtml.SERIAL_NUM] pre_id = data[uhtml.PRE_ID] password = data[uhtml.PASSWORD] if functions.is_valid_password(password): with Database() as base: connection, cursor = base if equip_name.replace(" ", '') == '': page = uhtml.data_is_not_valid() pre_addr = '/' elif model == '': insert_operations.create_new_equip(cursor, point_id, equip_name) connection.commit() page = uhtml.operation_completed() pre_addr = '/equip/' + str(point_id) elif serial_num == '': insert_operations.create_new_equip(cursor, point_id, equip_name, model) connection.commit() page = uhtml.operation_completed() pre_addr = '/equip/' + str(point_id) elif pre_id == '': insert_operations.create_new_equip(cursor, point_id, equip_name, model, serial_num) connection.commit() page = uhtml.operation_completed() pre_addr = '/equip/' + str(point_id) else: insert_operations.create_new_equip(cursor, point_id, equip_name, model, serial_num, pre_id) connection.commit() page = uhtml.operation_completed() pre_addr = '/equip/' + str(point_id) else: page = uhtml.pass_is_not_valid() pre_addr = '/equip/' + str(point_id) else: page = 'Method in Add Equip not corrected!' pre_addr = '/all-points' return web_template.result_page(page, pre_addr, str(stylesheet_number))
def statistics_page(preview_page, stylesheet_number: str) -> str: """Function create STATISTIC web-page""" with Database() as base: _, cursor = base statistics = select_operations.get_statistic(cursor) links_list = ['/equip/' + str(elem[0]) for elem in statistics] result = uhtml.universal_table(table_headers.statistics_table_name, table_headers.statistics_table, [[elem[i] for i in range(1, len(elem))] for elem in statistics], True, links_list) return web_template.result_page(result, preview_page, str(stylesheet_number))
def add_bugs_result_table(data, method, stylesheet_number: str) -> str: """Add new bug in bug tracker after use input form to add bug""" if method == 'POST': bug_description = data[uhtml.DESCRIPTION] password = data[uhtml.PASSWORD] pre_adr = '/bugs' if functions.is_valid_password(password): with Database() as base: connection, cursor = base insert_operations.add_new_bug_in_bugzilla( cursor, bug_description) connection.commit() return web_template.result_page(uhtml.operation_completed(), pre_adr, str(stylesheet_number)) else: return web_template.result_page(uhtml.pass_is_not_valid(), pre_adr, str(stylesheet_number)) else: return web_template.result_page('Method in Add New Bug not corrected!', '/bugs', str(stylesheet_number))
def find_equip_to_id_page(stylesheet_number: str) -> str: """Create page to FIND equip FROM EQUIP_ID""" with Database() as base: _, cursor = base max_equip_id = select_operations.get_maximal_equip_id(cursor) find_table = list() find_table.append('<table><caption>Поиск оборудования по уникальному ID</caption>') find_table.append('<form action="/select-equip-to-id" method="post">') find_table.append('<tr><td><input type="number" name="id" min="0" max="' + max_equip_id + '"></td></tr>') find_table.append('<tr><td><input type="submit" value="Найти"></td></tr>') return web_template.result_page("\n".join(find_table), '/equips', str(stylesheet_number))
def find_method(data, method, stylesheet_number: str) -> str: """Switch for different find methods""" if method == "POST": find_request = data[uhtml.FIND_REQUEST] find_from_table = data[uhtml.FIND_IN_TABLE] if find_from_table == uhtml.WORKS_IGNORED_DATE: page = redirect('/find/work/{0}/page/1'.format(find_request)) elif find_from_table == uhtml.WORKS: page = redirect('/find/work/{0}/{1}/{2}/page/1'.format( find_request, data[uhtml.WORK_DATETIME_START], data[uhtml.WORK_DATETIME_STOP])) elif find_from_table == uhtml.WORKS_POINTS: page = redirect('/find/point/{0}/page/1'.format(find_request)) elif find_from_table == uhtml.EQUIPS: page = redirect('/find/equip/{0}/page/1'.format(find_request)) else: page = web_template.result_page('Not corrected selected in Find!', '/', str(stylesheet_number)) else: page = web_template.result_page('Method in Find Page not corrected!', '/', str(stylesheet_number)) return page
def find_work_to_id_page(stylesheet_number: str) -> str: """Return page, contain form to find work like WORK_ID""" with Database() as base: _, cursor = base max_work_id = select_operations.get_maximal_work_id(cursor) find_table = list() find_table.append( '<table><caption>Поиск выполненной работы по уникальному ID</caption>' ) find_table.append('<form action="/select-work-to-id" method="post">') find_table.append( '<tr><td><input type="number" name="id" min="0" max="' + max_work_id + '"></td></tr>') find_table.append( '<tr><td><input type="submit" value="Найти"></td></tr>') return web_template.result_page("\n".join(find_table), '/works', str(stylesheet_number))
def find_work_paging(find_string: str, page_num: str, stylesheet_number: str) -> str: """Create table contain result find from only works""" with Database() as base: _, cursor = base works = select_operations.get_all_works_like_word_limit( cursor, find_string, int(page_num)) works = functions.works_table_add_new_performer(works) pages_list = functions.list_of_pages( select_operations.get_all_works_like_word(cursor, find_string)) result = uhtml.universal_table(table_headers.works_table_name, table_headers.works_table, [list(work) for work in works]) pages_table = uhtml.paging_table( '/find/work/{0}/page'.format(find_string), pages_list, int(page_num)) return web_template.result_page(result + pages_table, '/find', str(stylesheet_number))
def faq_page(pre_adr: str, stylesheet_number: str) -> str: """Function create FAQ web-page""" with Database() as base: _, cursor = base page = list() page.append( '<table><caption>Наиболее частые вопросы по системе:</caption><tr><td>' ) page.append('<ul>') page.append('<li class="faq_question">Что нужно для использования системы?'+\ web_template.faq_state_machine('hardware') + '</li>') page.append( '<li class="faq_question">С использованием каких технологий ' + 'написана система?' + web_template.faq_state_machine('tecnology') + '</li>') page.append('<li class="faq_question">Сколько пользователей поддерживает система?' +\ web_template.faq_state_machine('multiuser') + '</li>') page.append('<li class="faq_question">Планируется ли развитие системы?' +\ web_template.faq_state_machine('update') + '</li>') max_equip_id = select_operations.get_maximal_equip_id(cursor) max_point_id = select_operations.get_maximal_points_id(cursor) max_work_id = select_operations.get_maximal_work_id(cursor) page.append('<li class="faq_question">Сколько записей зарегистрированно на ' + ' данный момент?' +\ uhtml.list_to_ul(['Единиц или групп оборудования: <a href="' + config.full_address + '/all-equips">' + str(max_equip_id) + '</a>', 'Предприятий: <a href="' + config.full_address + '/all-points">' + str(max_point_id) + '</a>', 'Произведенных работ: <a href="' + config.full_address + '/all-works">' + str(max_work_id) + '</a>']) + '</li>') page.append('<li class="faq_question">Текущий размер базы данных : ' + str(select_operations.get_size_database(cursor)) + '</li>') page.append( '<li class="faq_question">Среднее количество работ на смену : ' + str( select_operations.get_count_unique_works(cursor) / select_operations.get_count_unique_dates_in_works(cursor)) + '</li>') page.append('</ul></td></tr></table>') return web_template.result_page('\n'.join(page), pre_adr, str(stylesheet_number))
def remove_table_page(equip_id: str, stylesheet_number: str) -> str: """Method create table for all moving equip""" result = [] with Database() as base: _, cursor = base equip_info = [str(equip_id)] +\ select_operations.get_full_equip_information(cursor, str(equip_id)) result.insert(0, equip_info) while str(equip_info[0]) != str(equip_info[5]): old_equip_id = str(equip_info[5]) equip_info = [old_equip_id] +\ select_operations.get_full_equip_information(cursor, old_equip_id) result.insert(0, equip_info) links = ['/work/{0}'.format(elem[0]) for elem in result] page = uhtml.universal_table(table_headers.remove_table_name, table_headers.remove_table, result, True, links) return web_template.result_page(page, "/", str(stylesheet_number))
def find_point_page(find_string: str, page_num: str, stylesheet_number: str) -> str: """Create table contain result find from only works points""" with Database() as base: _, cursor = base points = select_operations.get_all_points_list_from_like_str_limit( cursor, find_string, int(page_num)) pages_list = functions.list_of_pages( select_operations.get_all_points_list_from_like_str( cursor, find_string)) links_list = ['/equip/' + str(elem[0]) for elem in points] result = uhtml.universal_table(table_headers.points_table_name, table_headers.points_table, [[point[1], point[2], point[3]] for point in points], True, links_list) pages_table = uhtml.paging_table( '/find/point/{0}/page'.format(find_string), pages_list, int(page_num)) return web_template.result_page(result + pages_table, '/find', str(stylesheet_number))
def find_equip_page(find_string: str, page_num: str, stylesheet_number: str) -> str: """Create table contains result find from equips only""" with Database() as base: _, cursor = base equips = select_operations.get_all_equips_list_from_like_str_limit( cursor, find_string, int(page_num)) pages_list = functions.list_of_pages( select_operations.get_all_equips_list_from_like_str( cursor, find_string)) links_list = ['/work/' + str(equip[0]) for equip in equips] result = uhtml.universal_table( table_headers.equips_table_name, table_headers.equips_table, [[equip[i] for i in range(1, len(equip))] for equip in equips], True, links_list) pages_table = uhtml.paging_table( '/find/equip/{0}/page'.format(find_string), pages_list, int(page_num)) return web_template.result_page(result + pages_table, '/find', str(stylesheet_number))
def work_to_equip_paging(equip_id, page_id, stylesheet_number: str) -> str: """Return page, contain works from current equip""" with Database() as base: _, cursor = base pre_adr = ('/equip/' + str(select_operations. get_point_id_from_equip_id(cursor, equip_id))) \ if str(equip_id) != '0' \ else '/works' full_works = select_operations.get_works_from_equip_id_limit( cursor, equip_id, page_id) full_works = functions.works_table_add_new_performer(full_works) table1 = uhtml.universal_table(table_headers.works_table_name, table_headers.works_table, full_works) table2 = uhtml.add_new_work(equip_id) if str(equip_id) != 0 else "" table_paging = uhtml.paging_table( "/work/{0}/page".format(equip_id), functions.list_of_pages( select_operations.get_works_from_equip_id(cursor, equip_id)), int(page_id)) return web_template.result_page(table1 + table_paging + table2, pre_adr, str(stylesheet_number))
def move_equip_method(data, method, stylesheet_number: str) -> str: """Move equip to new point""" pre_adr = '/' if method == 'POST': if functions.is_superuser_password(data[uhtml.PASSWORD]): if data[uhtml.POINT_ID] == data[uhtml.NEW_POINT_ID]: page = uhtml.data_is_not_valid() else: with Database() as base: connection, cursor = base name_old = select_operations.get_point_name_from_id(cursor, str(data[uhtml.POINT_ID])) name_new = select_operations.\ get_point_name_from_id(cursor, str(data[uhtml.NEW_POINT_ID])) date_remove = functions.date_to_browser().replace("T", ' ') + ':00' insert_operations.create_new_work(cursor, str(data[uhtml.EQUIP_ID]), date_remove, "Перемещение оборудования", "Перемещено из {0} в {1}.". format(name_old, name_new), '1') insert_operations.create_new_equip(cursor, data[uhtml.NEW_POINT_ID], data[uhtml.EQUIP_NAME], data[uhtml.MODEL], str(data[uhtml.SERIAL_NUM]), str(data[uhtml.EQUIP_ID])) connection.commit() page = uhtml.operation_completed() else: page = uhtml.pass_is_not_valid() else: page = "Method in Move Point not corrected!" return web_template.result_page(page, pre_adr, str(stylesheet_number))
def find_page(preview_page, stylesheet_number: str) -> str: """Create main find table for all operations""" return web_template.result_page(uhtml.find_table(), preview_page, str(stylesheet_number))