本文整理匯總了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)