Пример #1
0
    def report_html(self, request, result=None, query=None):
        def is_local(r):
            return not bool(CollectionCache.objects.filter(uuid=r.uuid))

        r = ["["]
        r += [",\n".join([
            indent(r.to_json())
            for r in EventClassificationRule.objects.order_by("name")
            if is_local(r)
        ])]
        r += ["]", ""]
        return "<pre>" + escape("\n".join(r)) + "</pre>"
Пример #2
0
 def report_html(self, request, result=None, query=None):
     builtins = Collection.get_builtins("fm.eventclassificationrules")
     r = ["["]
     r += [
         ",\n".join(
             [
                 indent(rr.to_json())
                 for rr in EventClassificationRule.objects.order_by("name")
                 if rr.uuid and unicode(rr.uuid) not in builtins
             ]
         )
     ]
     r += ["]", ""]
     return "<pre>" + escape("\n".join(r)) + "</pre>"
Пример #3
0
 def convert(cls, o, i, order=None):
     if o is None:
         return indent("null", i)
     if isinstance(o, basestring):
         return indent("\"%s\"" % json_escape(o), i)
     elif isinstance(o, bool):
         return indent("true" if o else "false", i)
     elif isinstance(o, (int, long)):
         return indent("%d" % o, i)
     elif isinstance(o, float):
         return indent(str(o), i)
     elif isinstance(o, uuid.UUID):
         return indent("\"%s\"" % o, i)
     elif isinstance(o, list):
         if len(o) == 0:
             return indent("[]", i)
         t = [cls.convert(e, 0, order) for e in o]
         lt = reduce(lambda x, y: x + y, [len(x) for x in t])
         lt += i + (len(o) - 1) * 2
         if lt > 72:
             # Long line
             r = [indent("[", i)]
             r += [",\n".join(indent(x, i + 4) for x in t)]
             r += [indent("]", i)]
             return "\n".join(r)
         else:
             r = "[%s]" % ", ".join(t)
             return indent(r, i)
     elif isinstance(o, dict):
         if not o:
             return indent("{}", i)
         keys = sorted(o)
         if order:
             nk = [k for k in order if k in keys]
             nk += [k for k in keys if k not in order]
             keys = nk
         r = ",\n".join("%s: %s" % (cls.convert(k, 0), cls.convert(o[k], 0))
                        for k in keys)
         return indent("{\n%s\n}" % indent(r, 4), i)
     raise ValueError("Cannot encode %r" % o)