コード例 #1
0
ファイル: sidebar.py プロジェクト: iceman1989/Check_mk
def ajax_tag_tree():
    newconf = int(html.var("conf"))
    tree_conf = config.load_user_file("virtual_host_tree", {"tree": 0, "cwd": {}})
    if type(tree_conf) == int:
        tree_conf = {"cwd":{}} # convert from old style
    tree_conf["tree"] = newconf
    config.save_user_file("virtual_host_tree", tree_conf)
コード例 #2
0
def ajax_tag_tree_enter():
    path = html.var("path") and html.var("path").split("|") or []
    tree_conf = config.load_user_file("virtual_host_tree", {
        "tree": 0,
        "cwd": {}
    })
    tree_conf["cwd"][tree_conf["tree"]] = path
    config.save_user_file("virtual_host_tree", tree_conf)
コード例 #3
0
ファイル: pagetypes.py プロジェクト: NeilBryant/check_mk
    def save_user_instances(self, owner=None):
        if not owner:
            owner = config.user_id

        save_dict = {}
        for page in self.instances():
            if page.owner() == owner:
                save_dict[page.name()] = page.internal_representation()

        config.save_user_file("user_%ss" % self.type_name(), save_dict, user=owner)
コード例 #4
0
ファイル: pagetypes.py プロジェクト: bopopescu/check_mk-2
    def save_user_instances(cls, owner=None):
        if not owner:
            owner = config.user.id

        save_dict = {}
        for page in cls.instances():
            if page.owner() == owner:
                save_dict[page.name()] = page.internal_representation()

        config.save_user_file('user_%ss' % cls.type_name(), save_dict, owner)
コード例 #5
0
ファイル: htmllib.py プロジェクト: stasic/check_mk
 def invalidate_transid(self, id):
     used_ids = config.load_user_file("transids", [])
     new_ids = []
     now = time.time()
     for used_id in used_ids:
         timestamp, rand = used_id.split("/")
         if now - int(timestamp) < 604800: # 7 * 24 hours
             new_ids.append(used_id)
     used_ids.append(id)
     config.save_user_file("transids", used_ids)
コード例 #6
0
ファイル: weblib.py プロジェクト: v-a/check_mk
def set_rowselection(ident, rows, action):
    vo = config.load_user_file("rowselection/%s" % selection_id(), {})

    if action == 'set':
        vo[ident] = rows

    elif action == 'add':
        vo[ident] = list(set(vo.get(ident, [])).union(rows))

    elif action == 'del':
        vo[ident] = list(set(vo.get(ident, [])) - set(rows))

    elif action == 'unset':
        del vo[ident]

    if not os.path.exists(config.user_confdir + '/rowselection'):
        make_nagios_directory(config.user_confdir + '/rowselection')

    config.save_user_file("rowselection/%s" % selection_id(), vo)
コード例 #7
0
def set_rowselection(ident, rows, action):
    vo = config.load_user_file("rowselection/%s" % selection_id(), {})

    if action == 'set':
        vo[ident] = rows

    elif action == 'add':
        vo[ident] = list(set(vo.get(ident, [])).union(rows))

    elif action == 'del':
        vo[ident] = list(set(vo.get(ident, [])) - set(rows))

    elif action == 'unset':
        del vo[ident]

    if not os.path.exists(config.user_confdir + '/rowselection'):
        make_nagios_directory(config.user_confdir + '/rowselection')

    config.save_user_file("rowselection/%s" % selection_id(), vo)
コード例 #8
0
ファイル: sidebar.py プロジェクト: iceman1989/Check_mk
def ajax_tag_tree_enter():
    path = html.var("path") and html.var("path").split("|") or []
    tree_conf = config.load_user_file("virtual_host_tree", {"tree": 0, "cwd": {}})
    tree_conf["cwd"][tree_conf["tree"]] = path
    config.save_user_file("virtual_host_tree", tree_conf)
コード例 #9
0
def ajax_switch_help():
    config.save_user_file("help", html.var("enabled", "") != "")
コード例 #10
0
ファイル: sidebar.py プロジェクト: iceman1989/Check_mk
def save_user_config(user_config):
    if config.may("general.configure_sidebar"):
        config.save_user_file("sidebar", user_config)
