本文整理汇总了Python中wagtail.core.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:rkhleics,项目名称:wagtail,代码行数:26,代码来源:test_admin_views.py
示例2: 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)
self.assertTrue(response.context['doc'].file_hash)
# check that it is in the 'evil plans' collection
doc = models.get_document_model().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(
set(response.context['form'].fields),
set(models.get_document_model().admin_form_fields) - {'file'} | {'collection'},
)
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:nealtodd,项目名称:wagtail,代码行数:48,代码来源:test_admin_views.py
示例3: test_post_video_with_collections
def test_post_video_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 movie"))
fake_file.name = 'movie.mp3'
# Submit
post_data = {
'title': "Test media",
'file': fake_file,
'duration': 100,
'collection': evil_plans_collection.id,
}
response = self.client.post(reverse('wagtailmedia:add', args=('video', )), post_data)
# User should be redirected back to the index
self.assertRedirects(response, reverse('wagtailmedia:index'))
# Media should be created, and be placed in the Evil Plans collection
self.assertTrue(models.Media.objects.filter(title="Test media").exists())
media = models.Media.objects.get(title="Test media")
self.assertEqual(media.collection, evil_plans_collection)
self.assertEqual(media.type, 'video')
开发者ID:torchbox,项目名称:wagtailmedia,代码行数:26,代码来源:test_views.py
示例4: setUp
def setUp(self):
# Build a fake file
fake_file = ContentFile(b("A boring example song"))
fake_file.name = 'song.mp3'
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 media to edit
self.media = models.Media.objects.create(
title="Test media", file=fake_file, collection=self.nice_plans_collection, duration=100
)
# Create a user with change_media permission but not add_media
user = get_user_model().objects.create_user(
username='changeonly',
email='[email protected]',
password='password'
)
change_permission = Permission.objects.get(
content_type__app_label='wagtailmedia', codename='change_media'
)
admin_permission = Permission.objects.get(
content_type__app_label='wagtailadmin', codename='access_admin'
)
self.changers_group = Group.objects.create(name='Media 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:torchbox,项目名称:wagtailmedia,代码行数:35,代码来源:test_permissions.py
示例5: 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
document = models.Document.objects.get(title="Test document")
root_collection = Collection.get_first_root_node()
self.assertEqual(
document.collection,
root_collection
)
# Check that the file_size field was set
self.assertTrue(document.file_size)
开发者ID:rkhleics,项目名称:wagtail,代码行数:25,代码来源:test_admin_views.py
示例6: 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_image permission
image_adders_group = Group.objects.create(name="Image adders")
GroupCollectionPermission.objects.create(
group=image_adders_group,
collection=Collection.get_first_root_node(),
permission=Permission.objects.get(codename='add_image'),
)
self.owner.groups.add(image_adders_group)
# Create an image for running tests on
self.image = Image.objects.create(
title="Test image",
uploaded_by_user=self.owner,
file=get_test_image_file(),
)
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:26,代码来源:test_models.py
示例7: 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:gasman,项目名称:wagtail,代码行数:26,代码来源:test_admin_views.py
示例8: setUp
def setUp(self):
add_doc_permission = Permission.objects.get(
content_type__app_label='wagtaildocs', codename='add_document'
)
admin_permission = Permission.objects.get(
content_type__app_label='wagtailadmin', codename='access_admin'
)
root_collection = Collection.get_first_root_node()
self.evil_plans_collection = root_collection.add_child(name="Evil plans")
conspirators_group = Group.objects.create(name="Evil conspirators")
conspirators_group.permissions.add(admin_permission)
GroupCollectionPermission.objects.create(
group=conspirators_group,
collection=self.evil_plans_collection,
permission=add_doc_permission
)
user = get_user_model().objects.create_user(
username='moriarty',
email='[email protected]',
password='password'
)
user.groups.add(conspirators_group)
self.client.login(username='moriarty', password='password')
开发者ID:rkhleics,项目名称:wagtail,代码行数:27,代码来源:test_admin_views.py
示例9: index
def index(request):
Image = get_image_model()
# Get images (filtered by user permission)
images = permission_policy.instances_user_has_any_permission_for(
request.user, ['change', 'delete']
).order_by('-created_at')
# Search
query_string = None
if 'q' in request.GET:
form = SearchForm(request.GET, placeholder=_("Search images"))
if form.is_valid():
query_string = form.cleaned_data['q']
images = images.search(query_string)
else:
form = SearchForm(placeholder=_("Search images"))
# Filter by collection
current_collection = None
collection_id = request.GET.get('collection_id')
if collection_id:
try:
current_collection = Collection.objects.get(id=collection_id)
images = images.filter(collection=current_collection)
except (ValueError, Collection.DoesNotExist):
pass
paginator = Paginator(images, per_page=20)
images = paginator.get_page(request.GET.get('p'))
collections = permission_policy.collections_user_has_any_permission_for(
request.user, ['add', 'change']
)
if len(collections) < 2:
collections = None
else:
collections = Collection.order_for_display(collections)
# Create response
if request.is_ajax():
return render(request, 'wagtailimages/images/results.html', {
'images': images,
'query_string': query_string,
'is_searching': bool(query_string),
})
else:
return render(request, 'wagtailimages/images/index.html', {
'images': images,
'query_string': query_string,
'is_searching': bool(query_string),
'search_form': form,
'popular_tags': popular_tags_for_model(Image),
'collections': collections,
'current_collection': current_collection,
'user_can_add': permission_policy.user_has_permission(request.user, 'add'),
})
开发者ID:Proper-Job,项目名称:wagtail,代码行数:59,代码来源:images.py
示例10: 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:BertrandBordage,项目名称:wagtail,代码行数:8,代码来源:test_collection_model.py
示例11: test_index_with_collection
def test_index_with_collection(self):
root_collection = Collection.get_first_root_node()
root_collection.add_child(name="Evil plans")
self.make_docs()
response = self.client.get(reverse('wagtaildocs:index'))
self.assertContains(response, '<th>Collection</th>')
self.assertContains(response, '<td>Root</td>')
开发者ID:nealtodd,项目名称:wagtail,代码行数:9,代码来源:test_admin_views.py
示例12: test_ordering
def test_ordering(self):
root_collection = Collection.get_first_root_node()
root_collection.add_child(name="Milk")
root_collection.add_child(name="Bread")
root_collection.add_child(name="Avacado")
response = self.get()
self.assertEqual(
[collection.name for collection in response.context['object_list']],
['Avacado', 'Bread', 'Milk'])
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:9,代码来源:test_collections_views.py
示例13: dummy_wagtail_doc
def dummy_wagtail_doc(request):
if not Collection.objects.exists(): # pragma: no cover
Collection.add_root()
doc = Document(title='hello')
doc.file.save('foo.txt', ContentFile('foo', 'foo.txt'))
doc.save()
doc = Document.objects.get(pk=doc.pk) # Reload to ensure the upload took
def nuke():
try: # Try cleaning up so `/var/media` isn't full of foo
doc.file.delete()
doc.delete()
except: # pragma: no cover
pass
request.addfinalizer(nuke)
return doc
开发者ID:City-of-Helsinki,项目名称:wagtail-svgmap,代码行数:18,代码来源:conftest.py
示例14: 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:gasman,项目名称:wagtail,代码行数:10,代码来源:test_admin_views.py
示例15: 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:rkhleics,项目名称:wagtail,代码行数:10,代码来源:test_admin_views.py
示例16: 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:rkhleics,项目名称:wagtail,代码行数:14,代码来源:test_admin_views.py
示例17: 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:Henk-JanVanHasselaar,项目名称:wagtail,代码行数:16,代码来源:test_collections_views.py
示例18: get_chooser_context
def get_chooser_context(request):
"""Helper function to return common template context variables for the main chooser view"""
collections = Collection.objects.all()
if len(collections) < 2:
collections = None
else:
collections = Collection.order_for_display(collections)
return {
'searchform': SearchForm(),
'is_searching': False,
'query_string': None,
'will_select_format': request.GET.get('select_format'),
'popular_tags': popular_tags_for_model(get_image_model()),
'collections': collections,
}
开发者ID:nealtodd,项目名称:wagtail,代码行数:17,代码来源:chooser.py
示例19: 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:Henk-JanVanHasselaar,项目名称:wagtail,代码行数:18,代码来源:test_collections_views.py
示例20: test_get_video_with_collections
def test_get_video_with_collections(self):
root_collection = Collection.get_first_root_node()
root_collection.add_child(name="Evil plans")
response = self.client.get(reverse('wagtailmedia:add', args=('video', )))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailmedia/media/add.html')
self.assertContains(response, '<label for="id_collection">')
self.assertContains(response, "Evil plans")
self.assertContains(response, 'Add video')
self.assertContains(
response,
'<form action="{0}" method="POST" enctype="multipart/form-data" novalidate>'.format(
reverse('wagtailmedia:add', args=('video',))
),
count=1
)
开发者ID:torchbox,项目名称:wagtailmedia,代码行数:18,代码来源:test_views.py
注:本文中的wagtail.core.models.Collection类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论