本文整理汇总了Python中wheelcms_axle.models.Node类的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
def handle(self, readfrom, update_lm=True, base="", owner="", **options):
contentxml = os.path.join(readfrom, "content.xml")
mediadir = os.path.join(readfrom, "media")
if not os.access(settings.MEDIA_ROOT, os.W_OK):
print "%s may not be writable. Continue (y/n)?" % settings.MEDIA_ROOT
if raw_input().lower().strip() != "y":
print "Exiting"
return
data = open(contentxml).read()
tree = ElementTree.fromstring(data)
basenode = Node.get(base)
if basenode is None:
basenode = Node.root()
for part in base.strip("/").split("/"):
sub = basenode.child(part)
if sub is None:
sub = basenode.add(part)
basenode = sub
Importer(basenode, update_lm=update_lm).run(tree)
## check writability
if os.path.exists(mediadir):
copy_tree(mediadir, settings.MEDIA_ROOT)
示例2: test_update_post
def test_update_post(self, client):
root = Node.root()
Type1(node=root, title="Hello").save()
request = superuser_request("/edit", method="POST",
title="Test",
slug="",
language="en")
handler = MainHandler(request=request, post=True, instance=root)
pytest.raises(Redirect, handler.update)
root = Node.root()
assert root.content().title == "Test"
示例3: test_create_post
def test_create_post(self, client):
request = superuser_request("/create", method="POST",
title="Test",
slug="test",
language="en")
root = Node.root()
handler = MainHandler(request=request, post=True,
instance=dict(instance=root))
pytest.raises(Redirect, handler.create, type=Type1.get_name())
node = Node.get("/test")
assert node.content().title == "Test"
示例4: test_create_attach_post
def test_create_attach_post(self, client):
""" post the form for attaching content """
request = superuser_request("/create", method="POST",
title="Test", language="en")
root = Node.root()
handler = MainHandler(request=request, post=True,
instance=dict(instance=root))
pytest.raises(Redirect, handler.create, type=Type1.get_name(), attach=True)
root = Node.root()
# pytest.set_trace()
assert root.content().title == "Test"
示例5: test_create_post_unicode
def test_create_post_unicode(self, client):
""" issue #693 - unicode enoding issue """
request = superuser_request("/create", method="POST",
title=u"Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20% off!",
slug="test",
language="en")
root = Node.root()
handler = MainHandler(request=request, post=True,
instance=dict(instance=root))
pytest.raises(Redirect, handler.create, type=Type1.get_name())
node = Node.get("/test")
assert node.content().title == u"Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20% off!"
示例6: test_update_post_unicode
def test_update_post_unicode(self, client):
""" update content with unicode with new unicode title """
root = Node.root()
Type1(node=root, title=u"Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20% off!").save()
request = superuser_request("/edit", method="POST",
title="TTesting «ταБЬℓσ»: 1<2 & 4+1>3, now 20% off!",
slug="",
language="en")
root = Node.root()
handler = MainHandler(request=request, post=True, instance=root)
pytest.raises(Redirect, handler.update)
root = Node.root()
assert root.content().title == u"TTesting «ταБЬℓσ»: 1<2 & 4+1>3, now 20% off!"
示例7: test_create_image
def test_create_image(self, client):
request = superuser_request("/create", method="POST",
title="Test",
slug="test",
language="en",
storage=filedata)
root = Node.root()
handler = MainHandler(request=request, post=True,
instance=dict(instance=root))
pytest.raises(Redirect, handler.create, type=TestImage.get_name())
node = Node.get("/test")
filedata.seek(0)
assert node.content().storage.read() == filedata.read()
示例8: test_update_image
def test_update_image(self, client):
root = Node.root()
node = root.add("test")
TestImage(node=node, title="image", storage=filedata).save()
request = superuser_request("/test/edit", method="POST",
title="Test",
slug="",
language="en",
storage=filedata2)
handler = MainHandler(request=request, post=True, instance=node)
pytest.raises(Redirect, handler.update)
node = Node.get("/test")
filedata2.seek(0)
assert node.content().storage.read() == filedata2.read()
示例9: test_form_choices
def test_form_choices(self):
""" the form should get its choices from the workflow """
form = Type1Type.form(parent=Node.root())
wfclass = core.workflow[Type1Type]
assert form.workflow_choices() == wfclass.states
assert form.workflow_default() == wfclass.default
示例10: test_handler_create
def test_handler_create(self, client):
""" The handler *can* set the user """
request = create_request("POST", "/create",
data=dict(title="Test",
slug="test",
language="en"))
request.user = self.user
root = Node.root()
handler = MainHandler(request=request, post=True,
instance=dict(parent=root))
pytest.raises(Redirect, handler.create, type=Type1.get_name())
node = Node.get("/test")
assert node.content().title == "Test"
assert node.content().owner == self.user
示例11: test_paste_cut_action
def test_paste_cut_action(self, client):
""" paste after cut moves content, must be in different node to have
any effect """
root = Node.root()
target = root.add("target")
t1 = Type1(node=root.add("t1"), title="t1").save()
t2 = Type1(node=root.add("t2"), title="t2").save()
request = superuser_request("/contents_actions_cutcopypaste",
method="POST", action="paste",
selection=[t1.node.tree_path,
t2.node.tree_path])
request.session['clipboard_cut'] = [t2.node.tree_path, t1.node.tree_path]
handler = MainHandlerTestable(request=request, instance=target,
post=True)
pytest.raises(Redirect, handler.handle_contents_actions_cutcopypaste)
assert len(target.children()) == 2
assert set(x.content().title for x in target.children()) == \
set(('t1', 't2'))
assert len(root.children()) == 1
assert root.child('target')
示例12: handle
def handle(self, writeto=None, path="", *args, **options):
if writeto is None:
raise CommandError("You must specificy a writable directory where the export can be written to")
verbose = options.get('verbose', True)
mediadir = os.path.join(writeto, "media")
if not os.path.exists(mediadir):
os.makedirs(mediadir)
base = path # "" # /sub5_2/sub4_2/sub3_2"
root = Node.get(base)
xml, files = Exporter().run(root, base)
open(os.path.join(writeto, "content.xml"), "w"
).write(prettify(xml).encode("utf8"))
for file in set(files):
dirname = os.path.dirname(file)
if dirname:
dir = os.path.join(mediadir, dirname)
if not os.path.exists(dir):
os.makedirs(dir)
dest = os.path.join(mediadir, file)
source = os.path.join(settings.MEDIA_ROOT, file)
if verbose:
print "Copy %s to %s" % (source, dest)
shutil.copy(source, dest)
if verbose:
print files
示例13: test_coerce_parent
def test_coerce_parent(self, client):
""" coerce a dict holding an parent path """
root = Node.root()
a = root.add("a")
res = MainHandler.coerce(dict(parent="a"))
assert 'parent' in res
assert res['parent'] == a
assert 'instance' not in res
示例14: test_attached_root
def test_attached_root(self, client):
""" A root node with content attached. Its name should not be
its title but 'Home' """
root = Node.root()
Type1(node=root, title="The rootnode of this site").save()
request = create_request("GET", "/")
handler = MainHandlerTestable(request=request, instance=root)
assert handler.breadcrumb() == [("Home", '')]
示例15: test_create_attach_get
def test_create_attach_get(self, client):
""" get the form for attaching content """
root = Node.root()
Type1(node=root).save()
request = superuser_request("/", type=Type1.get_name())
handler = MainHandlerTestable(request=request, instance=root)
create = handler.create(type=Type1.get_name(), attach=True)
assert create['path'] == "wheelcms_axle/create.html"
assert 'form' in create['context']