コード例 #11
0
ファイル: bi.py プロジェクト: itouch2web/check_mk
def save_ex_level(current_ex_level):
    config.save_user_file("bi_treestate", (current_ex_level, ))
コード例 #12
0
ファイル: html_mod_python.py プロジェクト: alberts/check_mk
 def save_transids(self, used_ids, unlock = False):
     if config.user_id:
         config.save_user_file("transids", used_ids, unlock)
コード例 #13
0
def save_tree_states():
    config.save_user_file("treestates", treestates)
コード例 #14
0
ファイル: notifications.py プロジェクト: ffeldhaus/check_mk
def save_acknowledgements():
    config.save_user_file("acknowledged_notifications", int(g_acknowledgement_time[config.user_id]))
    g_modified_time = time.time()
コード例 #15
0
ファイル: table.py プロジェクト: davidedg/check_mk
def end():
    global table
    finish_previous()
    html.unplug()

    if not table:
        return

    # Output-Format "fetch" simply means that all data is being
    # returned as Python-values to be rendered somewhere else.
    if table["output_format"] == "fetch":
        return table["headers"], table["rows"]

    if table["output_format"] == "csv":
        do_csv = True
        csv_separator = html.var("csv_separator", ";")
    else:
        do_csv = False

    if not table["rows"] and table["omit_if_empty"]:
        table = None
        return

    if table["title"] and not do_csv:
        html.write("<h3>%s</h3>" % table["title"])

    if table.get("help") and not do_csv:
        html.help(table["help"])

    if not table["rows"] and not do_csv:
        html.write("<div class=info>%s</div>" % table["empty_text"])
        table = None
        return

    table_id = table['id']
    rows = table["rows"]

    # Controls wether or not actions are available for a table
    search_term = None
    actions_enabled = (table["searchable"] or table["sortable"]) and not do_csv
    if actions_enabled:
        user_opts = config.load_user_file("tableoptions", {})
        user_opts.setdefault(table_id, {})
        table_opts = user_opts[table_id]

        # Handle the initial visibility of the actions
        actions_visible = user_opts[table_id].get('actions_visible', False)
        if html.var('_%s_actions' % table_id):
            actions_visible = html.var('_%s_actions' % table_id) == '1'

            user_opts[table_id]['actions_visible'] = actions_visible

        if html.var('_%s_reset' % table_id):
            html.del_var('_%s_search' % table_id)
            if 'search' in table_opts:
                del table_opts['search'] # persist

        if table["searchable"]:
            # Search is always lower case -> case insensitive
            search_term = html.var('_%s_search' % table_id, table_opts.get('search', '')).lower()
            if search_term:
                html.set_var('_%s_search' % table_id, search_term)
                table_opts['search'] = search_term # persist
                filtered_rows = []
                for row, css, state, fixed in rows:
                    if state == "header" or fixed:
                        continue # skip filtering of headers or fixed rows
                    for cell_content, css_classes, colspan in row:
                        if fixed or search_term in cell_content.lower():
                            filtered_rows.append((row, css, state, fixed))
                            break # skip other cells when matched
                rows = filtered_rows

        if html.var('_%s_reset_sorting' % table_id):
            html.del_var('_%s_sort' % table_id)
            if 'sort' in table_opts:
                del table_opts['sort'] # persist

        if table["sortable"]:
            # Now apply eventual sorting settings
            sort = html.var('_%s_sort' % table_id, table_opts.get('sort'))
            if sort != None:
                html.set_var('_%s_sort' % table_id, sort)
                table_opts['sort'] = sort # persist
                sort_col, sort_reverse = map(int, sort.split(',', 1))

                # remove and remind fixed rows, add to separate list
                fixed_rows = []
                for index, row in enumerate(rows[:]):
                    if row[3] == True:
                        rows.remove(row)
                        fixed_rows.append((index, row))

                # Then use natural sorting to sort the list
                rows.sort(cmp=lambda a, b: cmp(num_split(a[0][sort_col][0]),
                                               num_split(b[0][sort_col][0])),
                          reverse=sort_reverse==1)

                # Now re-add the removed "fixed" rows to the list again
                if fixed_rows:
                    for index, row in fixed_rows:
                        rows.insert(index, row)

    num_rows_unlimited = len(rows)
    num_cols = len(table["headers"])

    # Apply limit after search / sorting etc.
    limit = table['limit']
    if limit is not None:
        rows = rows[:limit]

    if not do_csv:
        html.write('<table class="data')
        if "css" in table:
            html.write(" %s" % table["css"])
        html.write('">\n')

    def render_headers():
        if table["omit_headers"]:
            return

        if do_csv:
            html.write(csv_separator.join([html.strip_tags(header) or "" for (header, help, sortable) in table["headers"]]) + "\n")
        else:
            html.write("  <tr>")
            first_col = True
            for nr, (header, help, sortable) in enumerate(table["headers"]):
                text = header
                if help:
                    header = '<span title="%s">%s</span>' % (html.attrencode(help), header)
                if not table["sortable"] or not sortable:
                    html.write("  <th>")
                else:
                    reverse = 0
                    sort = html.var('_%s_sort' % table_id)
                    if sort:
                        sort_col, sort_reverse = map(int, sort.split(',', 1))
                        if sort_col == nr:
                            reverse = sort_reverse == 0 and 1 or 0
                    html.write("  <th class=\"sort\" title=\"%s\" onclick=\"location.href='%s'\">" %
                                (_('Sort by %s') % text, html.makeactionuri([('_%s_sort' % table_id, '%d,%d' % (nr, reverse))])))

                # Add the table action link
                if first_col:
                    if actions_enabled:
                        if actions_visible:
                            state = '0'
                            help  = _('Hide table actions')
                            img   = 'table_actions_on'
                        else:
                            state = '1'
                            help  = _('Display table actions')
                            img   = 'table_actions_off'
                        html.icon_button(html.makeuri([('_%s_actions' % table_id, state)]),
                            help, img, cssclass = 'toggle_actions')
                    first_col = False

                html.write("%s</th>\n" % header)
            html.write("  </tr>\n")

    # If we have no group headers then paint the headers now
    if table["rows"] and table["rows"][0][2] != "header":
        render_headers()

    if actions_enabled and actions_visible and not do_csv:
        html.write('<tr class="data even0 actions"><td colspan=%d>' % num_cols)
        if not html.in_form():
            html.begin_form("%s_actions" % table_id)

        if table["searchable"]:
            html.write("<div class=search>")
            html.text_input("_%s_search" % table_id)
            html.button("_%s_submit" % table_id, _("Search"))
            html.button("_%s_reset" % table_id, _("Reset search"))
            html.set_focus("_%s_search" % table_id)
            html.write("</div>\n")

        if html.has_var('_%s_sort' % table_id):
            html.write("<div class=sort>")
            html.button("_%s_reset_sorting" % table_id, _("Reset sorting"))
            html.write("</div>\n")

        if not html.in_form():
            html.begin_form("%s_actions" % table_id)

        html.hidden_fields()
        html.end_form()
        html.write('</tr>')

    odd = "even"
    for nr, (row, css, state, fixed) in enumerate(rows):
        if do_csv:
            html.write(csv_separator.join([html.strip_tags(cell_content) for cell_content, css_classes, colspan in row ]))
            html.write("\n")

        else: # HTML output
            # Intermediate header
            if state == "header":
                # Show the header only, if at least one (non-header) row follows
                if nr < len(rows) - 1 and rows[nr+1][2] != "header":
                    html.write('  <tr class="groupheader"><td colspan=%d><br>%s</td></tr>' % (num_cols, row))
                    odd = "even"
                    render_headers()
                continue

            odd = odd == "odd" and "even" or "odd"
            html.write('  <tr class="data %s%d' % (odd, state))
            if css:
                html.write(' %s' % css)
            html.write('">\n')
            for cell_content, css_classes, colspan in row:
                colspan = colspan and (' colspan="%d"' % colspan) or ''
                html.write("    <td%s%s>" % (css_classes and (" class='%s'" % css_classes) or "", colspan))
                html.write(cell_content)
                html.write("</td>\n")
            html.write("</tr>\n")

    if table["searchable"] and search_term and not rows and not do_csv:
        html.write('<tr class="data odd0 no_match"><td colspan=%d>%s</td></tr>' %
            (num_cols, _('Found no matching rows. Please try another search term.')))

    if not do_csv:
        html.write("</table>\n")

    if limit is not None and num_rows_unlimited > limit and not do_csv:
        html.message(_('This table is limited to show only %d of %d rows. '
                       'Click <a href="%s">here</a> to disable the limitation.') %
                           (limit, num_rows_unlimited, html.makeuri([('limit', 'none')])))

    if actions_enabled and not do_csv:
        config.save_user_file("tableoptions", user_opts)

    table = None
