Ejemplo n.º 1
0
    def POST(self, key):
        site = web.ctx.site

        lst = site.get(key)
        if not lst:
            raise web.notfound()

        if not site.can_write(key):
            raise self.forbidden()

        data = formats.load(web.data(), self.encoding)

        data.setdefault("add", [])
        data.setdefault("remove", [])

        # support /subjects/foo and /books/OL1M along with subject:foo and {"key": "/books/OL1M"}.
        process_seeds = lists_json().process_seeds

        for seed in process_seeds(data["add"]):
            lst.add_seed(seed)

        for seed in process_seeds(data["remove"]):
            lst.remove_seed(seed)

        seeds = []
        for seed in data["add"] + data["remove"]:
            if isinstance(seed, dict):
                seeds.append(seed['key'])
            else:
                seeds.append(seed)

        changeset_data = {
            "list": {
                "key": key
            },
            "seeds": seeds,
            "add": data.get("add", []),
            "remove": data.get("remove", [])
        }

        d = lst._save(comment="updated list seeds.",
                      action="lists",
                      data=changeset_data)
        web.header("Content-Type", self.content_type)
        return delegate.RawText(formats.dump(d, self.encoding))
Ejemplo n.º 2
0
    def POST(self, key):
        site = web.ctx.site

        lst = site.get(key)
        if not lst:
            raise web.notfound()

        if not site.can_write(key):
            raise self.forbidden()

        data = formats.load(web.data(), self.encoding)

        data.setdefault("add", [])
        data.setdefault("remove", [])

        # support /subjects/foo and /books/OL1M along with subject:foo and {"key": "/books/OL1M"}.
        process_seeds = lists_json().process_seeds

        for seed in process_seeds(data["add"]):
            lst.add_seed(seed)

        for seed in process_seeds(data["remove"]):
            lst.remove_seed(seed)

        seeds = []
        for seed in data["add"] + data["remove"]:
            if isinstance(seed, dict):
                seeds.append(seed['key'])
            else:
                seeds.append(seed)

        changeset_data = {
            "list": {"key": key},
            "seeds": seeds,
            "add": data.get("add", []),
            "remove": data.get("remove", [])
        }

        d = lst._save(comment="updated list seeds.", action="lists", data=changeset_data)
        web.header("Content-Type", self.content_type)
        return delegate.RawText(formats.dump(d, self.encoding))
Ejemplo n.º 3
0
    def POST(self, key):
        site = web.ctx.site
        
        list = site.get(key)
        if not list:
            raise web.notfound()
            
        if not site.can_write(key):
            raise self.forbidden()
            
        data = formats.load(web.data(), self.encoding)
        
        for seed in data.get("add", []):
            list.add_seed(seed)
            
        for seed in data.get("remove", []):
            list.remove_seed(seed)
            
        d = list._save(comment="updated list seeds.")

        web.header("Content-Type", self.content_type)
        return delegate.RawText(formats.dump(d, self.encoding))
Ejemplo n.º 4
0
 def loads(self, text):
     return formats.load(text, self.encoding)
Ejemplo n.º 5
0
 def loads(self, text):
     return formats.load(text, self.encoding)