Esempio n. 1
0
def handle_delete_annotations():
    if html.var("_delete_annotation"):
        site_id = html.var("anno_site") or ""
        hostname = html.var("anno_host")
        service = html.var("anno_service") or None
        fromtime = float(html.var("anno_from"))
        untiltime = float(html.var("anno_until"))
        site_host_svc = (site_id, hostname, service)

        annotations = availability.load_annotations()
        annotation = availability.find_annotation(annotations, site_host_svc, fromtime, untiltime)
        if not annotation:
            return

        if not html.confirm(_("Are you sure that you want to delete the annotation '%s'?" % annotation["text"])):
            return

        availability.delete_annotation(annotations, site_host_svc, fromtime, untiltime)
        availability.save_annotations(annotations)
Esempio n. 2
0
def handle_delete_annotations():
    if html.var("_delete_annotation"):
        site_id = html.var("anno_site") or ""
        hostname = html.var("anno_host")
        service = html.var("anno_service") or None
        fromtime = float(html.var("anno_from"))
        untiltime = float(html.var("anno_until"))
        site_host_svc = (site_id, hostname, service)

        annotations = availability.load_annotations()
        annotation = availability.find_annotation(annotations, site_host_svc, fromtime, untiltime)
        if not annotation:
            return

        if not html.confirm(_("Are you sure that you want to delete the annotation '%s'?") % annotation["text"]):
            return

        availability.delete_annotation(annotations, site_host_svc, fromtime, untiltime)
        availability.save_annotations(annotations)
Esempio n. 3
0
def edit_annotation():
    site_id = html.var("anno_site") or ""
    hostname = html.var("anno_host")
    service = html.var("anno_service") or None
    fromtime = float(html.var("anno_from"))
    untiltime = float(html.var("anno_until"))
    site_host_svc = (site_id, hostname, service)

    # Find existing annotation with this specification
    annotations = availability.load_annotations()
    annotation = availability.find_annotation(annotations, site_host_svc,
                                              fromtime, untiltime)
    if not annotation:
        value = {
            "from": fromtime,
            "until": untiltime,
            "text": "",
        }
    else:
        value = annotation.copy()

    value["host"] = hostname
    value["service"] = service
    value["site"] = site_id

    # FIXME: Why use plugging here? Can we clean this up?
    html.plug()

    title = _("Edit annotation of ") + hostname
    if service:
        title += "/" + service
    html.body_start(title, stylesheets=["pages", "views", "status"])
    html.top_heading(title)

    html.begin_context_buttons()
    html.context_button(_("Abort"), html.makeuri([("anno_host", "")]), "abort")
    html.end_context_buttons()

    value = forms.edit_dictionary([
        ("site", TextAscii(title=_("Site"))),
        ("host", TextUnicode(title=_("Hostname"))),
        ("service",
         Optional(TextUnicode(allow_empty=False),
                  sameline=True,
                  title=_("Service"))),
        ("from", AbsoluteDate(title=_("Start-Time"), include_time=True)),
        ("until", AbsoluteDate(title=_("End-Time"), include_time=True)),
        ("downtime",
         Optional(
             DropdownChoice(choices=[
                 (True, _("regard as scheduled downtime")),
                 (False, _("do not regard as scheduled downtime")),
             ], ),
             title=_("Scheduled downtime"),
             label=_("Reclassify downtime of this period"),
         )),
        ("text", TextAreaUnicode(title=_("Annotation"), allow_empty=False)),
    ],
                                  value,
                                  varprefix="editanno_",
                                  formname="editanno",
                                  focus="text")

    if value:
        site_host_svc = value["site"], value["host"], value["service"]
        del value["site"]
        del value["host"]
        value["date"] = time.time()
        value["author"] = config.user.id
        availability.update_annotations(site_host_svc,
                                        value,
                                        replace_existing=annotation)
        html.drain()  # omit previous HTML code, not needed
        html.unplug()
        html.del_all_vars(prefix="editanno_")
        html.del_var("filled_in")
        return False

    html.unplug()  # show HTML code

    html.bottom_footer()
    html.body_end()
    return True
Esempio n. 4
0
def edit_annotation():
    site_id       = html.var("anno_site") or ""
    hostname      = html.var("anno_host")
    service       = html.var("anno_service") or None
    fromtime      = float(html.var("anno_from"))
    untiltime     = float(html.var("anno_until"))
    site_host_svc = (site_id, hostname, service)

    # Find existing annotation with this specification
    annotations = availability.load_annotations()
    annotation = availability.find_annotation(annotations, site_host_svc, fromtime, untiltime)
    if not annotation:
        value = {
            "from"    : fromtime,
            "until"   : untiltime,
            "text"    : "",
        }
    else:
        value = annotation.copy()

    value["host"] = hostname
    value["service"] = service
    value["site"] = site_id

    # FIXME: Why use plugging here? Can we clean this up?
    html.plug()

    title = _("Edit annotation of ") + hostname
    if service:
        title += "/" + service
    html.body_start(title, stylesheets=["pages","views","status"])
    html.top_heading(title)

    html.begin_context_buttons()
    html.context_button(_("Abort"), html.makeuri([("anno_host", "")]), "abort")
    html.end_context_buttons()

    value = forms.edit_dictionary([
        ( "site",     TextAscii(title = _("Site")) ),
        ( "host",     TextUnicode(title = _("Hostname")) ),
        ( "service",  Optional(TextUnicode(allow_empty=False), sameline = True, title = _("Service")) ),
        ( "from",     AbsoluteDate(title = _("Start-Time"), include_time = True) ),
        ( "until",    AbsoluteDate(title = _("End-Time"), include_time = True) ),
        ( "downtime", Optional(
                          DropdownChoice(
                              choices = [
                                  ( True,  _("regard as scheduled downtime") ),
                                  ( False, _("do not regard as scheduled downtime") ),
                              ],
                          ),
                          title = _("Scheduled downtime"),
                          label = _("Reclassify downtime of this period"),
        )),
        ( "text",    TextAreaUnicode(title = _("Annotation"), allow_empty = False) ), ],
        value,
        varprefix = "editanno_",
        formname = "editanno",
        focus = "text")

    if value:
        site_host_svc = value["site"], value["host"], value["service"]
        del value["site"]
        del value["host"]
        value["date"] = time.time()
        value["author"] = config.user_id
        availability.update_annotations(site_host_svc, value, replace_existing=annotation)
        html.drain() # omit previous HTML code, not needed
        html.unplug()
        html.del_all_vars(prefix = "editanno_")
        html.del_var("filled_in")
        return False

    html.unplug() # show HTML code

    html.bottom_footer()
    html.body_end()
    return True