コード例 #16
0
ファイル: help.py プロジェクト: FireFoxIXI/check_mk
def ajax_switch_help():
    config.save_user_file("help", html.var("enabled", "") != "")
コード例 #17
0
ファイル: help.py プロジェクト: v-a/check_mk
def ajax_switch_help():
    state = html.var("enabled", "") != ""
    config.save_user_file("help", state)
    html.write("%r" % state)
コード例 #18
0
ファイル: html_mod_python.py プロジェクト: hamcos/check_mk
 def save_transids(self, used_ids, unlock = False):
     if config.user_id:
         config.save_user_file("transids", used_ids, unlock)
コード例 #19
0
ファイル: table.py プロジェクト: v-a/check_mk
def end():
    global table
    finish_previous()
    html.unplug()

    if not table:
        return

    if not table["rows"] and table["omit_if_empty"]:
        table = None
        return

    if table["title"]:
        html.write("<h3>%s</h3>" % table["title"])

    if table.get("help"):
        html.help(table["help"])

    if not table["rows"]:
        html.write("<div class=info>%s</div>" % table["empty_text"])
        table = None
        return

    table_id = table["id"]
    rows = table["rows"]

    # Controls wether or not actions are available for a table
    actions_enabled = table["searchable"]
    if actions_enabled:
        user_opts = config.load_user_file("tableoptions", {})
        user_opts.setdefault(table_id, {})
        table_opts = user_opts[table_id]

        # Handle the initial visibility of the actions
        actions_visible = user_opts[table_id].get("actions_visible", False)
        if html.var("_%s_actions" % table_id):
            actions_visible = html.var("_%s_actions" % table_id) == "1"

            user_opts[table_id]["actions_visible"] = actions_visible

        if html.var("_%s_reset" % table_id):
            html.del_var("_%s_search" % table_id)
            if "search" in table_opts:
                del table_opts["search"]  # persist

        # Search is always lower case -> case insensitive
        search_term = html.var("_%s_search" % table_id, table_opts.get("search", "")).lower()
        if search_term:
            html.set_var("_%s_search" % table_id, search_term)
            table_opts["search"] = search_term  # persist
            filtered_rows = []
            for row, css, state in rows:
                if state == "header":
                    continue
                for cell_content, css_classes in row:
                    if search_term in cell_content.lower():
                        filtered_rows.append((row, css, state))
                        break  # skip other cells when matched
            rows = filtered_rows

    num_rows_unlimited = len(rows)
    num_cols = len(table["headers"])

    # Apply limit after search / sorting etc.
    limit = table["limit"]
    if limit is not None:
        rows = rows[:limit]

    html.write('<table class="data')
    if "css" in table:
        html.write(" %s" % table["css"])
    html.write('">\n')

    def render_headers():
        html.write("  <tr class=DEPP>")
        first_col = True
        for header, help in table["headers"]:
            if help:
                header = '<span title="%s">%s</span>' % (html.attrencode(help), header)
            html.write("  <th>")

            # Add the table action link
            if first_col:
                if actions_enabled:
                    if actions_visible:
                        state = "0"
                        help = _("Hide table actions")
                        img = "table_actions_on"
                    else:
                        state = "1"
                        help = _("Display table actions")
                        img = "table_actions_off"
                    html.icon_button(
                        html.makeuri([("_%s_actions" % table_id, state)]), help, img, cssclass="toggle_actions"
                    )
                first_col = False

            html.write("%s</th>\n" % header)
        html.write("  </tr>\n")

    # If we have no group headers then paint the headers now
    if table["rows"] and table["rows"][0][2] != "header":
        render_headers()

    if actions_enabled and actions_visible:
        html.write('<tr class="data even0 actions"><td colspan=%d>' % num_cols)
        html.begin_form("%s_actions" % table_id)

        if table["searchable"]:
            html.write("<div class=search>")
            html.text_input("_%s_search" % table_id)
            html.button("_%s_submit" % table_id, _("Search"))
            html.button("_%s_reset" % table_id, _("Reset"))
            html.set_focus("_%s_search" % table_id)
            html.write("</div>\n")

        html.hidden_fields()
        html.end_form()
        html.write("</tr>")

    odd = "even"
    # TODO: Sorting
    for nr, (row, css, state) in enumerate(rows):
        # Intermediate header
        if state == "header":
            # Show the header only, if at least one (non-header) row follows
            if nr < len(rows) - 1 and rows[nr + 1][2] != "header":
                html.write('  <tr class="groupheader"><td colspan=%d><br>%s</td></tr>' % (num_cols, row))
                odd = "even"
                render_headers()
            continue

        odd = odd == "odd" and "even" or "odd"
        html.write('  <tr class="data %s%d' % (odd, state))
        if css:
            html.write(" %s" % css)
        html.write('">\n')
        for cell_content, css_classes in row:
            html.write("    <td%s>" % (css_classes and (" class='%s'" % css_classes) or ""))
            html.write(cell_content)
            html.write("</td>\n")
        html.write("</tr>\n")

    if actions_enabled and search_term and not rows:
        html.write(
            '<tr class="data odd0 no_match"><td colspan=%d>%s</td></tr>'
            % (num_cols, _("Found no matching rows. Please try another search term."))
        )

    html.write("</table>\n")

    if limit is not None and num_rows_unlimited > limit:
        html.message(
            _(
                "This table is limited to show only %d of %d rows. "
                'Click <a href="%s">here</a> to disable the limitation.'
            )
            % (limit, num_rows_unlimited, html.makeuri([("limit", "none")]))
        )

    if actions_enabled:
        config.save_user_file("tableoptions", user_opts)

    table = None
