本文整理汇总了Python中django.contrib.admin.options.TO_FIELD_VAR属性的典型用法代码示例。如果您正苦于以下问题:Python options.TO_FIELD_VAR属性的具体用法?Python options.TO_FIELD_VAR怎么用?Python options.TO_FIELD_VAR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类django.contrib.admin.options
的用法示例。
在下文中一共展示了options.TO_FIELD_VAR属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_preserved_filters
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import TO_FIELD_VAR [as 别名]
def add_preserved_filters(self, context, url, popup=False, to_field=None):
opts = context.get('opts')
preserved_filters = context.get('preserved_filters')
parsed_url = list(urlparse(url))
parsed_qs = dict(parse_qsl(parsed_url[4]))
merged_qs = dict()
if opts and preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters))
match_url = '/%s' % url.partition(get_script_prefix())[2]
try:
match = resolve(match_url)
except Resolver404:
pass
else:
current_url = '%s:%s' % (match.app_name, match.url_name)
changelist_url = 'admin:%s_changelist' % self.get_base_viewname()
if changelist_url == current_url and '_changelist_filters' in preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))
merged_qs.update(preserved_filters)
if popup:
from django.contrib.admin.options import IS_POPUP_VAR
merged_qs[IS_POPUP_VAR] = 1
if to_field:
from django.contrib.admin.options import TO_FIELD_VAR
merged_qs[TO_FIELD_VAR] = to_field
merged_qs.update(parsed_qs)
parsed_url[4] = urlencode(merged_qs)
return urlunparse(parsed_url)
示例2: add_preserved_filters
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import TO_FIELD_VAR [as 别名]
def add_preserved_filters(context, url, popup=False, to_field=None):
opts = context.get('opts')
preserved_filters = context.get('preserved_filters')
parsed_url = list(urlparse(url))
parsed_qs = dict(parse_qsl(parsed_url[4]))
merged_qs = dict()
if opts and preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters))
match_url = '/%s' % url.partition(get_script_prefix())[2]
try:
match = resolve(match_url)
except Resolver404:
pass
else:
current_url = '%s:%s' % (match.app_name, match.url_name)
changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
if changelist_url == current_url and '_changelist_filters' in preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))
merged_qs.update(preserved_filters)
if popup:
from django.contrib.admin.options import IS_POPUP_VAR
merged_qs[IS_POPUP_VAR] = 1
if to_field:
from django.contrib.admin.options import TO_FIELD_VAR
merged_qs[TO_FIELD_VAR] = to_field
merged_qs.update(parsed_qs)
parsed_url[4] = urlencode(merged_qs)
return urlunparse(parsed_url)
示例3: change_view
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import TO_FIELD_VAR [as 别名]
def change_view(self, request, object_id, form_url='', extra_context=None):
"""
Override this function to hide the sumbit row from the user who has
view only permission
"""
to_field = request.POST.get(
TO_FIELD_VAR, request.GET.get(TO_FIELD_VAR)
)
model = self.model
opts = model._meta
# TODO: Overriding the change_view costs 1 query more (one from us
# and another from the super)
obj = self.get_object(request, unquote(object_id), to_field)
if self.has_view_permission(request, obj) and \
not self._has_change_only_permission(request, obj):
extra_context = extra_context or {}
extra_context['title'] = _('View %s') % force_text(
opts.verbose_name)
extra_context['show_save'] = False
extra_context['show_save_and_continue'] = False
extra_context['show_save_and_add_another'] = False
extra_context['show_save_as_new'] = False
inlines = self.get_inline_instances(request, obj)
for inline in inlines:
if (inline._has_change_only_permission(request, obj) or
inline.has_add_permission(request)):
extra_context['show_save'] = True
extra_context['show_save_and_continue'] = True
break
return super(AdminViewPermissionModelAdmin, self).change_view(
request, object_id, form_url, extra_context)
示例4: add_preserved_filters
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import TO_FIELD_VAR [as 别名]
def add_preserved_filters(context, url, popup=False, to_field=None):
opts = context.get('opts')
preserved_filters = context.get('preserved_filters')
parsed_url = list(urlparse(url))
parsed_qs = dict(parse_qsl(parsed_url[4]))
merged_qs = {}
if opts and preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters))
match_url = '/%s' % url.partition(get_script_prefix())[2]
try:
match = resolve(match_url)
except Resolver404:
pass
else:
current_url = '%s:%s' % (match.app_name, match.url_name)
changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
if changelist_url == current_url and '_changelist_filters' in preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))
merged_qs.update(preserved_filters)
if popup:
from django.contrib.admin.options import IS_POPUP_VAR
merged_qs[IS_POPUP_VAR] = 1
if to_field:
from django.contrib.admin.options import TO_FIELD_VAR
merged_qs[TO_FIELD_VAR] = to_field
merged_qs.update(parsed_qs)
parsed_url[4] = urlencode(merged_qs)
return urlunparse(parsed_url)
示例5: _prepare_form_template
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import TO_FIELD_VAR [as 别名]
def _prepare_form_template(self, request, object_id, extra_context=None):
self.change_form_template = None
if request.method == 'POST':
base_actions = ['_save', '_continue', '_addanother']
source_action = None
for action in base_actions:
if self._get_confirm_action_name(action) in request.POST:
request.POST = request.POST.copy()
request.POST[action] = request.POST[self._get_confirm_action_name(action)]
source_action = action
break
if not source_action:
form = None
to_field = request.POST.get(TO_FIELD_VAR, request.GET.get(TO_FIELD_VAR))
if not to_field or (to_field and self.to_field_allowed(request, to_field)):
obj = self.get_object(request, unquote(object_id), to_field) if object_id else None
ModelForm = self.get_form(request, obj)
form = ModelForm(request.POST, request.FILES, instance=obj)
if not form or not form.is_valid():
return extra_context
warning_context = self.build_warning_context(object_id, form)
if warning_context:
for action in base_actions:
if action in request.POST:
extra_context = {**warning_context, **extra_context} if extra_context else warning_context
self.change_form_template = self.save_warning_template
extra_context['confirmation_button_name'] = self._get_confirm_action_name(action)
extra_context['source_action'] = action
break
return extra_context
示例6: add_preserved_filters
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import TO_FIELD_VAR [as 别名]
def add_preserved_filters(context, url, popup=False, to_field=None):
opts = context.get('opts')
preserved_filters = context.get('preserved_filters')
parsed_url = list(urlparse(url))
parsed_qs = dict(parse_qsl(parsed_url[4]))
merged_qs = {}
if opts and preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters))
match_url = '/%s' % unquote(url).partition(get_script_prefix())[2]
try:
match = resolve(match_url)
except Resolver404:
pass
else:
current_url = '%s:%s' % (match.app_name, match.url_name)
changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
if changelist_url == current_url and '_changelist_filters' in preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))
merged_qs.update(preserved_filters)
if popup:
from django.contrib.admin.options import IS_POPUP_VAR
merged_qs[IS_POPUP_VAR] = 1
if to_field:
from django.contrib.admin.options import TO_FIELD_VAR
merged_qs[TO_FIELD_VAR] = to_field
merged_qs.update(parsed_qs)
parsed_url[4] = urlencode(merged_qs)
return urlunparse(parsed_url)