本文整理汇总了Python中wagtail.wagtailcore.models.Collection类的典型用法代码示例。如果您正苦于以下问题:Python Collection类的具体用法?Python Collection怎么用?Python Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_post_with_collections
def test_post_with_collections(self):
root_collection = Collection.get_first_root_node()
evil_plans_collection = root_collection.add_child(name="Evil plans")
# Build a fake file
fake_file = ContentFile(b("A boring example document"))
fake_file.name = 'test.txt'
# Submit
post_data = {
'title': "Test document",
'file': fake_file,
'collection': evil_plans_collection.id,
}
response = self.client.post(reverse('wagtaildocs:add'), post_data)
# User should be redirected back to the index
self.assertRedirects(response, reverse('wagtaildocs:index'))
# Document should be created, and be placed in the Evil Plans collection
self.assertTrue(models.Document.objects.filter(title="Test document").exists())
root_collection = Collection.get_first_root_node()
self.assertEqual(
models.Document.objects.get(title="Test document").collection,
evil_plans_collection
)
开发者ID:davecranwell,项目名称:wagtail,代码行数:26,代码来源:tests.py
示例2: test_pagination_preserves_other_params
def test_pagination_preserves_other_params(self):
root_collection = Collection.get_first_root_node()
evil_plans_collection = root_collection.add_child(name="Evil plans")
for i in range(1, 50):
self.image = Image.objects.create(
title="Test image %i" % i,
file=get_test_image_file(),
collection=evil_plans_collection
)
response = self.get({'collection_id': evil_plans_collection.id, 'p': 2})
self.assertEqual(response.status_code, 200)
response_body = response.content.decode('utf8')
# prev link should exist and include collection_id
self.assertTrue(
("?p=1&collection_id=%i" % evil_plans_collection.id) in response_body or
("?collection_id=%i&p=1" % evil_plans_collection.id) in response_body
)
# next link should exist and include collection_id
self.assertTrue(
("?p=3&collection_id=%i" % evil_plans_collection.id) in response_body or
("?collection_id=%i&p=3" % evil_plans_collection.id) in response_body
)
开发者ID:timorieber,项目名称:wagtail,代码行数:26,代码来源:test_admin_views.py
示例3: setUp
def setUp(self):
# Create a group to edit
self.test_group = Group.objects.create(name='test group')
self.root_page = Page.objects.get(id=1)
self.root_add_permission = GroupPagePermission.objects.create(page=self.root_page,
permission_type='add',
group=self.test_group)
self.home_page = Page.objects.get(id=2)
# Get the hook-registered permissions, and add one to this group
self.registered_permissions = Permission.objects.none()
for fn in hooks.get_hooks('register_permissions'):
self.registered_permissions = self.registered_permissions | fn()
self.existing_permission = self.registered_permissions.order_by('pk')[0]
self.another_permission = self.registered_permissions.order_by('pk')[1]
self.test_group.permissions.add(self.existing_permission)
# set up collections to test document permissions
self.root_collection = Collection.get_first_root_node()
self.evil_plans_collection = self.root_collection.add_child(name="Evil plans")
self.add_doc_permission = Permission.objects.get(
content_type__app_label='wagtaildocs', codename='add_document'
)
self.change_doc_permission = Permission.objects.get(
content_type__app_label='wagtaildocs', codename='change_document'
)
GroupCollectionPermission.objects.create(
group=self.test_group,
collection=self.evil_plans_collection,
permission=self.add_doc_permission,
)
# Login
self.login()
开发者ID:jschneier,项目名称:wagtail,代码行数:35,代码来源:tests.py
示例4: setUp
def setUp(self):
# Build a fake file
fake_file = ContentFile(b("A boring example document"))
fake_file.name = 'test.txt'
self.root_collection = Collection.get_first_root_node()
self.evil_plans_collection = self.root_collection.add_child(name="Evil plans")
self.nice_plans_collection = self.root_collection.add_child(name="Nice plans")
# Create a document to edit
self.document = models.Document.objects.create(
title="Test document", file=fake_file, collection=self.nice_plans_collection
)
# Create a user with change_document permission but not add_document
user = get_user_model().objects.create_user(
username='changeonly',
email='[email protected]',
password='password'
)
change_permission = Permission.objects.get(
content_type__app_label='wagtaildocs', codename='change_document'
)
admin_permission = Permission.objects.get(
content_type__app_label='wagtailadmin', codename='access_admin'
)
self.changers_group = Group.objects.create(name='Document changers')
GroupCollectionPermission.objects.create(
group=self.changers_group, collection=self.root_collection,
permission=change_permission
)
user.groups.add(self.changers_group)
user.user_permissions.add(admin_permission)
self.assertTrue(self.client.login(username='changeonly', password='password'))
开发者ID:davecranwell,项目名称:wagtail,代码行数:35,代码来源:tests.py
示例5: test_add_post_with_collections
def test_add_post_with_collections(self):
"""
This tests that a POST request to the add view saves the document
and returns an edit form, when collections are active
"""
root_collection = Collection.get_first_root_node()
evil_plans_collection = root_collection.add_child(name="Evil plans")
response = self.client.post(
reverse("wagtaildocs:add_multiple"),
{
"files[]": SimpleUploadedFile("test.png", b"Simple text document"),
"collection": evil_plans_collection.id,
},
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
)
# Check response
self.assertEqual(response.status_code, 200)
self.assertEqual(response["Content-Type"], "application/json")
self.assertTemplateUsed(response, "wagtaildocs/multiple/edit_form.html")
# Check document
self.assertIn("doc", response.context)
self.assertEqual(response.context["doc"].title, "test.png")
self.assertTrue(response.context["doc"].file_size)
# check that it is in the 'evil plans' collection
doc = Document.objects.get(title="test.png")
root_collection = Collection.get_first_root_node()
self.assertEqual(doc.collection, evil_plans_collection)
# Check form
self.assertIn("form", response.context)
self.assertEqual(response.context["form"].initial["title"], "test.png")
# Check JSON
response_json = json.loads(response.content.decode())
self.assertIn("doc_id", response_json)
self.assertIn("form", response_json)
self.assertIn("success", response_json)
self.assertEqual(response_json["doc_id"], response.context["doc"].id)
self.assertTrue(response_json["success"])
# form should contain a collection chooser
self.assertIn("Collection", response_json["form"])
开发者ID:m1kola,项目名称:wagtail,代码行数:47,代码来源:tests.py
示例6: setUp
def setUp(self):
self.root_collection = Collection.get_first_root_node()
self.holiday_photos_collection = self.root_collection.add_child(
name="Holiday photos"
)
self.evil_plans_collection = self.root_collection.add_child(
name="Evil plans"
)
开发者ID:DimiC,项目名称:wagtail,代码行数:8,代码来源:test_collection_model.py
示例7: test_add_post_with_collections
def test_add_post_with_collections(self):
"""
This tests that a POST request to the add view saves the document
and returns an edit form, when collections are active
"""
root_collection = Collection.get_first_root_node()
evil_plans_collection = root_collection.add_child(name="Evil plans")
response = self.client.post(reverse('wagtaildocs:add_multiple'), {
'files[]': SimpleUploadedFile('test.png', b"Simple text document"),
'collection': evil_plans_collection.id
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
# Check response
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-Type'], 'application/json')
self.assertTemplateUsed(response, 'wagtaildocs/multiple/edit_form.html')
# Check document
self.assertIn('doc', response.context)
self.assertEqual(response.context['doc'].title, 'test.png')
self.assertTrue(response.context['doc'].file_size)
# check that it is in the 'evil plans' collection
doc = Document.objects.get(title='test.png')
root_collection = Collection.get_first_root_node()
self.assertEqual(doc.collection, evil_plans_collection)
# Check form
self.assertIn('form', response.context)
self.assertEqual(response.context['form'].initial['title'], 'test.png')
# Check JSON
response_json = json.loads(response.content.decode())
self.assertIn('doc_id', response_json)
self.assertIn('form', response_json)
self.assertIn('success', response_json)
self.assertEqual(response_json['doc_id'], response.context['doc'].id)
self.assertTrue(response_json['success'])
# form should contain a collection chooser
self.assertIn('Collection', response_json['form'])
开发者ID:davecranwell,项目名称:wagtail,代码行数:43,代码来源:tests.py
示例8: test_get_with_collections
def test_get_with_collections(self):
root_collection = Collection.get_first_root_node()
root_collection.add_child(name="Evil plans")
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "wagtailimages/images/add.html")
self.assertContains(response, '<label for="id_collection">')
self.assertContains(response, "Evil plans")
开发者ID:quru,项目名称:wagtail,代码行数:10,代码来源:test_admin_views.py
示例9: test_get_with_collections
def test_get_with_collections(self):
root_collection = Collection.get_first_root_node()
root_collection.add_child(name="Evil plans")
response = self.client.get(reverse('wagtaildocs:add'))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtaildocs/documents/add.html')
self.assertContains(response, '<label for="id_collection">')
self.assertContains(response, "Evil plans")
开发者ID:davecranwell,项目名称:wagtail,代码行数:10,代码来源:tests.py
示例10: test_add_with_collections
def test_add_with_collections(self):
root_collection = Collection.get_first_root_node()
root_collection.add_child(name="Evil plans")
# Send request
response = self.client.get(reverse('wagtaildocs:add_multiple'))
# Check response
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtaildocs/multiple/add.html')
# collection chooser should exisst
self.assertContains(response, '<label for="id_adddocument_collection">')
self.assertContains(response, 'Evil plans')
开发者ID:davecranwell,项目名称:wagtail,代码行数:14,代码来源:tests.py
示例11: test_post
def test_post(self):
response = self.post({
'name': "Holiday snaps",
})
# Should redirect back to index
self.assertRedirects(response, reverse('wagtailadmin_collections:index'))
# Check that the collection was created and is a child of root
self.assertEqual(Collection.objects.filter(name="Holiday snaps").count(), 1)
root_collection = Collection.get_first_root_node()
self.assertEqual(
Collection.objects.get(name="Holiday snaps").get_parent(),
root_collection
)
开发者ID:Jimmy570,项目名称:wagtail,代码行数:16,代码来源:test_collections_views.py
示例12: test_post
def test_post(self):
# Build a fake file
fake_file = ContentFile(b("A boring example document"))
fake_file.name = "test.txt"
# Submit
post_data = {"title": "Test document", "file": fake_file}
response = self.client.post(reverse("wagtaildocs:add"), post_data)
# User should be redirected back to the index
self.assertRedirects(response, reverse("wagtaildocs:index"))
# Document should be created, and be placed in the root collection
self.assertTrue(models.Document.objects.filter(title="Test document").exists())
root_collection = Collection.get_first_root_node()
self.assertEqual(models.Document.objects.get(title="Test document").collection, root_collection)
开发者ID:m1kola,项目名称:wagtail,代码行数:16,代码来源:tests.py
示例13: test_as_ordinary_editor
def test_as_ordinary_editor(self):
user = get_user_model().objects.create_user(username="editor", email="[email protected]", password="password")
add_permission = Permission.objects.get(content_type__app_label="wagtailimages", codename="add_image")
admin_permission = Permission.objects.get(content_type__app_label="wagtailadmin", codename="access_admin")
image_adders_group = Group.objects.create(name="Image adders")
image_adders_group.permissions.add(admin_permission)
GroupCollectionPermission.objects.create(
group=image_adders_group, collection=Collection.get_first_root_node(), permission=add_permission
)
user.groups.add(image_adders_group)
self.client.login(username="editor", password="password")
response = self.client.get(reverse("wagtailimages:add_multiple"))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "wagtailimages/multiple/add.html")
开发者ID:quru,项目名称:wagtail,代码行数:17,代码来源:test_admin_views.py
示例14: test_simple
def test_simple(self):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/collections/index.html')
# Initially there should be no collections listed
# (Root should not be shown)
self.assertContains(response, "No collections have been created.")
root_collection = Collection.get_first_root_node()
self.collection = root_collection.add_child(name="Holiday snaps")
# Now the listing should contain our collection
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/collections/index.html')
self.assertNotContains(response, "No collections have been created.")
self.assertContains(response, "Holiday snaps")
开发者ID:Jimmy570,项目名称:wagtail,代码行数:18,代码来源:test_collections_views.py
示例15: test_group_create_adding_permissions
def test_group_create_adding_permissions(self):
response = self.post(
{
"name": "test group",
"page_permissions-0-page": ["1"],
"page_permissions-0-permission_types": ["edit", "publish"],
"page_permissions-TOTAL_FORMS": ["1"],
"document_permissions-0-collection": [Collection.get_first_root_node().id],
"document_permissions-0-permissions": [self.add_doc_permission.id],
"document_permissions-TOTAL_FORMS": ["1"],
}
)
self.assertRedirects(response, reverse("wagtailusers_groups:index"))
# The test group now exists, with two page permissions
# and one 'add document' collection permission
new_group = Group.objects.get(name="test group")
self.assertEqual(new_group.page_permissions.all().count(), 2)
self.assertEqual(new_group.collection_permissions.filter(permission=self.add_doc_permission).count(), 1)
开发者ID:thrawny,项目名称:wagtail,代码行数:19,代码来源:tests.py
示例16: setUp
def setUp(self):
# Create an image to edit
self.image = Image.objects.create(title="Test image", file=get_test_image_file())
# Create a user with change_image permission but not add_image
user = get_user_model().objects.create_user(
username="changeonly", email="[email protected]", password="password"
)
change_permission = Permission.objects.get(content_type__app_label="wagtailimages", codename="change_image")
admin_permission = Permission.objects.get(content_type__app_label="wagtailadmin", codename="access_admin")
image_changers_group = Group.objects.create(name="Image changers")
image_changers_group.permissions.add(admin_permission)
GroupCollectionPermission.objects.create(
group=image_changers_group, collection=Collection.get_first_root_node(), permission=change_permission
)
user.groups.add(image_changers_group)
self.assertTrue(self.client.login(username="changeonly", password="password"))
开发者ID:quru,项目名称:wagtail,代码行数:19,代码来源:test_admin_views.py
示例17: test_group_create_adding_permissions
def test_group_create_adding_permissions(self):
response = self.post({
'name': "test group",
'page_permissions-0-page': ['1'],
'page_permissions-0-permission_types': ['edit', 'publish'],
'page_permissions-TOTAL_FORMS': ['1'],
'document_permissions-0-collection': [Collection.get_first_root_node().id],
'document_permissions-0-permissions': [self.add_doc_permission.id],
'document_permissions-TOTAL_FORMS': ['1'],
})
self.assertRedirects(response, reverse('wagtailusers_groups:index'))
# The test group now exists, with two page permissions
# and one 'add document' collection permission
new_group = Group.objects.get(name='test group')
self.assertEqual(new_group.page_permissions.all().count(), 2)
self.assertEqual(
new_group.collection_permissions.filter(permission=self.add_doc_permission).count(),
1
)
开发者ID:jschneier,项目名称:wagtail,代码行数:20,代码来源:tests.py
示例18: test_add_with_collections
def test_add_with_collections(self):
root_collection = Collection.get_first_root_node()
evil_plans_collection = root_collection.add_child(name="Evil plans")
response = self.post({
'title': "Test image",
'file': SimpleUploadedFile('test.png', get_test_image_file().file.getvalue()),
'collection': evil_plans_collection.id,
})
# Should redirect back to index
self.assertRedirects(response, reverse('wagtailimages:index'))
# Check that the image was created
images = Image.objects.filter(title="Test image")
self.assertEqual(images.count(), 1)
# Test that it was placed in the Evil Plans collection
image = images.first()
self.assertEqual(image.collection, evil_plans_collection)
开发者ID:Eraldo,项目名称:wagtail,代码行数:20,代码来源:test_admin_views.py
示例19: test_duplicate_document_permissions_error
def test_duplicate_document_permissions_error(self):
# Try to submit multiple document permission entries for the same collection
root_collection = Collection.get_first_root_node()
response = self.post({
'name': "test group",
'document_permissions-0-collection': [root_collection.id],
'document_permissions-0-permissions': [self.add_doc_permission.id],
'document_permissions-1-collection': [root_collection.id],
'document_permissions-1-permissions': [self.change_doc_permission.id],
'document_permissions-TOTAL_FORMS': ['2'],
})
self.assertEqual(response.status_code, 200)
# formset should have a non-form error about the duplication
# (we don't know what index in permission_panels the formset will be,
# so just assert that it happens on at least one permission_panel)
self.assertTrue(
any(
hasattr(panel, 'non_form_errors') and panel.non_form_errors
for panel in response.context['permission_panels']
)
)
开发者ID:jschneier,项目名称:wagtail,代码行数:22,代码来源:tests.py
示例20: setUp
def setUp(self):
# Create some user accounts for testing permissions
User = get_user_model()
self.user = User.objects.create_user(username="user", email="[email protected]", password="password")
self.owner = User.objects.create_user(username="owner", email="[email protected]", password="password")
self.editor = User.objects.create_user(username="editor", email="[email protected]", password="password")
self.editor.groups.add(Group.objects.get(name="Editors"))
self.administrator = User.objects.create_superuser(
username="administrator", email="[email protected]", password="password"
)
# Owner user must have the add_document permission
self.adders_group = Group.objects.create(name="Document adders")
GroupCollectionPermission.objects.create(
group=self.adders_group,
collection=Collection.get_first_root_node(),
permission=Permission.objects.get(codename="add_document"),
)
self.owner.groups.add(self.adders_group)
# Create a document for running tests on
self.document = models.Document.objects.create(title="Test document", uploaded_by_user=self.owner)
开发者ID:m1kola,项目名称:wagtail,代码行数:22,代码来源:tests.py
注:本文中的wagtail.wagtailcore.models.Collection类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论