コード例 #20
0
ファイル: weblib.py プロジェクト: dago/check_mk
def save_tree_states():
    config.save_user_file("treestates", treestates)
コード例 #21
0
ファイル: html_mod_python.py プロジェクト: alberts/check_mk
 def save_tree_states(self):
     config.save_user_file("treestates", self.treestates)
コード例 #22
0
def end():
    global table
    finish_previous()
    html.unplug()

    if not table:
        return

    # Output-Format "fetch" simply means that all data is being
    # returned as Python-values to be rendered somewhere else.
    if table["output_format"] == "fetch":
        return table["headers"], table["rows"]

    if table["output_format"] == "csv":
        do_csv = True
        csv_separator = html.var("csv_separator", ";")
    else:
        do_csv = False

    if not table["rows"] and table["omit_if_empty"]:
        table = None
        return

    if table["title"] and not do_csv:
        html.write("<h3>%s</h3>" % table["title"])

    if table.get("help") and not do_csv:
        html.help(table["help"])

    if not table["rows"] and not do_csv:
        html.write("<div class=info>%s</div>" % table["empty_text"])
        table = None
        return

    table_id = table['id']
    rows = table["rows"]

    # Controls wether or not actions are available for a table
    search_term = None
    actions_enabled = (table["searchable"] or table["sortable"]) and not do_csv
    if actions_enabled:
        user_opts = config.load_user_file("tableoptions", {})
        user_opts.setdefault(table_id, {})
        table_opts = user_opts[table_id]

        # Handle the initial visibility of the actions
        actions_visible = user_opts[table_id].get('actions_visible', False)
        if html.var('_%s_actions' % table_id):
            actions_visible = html.var('_%s_actions' % table_id) == '1'

            user_opts[table_id]['actions_visible'] = actions_visible

        if html.var('_%s_reset' % table_id):
            html.del_var('_%s_search' % table_id)
            if 'search' in table_opts:
                del table_opts['search']  # persist

        if table["searchable"]:
            # Search is always lower case -> case insensitive
            search_term = html.var_utf8('_%s_search' % table_id,
                                        table_opts.get('search', '')).lower()
            if search_term:
                html.set_var('_%s_search' % table_id, search_term)
                table_opts['search'] = search_term  # persist
                filtered_rows = []
                for row, css, state, fixed in rows:
                    if state == "header" or fixed:
                        continue  # skip filtering of headers or fixed rows
                    for cell_content, css_classes, colspan in row:
                        if fixed or search_term in cell_content.lower():
                            filtered_rows.append((row, css, state, fixed))
                            break  # skip other cells when matched
                rows = filtered_rows

        if html.var('_%s_reset_sorting' % table_id):
            html.del_var('_%s_sort' % table_id)
            if 'sort' in table_opts:
                del table_opts['sort']  # persist

        if table["sortable"]:
            # Now apply eventual sorting settings
            sort = html.var('_%s_sort' % table_id, table_opts.get('sort'))
            if sort != None:
                html.set_var('_%s_sort' % table_id, sort)
                table_opts['sort'] = sort  # persist
                sort_col, sort_reverse = map(int, sort.split(',', 1))

                # remove and remind fixed rows, add to separate list
                fixed_rows = []
                for index, row in enumerate(rows[:]):
                    if row[3] == True:
                        rows.remove(row)
                        fixed_rows.append((index, row))

                # Then use natural sorting to sort the list
                rows.sort(cmp=lambda a, b: cmp(num_split(a[0][sort_col][0]),
                                               num_split(b[0][sort_col][0])),
                          reverse=sort_reverse == 1)

                # Now re-add the removed "fixed" rows to the list again
                if fixed_rows:
                    for index, row in fixed_rows:
                        rows.insert(index, row)

    num_rows_unlimited = len(rows)
    num_cols = len(table["headers"])

    # Apply limit after search / sorting etc.
    limit = table['limit']
    if limit is not None:
        rows = rows[:limit]

    if not do_csv:
        html.write('<table class="data')
        if "css" in table:
            html.write(" %s" % table["css"])
        html.write('">\n')

    def render_headers():
        if table["omit_headers"]:
            return

        if do_csv:
            html.write(
                csv_separator.join([
                    html.strip_tags(header) or ""
                    for (header, help, sortable) in table["headers"]
                ]) + "\n")
        else:
            html.write("  <tr>")
            first_col = True
            for nr, (header, help, sortable) in enumerate(table["headers"]):
                text = header
                if help:
                    header = '<span title="%s">%s</span>' % (
                        html.attrencode(help), header)
                if not table["sortable"] or not sortable:
                    html.write("  <th>")
                else:
                    reverse = 0
                    sort = html.var('_%s_sort' % table_id)
                    if sort:
                        sort_col, sort_reverse = map(int, sort.split(',', 1))
                        if sort_col == nr:
                            reverse = sort_reverse == 0 and 1 or 0
                    html.write(
                        "  <th class=\"sort\" title=\"%s\" onclick=\"location.href='%s'\">"
                        %
                        (_('Sort by %s') % text,
                         html.makeactionuri([('_%s_sort' % table_id, '%d,%d' %
                                              (nr, reverse))])))

                # Add the table action link
                if first_col:
                    if actions_enabled:
                        if actions_visible:
                            state = '0'
                            help = _('Hide table actions')
                            img = 'table_actions_on'
                        else:
                            state = '1'
                            help = _('Display table actions')
                            img = 'table_actions_off'
                        html.icon_button(html.makeuri([
                            ('_%s_actions' % table_id, state)
                        ]),
                                         help,
                                         img,
                                         cssclass='toggle_actions')
                    first_col = False

                html.write("%s</th>\n" % header)
            html.write("  </tr>\n")

    # If we have no group headers then paint the headers now
    if table["rows"] and table["rows"][0][2] != "header":
        render_headers()

    if actions_enabled and actions_visible and not do_csv:
        html.write('<tr class="data even0 actions"><td colspan=%d>' % num_cols)
        if not html.in_form():
            html.begin_form("%s_actions" % table_id)

        if table["searchable"]:
            html.write("<div class=search>")
            html.text_input("_%s_search" % table_id)
            html.button("_%s_submit" % table_id, _("Search"))
            html.button("_%s_reset" % table_id, _("Reset search"))
            html.set_focus("_%s_search" % table_id)
            html.write("</div>\n")

        if html.has_var('_%s_sort' % table_id):
            html.write("<div class=sort>")
            html.button("_%s_reset_sorting" % table_id, _("Reset sorting"))
            html.write("</div>\n")

        if not html.in_form():
            html.begin_form("%s_actions" % table_id)

        html.hidden_fields()
        html.end_form()
        html.write('</tr>')

    odd = "even"
    for nr, (row, css, state, fixed) in enumerate(rows):
        if do_csv:
            html.write(
                csv_separator.join([
                    html.strip_tags(cell_content)
                    for cell_content, css_classes, colspan in row
                ]))
            html.write("\n")

        else:  # HTML output
            # Intermediate header
            if state == "header":
                # Show the header only, if at least one (non-header) row follows
                if nr < len(rows) - 1 and rows[nr + 1][2] != "header":
                    html.write(
                        '  <tr class="groupheader"><td colspan=%d><br>%s</td></tr>'
                        % (num_cols, row))
                    odd = "even"
                    render_headers()
                continue

            odd = odd == "odd" and "even" or "odd"
            html.write('  <tr class="data %s%d' % (odd, state))
            if css:
                html.write(' %s' % css)
            html.write('">\n')
            for cell_content, css_classes, colspan in row:
                colspan = colspan and (' colspan="%d"' % colspan) or ''
                html.write("    <td%s%s>" %
                           (css_classes and
                            (" class='%s'" % css_classes) or "", colspan))
                html.write(cell_content)
                html.write("</td>\n")
            html.write("</tr>\n")

    if table["searchable"] and search_term and not rows and not do_csv:
        html.write(
            '<tr class="data odd0 no_match"><td colspan=%d>%s</td></tr>' %
            (num_cols,
             _('Found no matching rows. Please try another search term.')))

    if not do_csv:
        html.write("</table>\n")

    if limit is not None and num_rows_unlimited > limit and not do_csv:
        html.message(
            _('This table is limited to show only %d of %d rows. '
              'Click <a href="%s">here</a> to disable the limitation.') %
            (limit, num_rows_unlimited, html.makeuri([('limit', 'none')])))

    if actions_enabled and not do_csv:
        config.save_user_file("tableoptions", user_opts)

    table = None
