示例#1
0
class TestTalesWithCam(TestCase, WithCheckPathMixin):
    def setUp(self):
        self.p = p = CamPackage("tmp", create=True)
        p.uri = "urn:1234"
        p.create_annotation_type("at1")
        p.create_annotation_type("at2")
        p.create_relation_type("rt1")
        p.create_relation_type("rt2")
        p.create_schema("s1", items=[p.get("at1"), p.get("at2"), p.get("rt1")])
        p.create_schema("s2", items=[p.get("at1"), p.get("rt2")])
        p.create_media("m1", "http://media.org/m1")
        p.create_annotation("a1", p.get("m1"), 42, 101, "text/plain",
                            type=p.get("at2"))
        p.create_user_tag("t1")
        p.create_user_list("l1", items=[p.get("a1"), p.get("at1")])
        p.associate_user_tag(p.get("a1"), p.get("t1"))
        p.associate_user_tag(p.get("m1"), p.get("t1"))

        self.c = AdveneContext(p)
        self.c.addGlobal("regpkg", p)

    def tearDown(self):
        pass

    def test_misc(self):
        p = self.p
        self.check_path("here/at1", p.get("at1"))
        self.check_path("here/annotation_types", p.all.annotation_types)
        self.check_path("here/relation_types", p.all.relation_types)
        self.check_path("here/schemas", p.all.schemas)
        self.check_path("here/user_tags", p.all.user_tags)
        self.check_path("here/user_lists", p.all.user_lists)
        self.check_path("here/a1/type", p["a1"].type)
示例#2
0
文件: tal.py 项目: oaubert/advene2
def apply_to(view, obj, refpkg=None):
    f = view.content_as_file
    html = view.content_mimetype.startswith("text/html")
    if html:
        t = simpleTAL.compileHTMLTemplate(f, "utf-8")
        kw = {}
    else:
        t = simpleTAL.compileXMLTemplate(f)
        kw = { "suppressXMLDeclaration": 1 }
        # It is a bit ugly to suppress XML declaration, but necessary when XML
        # views are used inside other XML views.
        # Furthermore, this does not seem to serious a ugliness, since we use
        # UTF-8 # encoding, which appears to be the default (at least for
        # simpleTAL generator), and since the XML spec allows well-formed
        # documents to have no XML declaration.
    f.close()

    # should we cache the compiled template for future uses,
    # and recompile it only when the content is modified?
    # the problem is that external contents may be modified without notification
    # (or rely on f.headers['date'], but that would require to hack content.py
    #  to make that field *always* present - might be a good idea...)

    c = AdveneContext(here=obj)
    c.addGlobal("view", view)
    if refpkg is None:
        if hasattr(obj, "ADVENE_TYPE"):
            refpkg = obj.owner
        else:
            refpkg = obj
    c.addGlobal("package", refpkg)
    out = StringIO()
    t.expand(c, out, outputEncoding="utf-8", **kw)
    return out.getvalue()
示例#3
0
    def setUp(self):
        self.p = p = CorePackage("tmp", create=True)
        p.uri = "urn:1234"
        p.create_media("m1", "http://media.org/m1")
        p.create_annotation("a1", p.get("m1"), 42, 101, "text/plain")
        p.create_tag("t1")
        p.associate_tag(p["a1"], p["t1"])

        self.c = AdveneContext(p)
        self.c.addGlobal("package", p)
示例#4
0
    def setUp(self):
        self.p = p = CamPackage("tmp", create=True)
        p.uri = "urn:1234"
        p.create_annotation_type("at1")
        p.create_annotation_type("at2")
        p.create_relation_type("rt1")
        p.create_relation_type("rt2")
        p.create_schema("s1", items=[p.get("at1"), p.get("at2"), p.get("rt1")])
        p.create_schema("s2", items=[p.get("at1"), p.get("rt2")])
        p.create_media("m1", "http://media.org/m1")
        p.create_annotation("a1", p.get("m1"), 42, 101, "text/plain",
                            type=p.get("at2"))
        p.create_user_tag("t1")
        p.create_user_list("l1", items=[p.get("a1"), p.get("at1")])
        p.associate_user_tag(p.get("a1"), p.get("t1"))
        p.associate_user_tag(p.get("m1"), p.get("t1"))

        self.c = AdveneContext(p)
        self.c.addGlobal("regpkg", p)
示例#5
0
 def build_context(self, here=None, alias=None):
     c=AdveneContext(here)
     c.addGlobal("package", here)
     return c
示例#6
0
class TestTalesWithCore(TestCase, WithCheckPathMixin):
    def setUp(self):
        self.p = p = CorePackage("tmp", create=True)
        p.uri = "urn:1234"
        p.create_media("m1", "http://media.org/m1")
        p.create_annotation("a1", p.get("m1"), 42, 101, "text/plain")
        p.create_tag("t1")
        p.associate_tag(p["a1"], p["t1"])

        self.c = AdveneContext(p)
        self.c.addGlobal("package", p)

    def tearDown(self):
        pass

    def test_misc(self):
        p = self.p
        self.check_path("here", p)
        self.check_path("here/a1", p["a1"])
        self.check_path("here/a1/media", p["a1"].media)
        self.check_path("here/a1/begin", p["a1"].begin)
        self.check_path("here/a1/my_tags", p["a1"].iter_my_tags(p))
        self.check_path("here/a1/my_tags/0", p["a1"].iter_my_tags(p).next())
        assert self.c.evaluate("foo|string:") is ""

    def test_absolute_url(self):
        p = self.p; c = self.c
        p1 = CorePackage("tmp1", create=True)
        p2 = CorePackage("tmp2", create=True)
        p3 = CorePackage("tmp3", create=True)
        t = p.create_tag("t")
        t1 = p1.create_tag("t1")
        t2 = p2.create_tag("t2")
        t3 = p3.create_tag("t3")
        p.create_import("i1", p1)
        p1.create_import("i2", p2)
        options = { "packages": {"p": p, "p1": p1},
                    "aliases": {p: "p", p1: "p1"},
                    "p": p, "p1": p1, "p2": p2, "p3": p3,
                  }
        c.addGlobal("options", options)
        # check on package
        self.check_path("options/p/absolute_url", "/p")
        self.check_path("options/p1/absolute_url", "/p1")
        try:
            self.check_path("options/p2/absolute_url", "/p/i1:i2/package")
            # it is either one or the other, we can't predict
        except AssertionError:
            self.check_path("options/p2/absolute_url", "/p1/i2/package")
        self.check_path("options/p/absolute_url/a/b/c", "/p/a/b/c")
        base = options["package_url"] = "http://localhost:1234/packages"
        self.check_path("options/p/absolute_url/a/b/c", base+"/p/a/b/c")
        self.check_path("options/p3/absolute_url|nothing", None)
        del options["package_url"]

        # check on element
        self.check_path("options/p/t/absolute_url", "/p/t")
        self.check_path("options/p1/t1/absolute_url", "/p1/t1")
        try:
            self.check_path("options/p2/t2/absolute_url", "/p/i1:i2:t2")
            # it is either one or the other, we can't predict
        except AssertionError:
            self.check_path("options/p2/t2/absolute_url", "/p1/i2:t2")
        self.check_path("options/p/t/absolute_url/a/b/c", "/p/t/a/b/c")
        base = options["package_url"] = "http://localhost:1234/packages"
        self.check_path("options/p/t/absolute_url/a/b/c", base+"/p/t/a/b/c")
        self.check_path("options/p3/t3/absolute_url|nothing", None)