本文整理汇总了Python中wagtail.wagtailcore.utils.resolve_model_string函数的典型用法代码示例。如果您正苦于以下问题:Python resolve_model_string函数的具体用法?Python resolve_model_string怎么用?Python resolve_model_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resolve_model_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: page_model_from_string
def page_model_from_string(string):
page_model = resolve_model_string(string)
if not issubclass(page_model, Page):
raise ValueError("Model is not a page")
return page_model
开发者ID:njamaleddine,项目名称:wagtail,代码行数:7,代码来源:chooser.py
示例2: target_content_type
def target_content_type(cls):
if cls._target_content_type is None:
if cls.page_type:
target_models = []
for page_type in cls.page_type:
try:
target_models.append(resolve_model_string(page_type))
except LookupError:
raise ImproperlyConfigured(
"{0}.page_type must be of the form 'app_label.model_name', given {1!r}".format(
cls.__name__, page_type
)
)
except ValueError:
raise ImproperlyConfigured(
"{0}.page_type refers to model {1!r} that has not been installed".format(
cls.__name__, page_type
)
)
cls._target_content_type = list(ContentType.objects.get_for_models(*target_models).values())
else:
target_model = cls.model._meta.get_field(cls.field_name).rel.to
cls._target_content_type = [ContentType.objects.get_for_model(target_model)]
return cls._target_content_type
开发者ID:Anlim,项目名称:wagtail,代码行数:27,代码来源:edit_handlers.py
示例3: get_invoice_model
def get_invoice_model(cls):
if isinstance(cls.invoice_model, models.Model):
return cls.invoice_model
elif isinstance(cls.invoice_model, string_types):
return resolve_model_string(cls.invoice_model, cls._meta.app_label)
else:
raise ValueError('Can not resolve {0}.invoice_model in to a model: {1!r}'.format(
cls.__name__, cls.invoice_model))
开发者ID:huxley,项目名称:wagtailinvoices,代码行数:8,代码来源:models.py
示例4: get_model
def get_model(self, request):
if 'type' not in request.GET:
return Page
model_name = request.GET['type']
try:
return resolve_model_string(model_name)
except LookupError:
raise self.BadRequestError("type doesn't exist")
开发者ID:michaelfillier,项目名称:wagtailapi,代码行数:9,代码来源:api.py
示例5: target_models
def target_models(self):
target_models = []
for target_model in self._target_models:
target_models.append(
resolve_model_string(target_model)
)
return target_models
开发者ID:xtelaur,项目名称:wagtail,代码行数:9,代码来源:field_block.py
示例6: target_model
def target_model(self):
"""
Defines the model used by the base ChooserBlock for ID <-> instance
conversions. If a single page type is specified in target_model,
we can use that to get the more specific instance "for free"; otherwise
use the generic Page model.
"""
if len(self.target_models) == 1:
return self.target_models[0]
return resolve_model_string('wagtailcore.Page')
开发者ID:xtelaur,项目名称:wagtail,代码行数:11,代码来源:field_block.py
示例7: page_models_from_string
def page_models_from_string(string):
page_models = []
for sub_string in string.split(','):
page_model = resolve_model_string(sub_string)
if not issubclass(page_model, Page):
raise ValueError("Model is not a page")
page_models.append(page_model)
return tuple(page_models)
开发者ID:Eraldo,项目名称:wagtail,代码行数:12,代码来源:chooser.py
示例8: get_model
def get_model(self, request):
if 'type' not in request.GET:
return Page
model_name = request.GET['type']
try:
model = resolve_model_string(model_name)
if not issubclass(model, Page):
raise BadRequestError("type doesn't exist")
return model
except LookupError:
raise BadRequestError("type doesn't exist")
开发者ID:ThemeSurgeon,项目名称:wagtail,代码行数:14,代码来源:endpoints.py
示例9: target_model
def target_model(cls):
if cls._target_model is None:
if cls.snippet_type:
try:
cls._target_model = resolve_model_string(cls.snippet_type)
except LookupError:
raise ImproperlyConfigured("{0}.snippet_type must be of the form 'app_label.model_name', given {1!r}".format(
cls.__name__, cls.snippet_type))
except ValueError:
raise ImproperlyConfigured("{0}.snippet_type refers to model {1!r} that has not been installed".format(
cls.__name__, cls.snippet_type))
else:
cls._target_model = cls.model._meta.get_field(cls.field_name).rel.to
return cls._target_model
开发者ID:Tivix,项目名称:wagtail,代码行数:15,代码来源:edit_handlers.py
示例10: target_content_type
def target_content_type(cls):
if cls._target_content_type is None:
if cls.page_type:
try:
model = resolve_model_string(cls.page_type)
except LookupError:
raise ImproperlyConfigured("{0}.page_type must be of the form 'app_label.model_name', given {1!r}".format(
cls.__name__, cls.page_type))
except ValueError:
raise ImproperlyConfigured("{0}.page_type refers to model {1!r} that has not been installed".format(
cls.__name__, cls.page_type))
cls._target_content_type = ContentType.objects.get_for_model(model)
else:
# TODO: infer the content type by introspection on the foreign key
cls._target_content_type = ContentType.objects.get_by_natural_key('wagtailcore', 'page')
return cls._target_content_type
开发者ID:jalourenco,项目名称:wagtail,代码行数:18,代码来源:edit_handlers.py
示例11: search
def search(request, parent_page_id=None):
page_types = request.GET.get('page_types')
content_types = []
# Convert page_types string into list of ContentType objects
if page_types:
try:
content_types = ContentType.objects.get_for_models(*[
resolve_model_string(page_type) for page_type in page_types.split(',')])
except LookupError:
raise Http404
search_form = SearchForm(request.GET)
if search_form.is_valid() and search_form.cleaned_data['q']:
pages = Page.objects.exclude(
depth=1 # never include root
)
# Restrict content types
if content_types:
pages = pages.filter(content_type__in=content_types)
# Do search
pages = pages.filter(title__icontains=search_form.cleaned_data['q'])
# Truncate results
pages = pages[:10]
else:
pages = Page.objects.none()
shown_pages = []
for page in pages:
page.can_choose = True
shown_pages.append(page)
return render(
request, 'wagtailadmin/chooser/_search_results.html',
shared_context(request, {
'searchform': search_form,
'pages': shown_pages,
})
)
开发者ID:javierhdez3,项目名称:wagtail,代码行数:42,代码来源:chooser.py
示例12: target_model
def target_model(cls):
if cls._target_model is None:
if cls.snippet_type:
# RemovedInWagtail16Warning: The target_model is automatically
# detected from the relation, so snippet_type is deprecated.
try:
cls._target_model = resolve_model_string(cls.snippet_type)
except LookupError:
raise ImproperlyConfigured(
"{0}.snippet_type must be of the form 'app_label.model_name', given {1!r}"
.format(cls.__name__, cls.snippet_type)
)
except ValueError:
raise ImproperlyConfigured(
"{0}.snippet_type refers to model {1!r} that has not been installed"
.format(cls.__name__, cls.snippet_type)
)
else:
cls._target_model = cls.model._meta.get_field(cls.field_name).rel.to
return cls._target_model
开发者ID:Anlim,项目名称:wagtail,代码行数:21,代码来源:edit_handlers.py
示例13: clean_parent_page_types
def clean_parent_page_types(cls):
"""
Returns the list of parent page types, with strings converted to class
objects where required
"""
if cls._clean_parent_page_types is None:
parent_page_types = getattr(cls, 'parent_page_types', None)
if parent_page_types is None:
# if parent_page_types is not specified on the Page class, allow all page types as subpages
res = get_page_types()
else:
try:
models = [resolve_model_string(model_string, cls._meta.app_label)
for model_string in parent_page_types]
except LookupError as err:
raise ImproperlyConfigured("{0}.parent_page_types must be a list of 'app_label.model_name' strings, given {1!r}".format(
cls.__name__, err.args[1]))
res = list(map(ContentType.objects.get_for_model, models))
cls._clean_parent_page_types = res
return cls._clean_parent_page_types
开发者ID:Rakuli,项目名称:wagtail,代码行数:22,代码来源:models.py
示例14: get_queryset
def get_queryset(self):
request = self.request
# Allow pages to be filtered to a specific type
if 'type' not in request.GET:
model = Page
else:
model_name = request.GET['type']
try:
model = resolve_model_string(model_name)
except LookupError:
raise BadRequestError("type doesn't exist")
if not issubclass(model, Page):
raise BadRequestError("type doesn't exist")
# Get live pages that are not in a private section
queryset = model.objects.public().live()
# Filter by site
queryset = queryset.descendant_of(request.site.root_page, inclusive=True)
return queryset
开发者ID:Tivix,项目名称:wagtail,代码行数:22,代码来源:endpoints.py
示例15: target_models
def target_models(cls):
if cls.page_type:
target_models = []
for page_type in cls.page_type:
try:
target_models.append(resolve_model_string(page_type))
except LookupError:
raise ImproperlyConfigured(
"{0}.page_type must be of the form 'app_label.model_name', given {1!r}".format(
cls.__name__, page_type
)
)
except ValueError:
raise ImproperlyConfigured(
"{0}.page_type refers to model {1!r} that has not been installed".format(
cls.__name__, page_type
)
)
return target_models
else:
return [cls.model._meta.get_field(cls.field_name).rel.to]
开发者ID:Eraldo,项目名称:wagtail,代码行数:23,代码来源:edit_handlers.py
示例16: test_resolve_from_string_with_default_app
def test_resolve_from_string_with_default_app(self):
model = resolve_model_string("Page", default_app="wagtailcore")
self.assertEqual(model, Page)
开发者ID:jjanssen,项目名称:wagtail,代码行数:4,代码来源:tests.py
示例17: browse
def browse(request, parent_page_id=None):
ITEMS_PER_PAGE = 25
page_types = request.GET.get('page_types', 'wagtailcore.page').split(',')
desired_classes = []
for page_type in page_types:
try:
content_type = resolve_model_string(page_type)
except LookupError:
raise Http404
desired_classes.append(content_type)
if parent_page_id:
parent_page = get_object_or_404(Page, id=parent_page_id)
else:
parent_page = Page.get_first_root_node()
parent_page.can_choose = issubclass(parent_page.specific_class, tuple(desired_classes))
search_form = SearchForm()
pages = parent_page.get_children()
if desired_classes == [Page]:
# apply pagination first, since we know that the page listing won't
# have to be filtered, and that saves us walking the entire list
p = request.GET.get('p', 1)
paginator = Paginator(pages, ITEMS_PER_PAGE)
try:
pages = paginator.page(p)
except PageNotAnInteger:
pages = paginator.page(1)
except EmptyPage:
pages = paginator.page(paginator.num_pages)
for page in pages:
page.can_choose = True
page.can_descend = page.get_children_count()
else:
# restrict the page listing to just those pages that:
# - are of the given content type (taking into account class inheritance)
# - or can be navigated into (i.e. have children)
shown_pages = []
for page in pages:
page.can_choose = issubclass(page.specific_class or Page, tuple(desired_classes))
page.can_descend = page.get_children_count()
if page.can_choose or page.can_descend:
shown_pages.append(page)
# Apply pagination
p = request.GET.get('p', 1)
paginator = Paginator(shown_pages, ITEMS_PER_PAGE)
try:
pages = paginator.page(p)
except PageNotAnInteger:
pages = paginator.page(1)
except EmptyPage:
pages = paginator.page(paginator.num_pages)
return render_modal_workflow(
request,
'wagtailadmin/chooser/browse.html', 'wagtailadmin/chooser/browse.js',
shared_context(request, {
'parent_page': parent_page,
'pages': pages,
'search_form': search_form,
'page_type_string': ','.join(page_types),
'page_type_names': [desired_class.get_verbose_name() for desired_class in desired_classes],
'page_types_restricted': (page_type != 'wagtailcore.page')
})
)
开发者ID:javierhdez3,项目名称:wagtail,代码行数:74,代码来源:chooser.py
示例18: target_model
def target_model(self):
return resolve_model_string(self._target_model)
开发者ID:nilnvoid,项目名称:wagtail,代码行数:2,代码来源:field_block.py
示例19: get_post_model
def get_post_model(cls):
if not cls.post_model:
return
return resolve_model_string(cls.post_model)
开发者ID:MariusCC,项目名称:wagtailforums,代码行数:5,代码来源:models.py
示例20: test_resolve_from_class
def test_resolve_from_class(self):
model = resolve_model_string(Page)
self.assertEqual(model, Page)
开发者ID:sixpearls,项目名称:wagtail,代码行数:4,代码来源:tests.py
注:本文中的wagtail.wagtailcore.utils.resolve_model_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论