本文整理汇总了Python中wagtail.wagtailcore.models.Collection类的典型用法代码示例。如果您正苦于以下问题:Python Collection类的具体用法?Python Collection怎么用?Python Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
)
示例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
)
示例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()
示例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'))
示例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"])
示例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"
)
示例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'])
示例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")
示例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")
示例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')
示例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
)
示例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)
示例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")
示例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")
示例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)