def section_pub(SITE): print('FUNCTION -> system-> calalog -> section -> pub/unpub') type = SITE.p[2] id = SITE.p[3] SECTION = Section(SITE) cat_id = SECTION.pub(type, id) if 'cancel' in SITE.post: return {'redirect': '/system/catalog/cat/' + str(cat_id)} return {'redirect': '/system/catalog/cat/' + str(cat_id)}
def section_delete(SITE): print('FUNCTION -> system-> calalog -> section -> delete') id = SITE.post['id'] SECTION = Section(SITE) if 'agree' in SITE.post and SITE.post['agree'] == 'yes': cat_id = SECTION.delete(id) else: cat_id = SECTION.getSection(id)['catalog_id'] return {'redirect': '/system/catalog/cat/' + str(cat_id)}
def section_list(SITE): print('FUNCTION -> system-> calalog -> section -> list') section_id = SITE.p[2] CATALOG = Catalog(SITE) SECTION = Section(SITE) section = SECTION.getSection(section_id) catalog = CATALOG.getItem(section['catalog_id']) row_out = '<tr><td>* * ТЕСТ * *<td><tr>' SITE.content += f'''<div class="bg_gray">
def section_insert(SITE): print('FUNCTION -> system-> calalog -> section -> insert') if 'cancel' in SITE.post: return {'redirect': '/system/catalog/cat/' + SITE.post['catalog_id']} SECTION = Section(SITE) SECTION.insert({ 'catalog_id': SITE.post['catalog_id'], 'parent_id': SITE.post['parent_id'], 'name': SITE.post['name'], 'text': SITE.post['text'], 'data': SITE.post['data'], 'status': SITE.post['status'], 'ordering': SITE.post['ordering'] }) return {'redirect': '/system/catalog/cat/' + SITE.post['catalog_id']}
def section_update(SITE): print('FUNCTION -> system-> calalog -> section -> update') section_id = SITE.p[3] SECTION = Section(SITE) section = SECTION.getSection(section_id) # Получаем текущий элемент catalog_id = section['catalog_id'] if 'cancel' in SITE.post: return {'redirect': '/system/catalog/cat/' + str(catalog_id)} SECTION.update({ 'id': section_id, 'parent_id': SITE.post['parent_id'], 'name': SITE.post['name'], 'text': SITE.post['text'], 'data': SITE.post['data'], 'status': SITE.post['status'], 'ordering': SITE.post['ordering'] }) return {'redirect': '/system/catalog/cat/' + str(catalog_id)}
def cat_sec_list(SITE): print('FUNCTION -> system_> calalog -> cat -> sec_list') catalog_id = SITE.p[2] SITE.addHeadFile('/templates/system/catalog/cat/sec.js') CATALOG = Catalog(SITE) catalog = CATALOG.getItem(catalog_id) SECTION = Section(SITE) rows = SECTION.tree(catalog_id) row_out = '' i = 1 if (rows): for row in rows: level = ' - ' * row['level'] status_tr_class = '' if row['status'] == 0: status_tr_class = 'class="admin_table_tr_unpub"' row_out += f''' <tr { status_tr_class }> <td>{ i }</td> <td> <div class="flex_row contextmenu_wrap"> <svg class="contextmenu_ico" title="Действия" data-id="{ row['id'] }"> <use xlink:href="/templates/system/svg/sprite.svg#menu_3"></use> </svg> </div> </td> <td> <a href="/system/catalog/section/{ row['id'] }">{ level }{ row['name'] }</a> </td> </tr> ''' i += 1 SITE.content += f'''<div class="bg_gray">
def load_sections(settings, session): """ Reads sections from the phpIpam API and creates Section objects :param settings: :param session: :return: session """ logging.debug('------- ENTERING FUNCTION: load_sections() -------') url_sections = settings.url_app + '/sections/' headers = { 'app_id': str(settings.app), 'Content-Type': 'application/json', 'token': str(session.token) # calling token will auto-validate freshenss } r = requests.get(url_sections, headers=headers, verify=False) if r.json().get('success'): for j_section in r.json().get('data'): s_id = j_section.get('id') s_name = j_section.get('name') s_description = j_section.get('description') s_mastersection = j_section.get('masterSection') s_permissions = j_section.get('permissions') s_strictmode = j_section.get('strictMode') s_subnetordering = j_section.get('subnetOrdering') s_order = j_section.get('order') s_showvlan = j_section.get('showVLAN') s_showvrf = j_section.get('showVRF') s_dns = j_section.get('DNS') # now build the Section object w_section = Section(s_name) w_section.id = s_id w_section.name = s_name w_section.description = s_description w_section.masterSection = s_mastersection w_section.permission = s_permissions w_section.strictMode = s_strictmode w_section.subnetOrdering = s_subnetordering w_section.order = s_order w_section.showVLAN = s_showvlan w_section.showVRF = s_showvrf w_section.DNS = s_dns # now add section to working session data session.sections.append(w_section) for section in session.sections: if section.name == settings.default_section: session.default_section_id = section.id else: logging.critical('ERROR') return session
def section_edit(SITE): print('PATH -> system/catalog/section/edit') CATALOG = Catalog(SITE) SECTION = Section(SITE) if SITE.p[2] == 'edit': section = SECTION.getSection(SITE.p[3]) catalog_id = section['catalog_id'] catalog = CATALOG.getItem(catalog_id) title = 'Редактировать раздел' action = 'update/' + SITE.p[3] else: catalog_id = SITE.p[3] catalog = CATALOG.getItem(catalog_id) title = 'Добавить раздел' action = 'insert' # ordering = SECTION.getMaxOrdering() + 1 ordering = 1 section = {'id': 0, 'parent_id': 0, 'name': '', 'text': '', 'data': '', 'status': 1, 'ordering': ordering} rows = SECTION.tree(catalog_id) sec_options = '' tabu_level = 1000 # Уровень, ниже которого опускаться нельзя для дочерних пунктов нашего раздела if (rows): for row in rows: if row['id'] == section['id']: # Если это текущий раздел, не отображать его и дочерние разделы tabu_level = row['level'] continue if row['level'] <= tabu_level: # Вышли из дочерних разделов текущего раздела - всё сбрасываем tabu_level = 1000 level = ' - ' * row['level'] selected = 'selected' if row['id'] == section['parent_id'] else '' sec_options += f'''<option { selected } value="{ row['id'] }">{ level }{ row['name'] }</option>''' SITE.content += '''<div class="bg_gray"> <h1>''' + title + '''</h1> <div class="breadcrumbs"> <a href="/system/"><svg class="home"><use xlink:href="/templates/system/svg/sprite.svg#home"></use></svg></a> <svg><use xlink:href="/templates/system/svg/sprite.svg#arrow_right_1"></use></svg> <a href="/system/catalog/cat">Каталог</a> <svg><use xlink:href="/templates/system/svg/sprite.svg#arrow_right_1"></use></svg> <a href="/system/catalog/cat/''' + str(catalog_id) + '''">''' + catalog['name'] + '''</a> <svg><use xlink:href="/templates/system/svg/sprite.svg#arrow_right_1"></use></svg> <span>''' + title + '''</span> </div> <form method="post" action="/system/catalog/section/''' + action + '''"> <div class="tc_container"> <div class="flex_row p_5_20"> <div class="tc_item_l">Наименование</div> <div class="tc_item_r flex_grow"> <input class="input" name="name" placeholder="Раздел 1" required value="''' + section['name'] + '''"> </div> </div> <div class="flex_row p_5_20"> <div class="tc_item_l">Родительский раздел</div> <div class="tc_item_r flex_grow"> <select class="input" name="parent_id"> <option value="0">Нет</option> ''' + sec_options + ''' </select> </div> </div> <div class="flex_row p_5_20"> <textarea class="input" name="text" style="width:100%;height:100px;">''' + section['text'] + '''</textarea> </div> <div class="flex_row p_5_20"> <div class="tc_item_l">Данные</div> <div class="tc_item_r flex_grow"> <textarea class="input" name="data" style="width:100%;height:100px;">''' + section['data'] + '''</textarea> </div> </div> <div class="flex_row p_5_20"> <div class="tc_item_l">Статус</div> <div class="tc_item_r flex_grow"> <input class="input" name="status" type="number" value="''' + str(section['status']) + '''"> </div> </div> <div class="flex_row p_5_20"> <div class="tc_item_l">Порядок следования</div> <div class="tc_item_r flex_grow"> <input class="input" name="ordering" type="number" value="''' + str(section['ordering']) + '''"> </div> </div> <div class="flex_row p_5_20"> <div class="tc_item_l"><input class="button_green" type="submit" name="submit" value="Сохранить"></div> <div class="tc_item_r flex_grow"><input class="button_white" type="submit" name="cancel" value="Отменить"></div> </div> </div> <input class="input" name="catalog_id" type="hidden" value="''' + str(catalog_id) + '''">