コード例 #23
0
def save_user_config(user_config):
    if config.may("general.configure_sidebar"):
        config.save_user_file("sidebar", user_config)
コード例 #24
0
ファイル: bi.py プロジェクト: sbakurdzhiev/check_mk
def save_ex_level(current_ex_level):
    config.save_user_file("bi_treestate", (current_ex_level, ))
コード例 #25
0
ファイル: help.py プロジェクト: ypid/check_mk
def ajax_switch_help():
    state = html.var("enabled", "") != ""
    config.save_user_file("help", state)
    html.write("%r" % state)
コード例 #26
0
ファイル: bi.py プロジェクト: itouch2web/check_mk
def save_assumptions():
    config.save_user_file("bi_assumptions", g_assumptions)
コード例 #27
0
ファイル: html_mod_python.py プロジェクト: v-a/check_mk
 def save_transids(self, used_ids):
     config.save_user_file("transids", used_ids)
コード例 #28
0
ファイル: table.py プロジェクト: wmbaum/check_mk
def end():
    global table
    finish_previous()
    html.unplug()

    if not table:
        return

    if not table["rows"] and table["omit_if_empty"]:
        table = None
        return

    if table["title"]:
        html.write("<h3>%s</h3>" % table["title"])

    if table.get("help"):
        html.help(table["help"])

    if not table["rows"]:
        html.write("<div class=info>%s</div>" % table["empty_text"])
        table = None
        return

    table_id = table['id']
    rows = table["rows"]

    # Controls wether or not actions are available for a table
    actions_enabled = table["searchable"]
    if actions_enabled:
        user_opts = config.load_user_file("tableoptions", {})
        user_opts.setdefault(table_id, {})
        table_opts = user_opts[table_id]

        # Handle the initial visibility of the actions
        actions_visible = user_opts[table_id].get('actions_visible', False)
        if html.var('_%s_actions' % table_id):
            actions_visible = html.var('_%s_actions' % table_id) == '1'

            user_opts[table_id]['actions_visible'] = actions_visible

        if html.var('_%s_reset' % table_id):
            html.del_var('_%s_search' % table_id)
            if 'search' in table_opts:
                del table_opts['search'] # persist

        # Search is always lower case -> case insensitive
        search_term = html.var('_%s_search' % table_id, table_opts.get('search', '')).lower()
        if search_term:
            html.set_var('_%s_search' % table_id, search_term)
            table_opts['search'] = search_term # persist
            filtered_rows = []
            for row, css in rows:
                for cell_content, css_classes in row:
                    if search_term in cell_content.lower():
                        filtered_rows.append((row, css))
                        break # skip other cells when matched
            rows = filtered_rows

    num_rows_unlimited = len(rows)
    num_cols = len(table["headers"])

    # Apply limit after search / sorting etc.
    limit = table['limit']
    if limit is not None:
        rows = rows[:limit]

    html.write('<table class="data')
    if "css" in table:
        html.write(" %s" % table["css"])
    html.write('">\n')

    html.write("  <tr>")
    first_col = True
    for header, help in table["headers"]:
        if help:
            header = '<span title="%s">%s</span>' % (html.attrencode(help), header)
        html.write("  <th>")

        # Add the table action link
        if first_col:
            if actions_enabled:
                if actions_visible:
                    state = '0'
                    help  = _('Hide table actions')
                    img   = 'table_actions_on'
                else:
                    state = '1'
                    help  = _('Display table actions')
                    img   = 'table_actions_off'
                html.icon_button(html.makeuri([('_%s_actions' % table_id, state)]),
                    help, img, cssclass = 'toggle_actions')
            first_col = False

        html.write("%s</th>\n" % header)
    html.write("  </tr>\n")

    if actions_enabled and actions_visible:
        html.write('<tr class="data even0 actions"><td colspan=%d>' % num_cols)
        html.begin_form("%s_actions" % table_id)

        if table["searchable"]:
            html.write("<div class=search>")
            html.text_input("_%s_search" % table_id)
            html.button("_%s_submit" % table_id, _("Search"))
            html.button("_%s_reset" % table_id, _("Reset"))
            html.set_focus("_%s_search" % table_id)
            html.write("</div>\n")

        html.hidden_fields()
        html.end_form()
        html.write('</tr>')

    odd = "even"
    # TODO: Sorting
    for row, css in rows:
        odd = odd == "odd" and "even" or "odd"
        html.write('  <tr class="data %s0' % odd)
        if css:
            html.write(' %s' % css)
        html.write('">\n')
        for cell_content, css_classes in row:
            html.write("    <td%s>" % (css_classes and (" class='%s'" % css_classes) or ""))
            html.write(cell_content)
            html.write("</td>\n")
        html.write("</tr>\n")

    if actions_enabled and search_term and not rows:
        html.write('<tr class="data odd0 no_match"><td colspan=%d>%s</td></tr>' %
            (num_cols, _('Found no matching rows. Please try another search term.')))

    html.write("</table>\n")

    if limit is not None and num_rows_unlimited > limit:
        html.message(_('This table is limited to show only %d of %d rows. '
                       'Click <a href="%s">here</a> to disable the limitation.') %
                           (limit, num_rows_unlimited, html.makeuri([('limit', 'none')])))

    if actions_enabled:
        config.save_user_file("tableoptions", user_opts)

    table = None
コード例 #29
0
ファイル: html_mod_python.py プロジェクト: v-a/check_mk
 def save_tree_states(self):
     config.save_user_file("treestates", self.treestates)
コード例 #30
0
ファイル: bi.py プロジェクト: sbakurdzhiev/check_mk
def save_assumptions():
    config.save_user_file("bi_assumptions", g_assumptions)