本文整理汇总了Python中django.contrib.admin.utils.unquote方法的典型用法代码示例。如果您正苦于以下问题:Python utils.unquote方法的具体用法?Python utils.unquote怎么用?Python utils.unquote使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.utils
的用法示例。
在下文中一共展示了utils.unquote方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: chosen
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def chosen(request, app_label, model_name, pk):
model = get_snippet_model_from_url_params(app_label, model_name)
item = get_object_or_404(model, pk=unquote(pk))
snippet_data = {
'id': str(item.pk),
'string': str(item),
'edit_link': reverse('wagtailsnippets:edit', args=(
app_label, model_name, quote(item.pk)))
}
return render_modal_workflow(
request,
None, None,
None, json_data={'step': 'chosen', 'result': snippet_data}
)
示例2: base_url_args
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def base_url_args(self):
return [unquote(arg) for arg in self.view_args]
示例3: get_parent_instance
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def get_parent_instance(self, parent_id):
return get_object_or_404(self.parent_model, pk=unquote(parent_id))
示例4: resend_view
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def resend_view(self, request, object_id, extra_context=None): # pylint: disable=W0613
"""
View that re-sends the notification
"""
obj = self.get_object(request, unquote(object_id))
success = obj.resend()
if success:
self.message_user(request, 'The notification was resent successfully.', messages.SUCCESS)
else:
self.message_user(request, 'The notification failed to resend.', messages.ERROR)
return self.response_post_save_change(request, obj)
示例5: change_view
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [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)
示例6: __init__
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def __init__(self, model_admin, instance_pk):
super().__init__(model_admin)
self.instance_pk = unquote(instance_pk)
self.pk_safe = quote(self.instance_pk)
self.site = get_object_or_404(Site, id=self.instance_pk)
self.instance = self.model.get_for_site(self.site)
self.instance.save()
示例7: json_view
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def json_view(self, request, object_id):
obj = self.get_object(request, unquote(object_id))
return HttpResponse(content=obj.to_json(), content_type='application/json')
示例8: _prepare_form_template
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [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
示例9: usage
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def usage(request, app_label, model_name, pk):
model = get_snippet_model_from_url_params(app_label, model_name)
instance = get_object_or_404(model, pk=unquote(pk))
paginator = Paginator(instance.get_usage(), per_page=20)
used_by = paginator.get_page(request.GET.get('p'))
return TemplateResponse(request, "wagtailsnippets/snippets/usage.html", {
'instance': instance,
'used_by': used_by
})
示例10: history_view
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def history_view(self, request, object_id, extra_context=None):
"The 'history' admin view for this model."
from django.contrib.admin.models import LogEntry
# First check if the user can see this history.
model = self.model
obj = get_object_or_404(self.get_queryset(request),
pk=unquote(object_id))
if not self.has_change_permission(request, obj):
raise PermissionDenied
# Then get the history for this object.
opts = model._meta
app_label = opts.app_label
action_list = LogEntry.objects.filter(
object_id=unquote(str(obj.identity)),
# this is the change for our override;
content_type=get_content_type_for_model(model)
).select_related().order_by('action_time')
ctx = self.admin_site.each_context(request)
context = dict(ctx,
title=('Change history: %s') % force_text(obj),
action_list=action_list,
module_name=capfirst(
force_text(opts.verbose_name_plural)),
object=obj,
opts=opts,
preserved_filters=self.get_preserved_filters(request),
)
context.update(extra_context or {})
return TemplateResponse(request, self.object_history_template or [
"admin/%s/%s/object_history.html" % (app_label, opts.model_name),
"admin/%s/object_history.html" % app_label,
"admin/object_history.html"
], context)
示例11: __init__
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def __init__(self, model_admin, form_pk):
self.form_pk = unquote(form_pk)
object_qs = model_admin.model._default_manager.get_queryset()
object_qs = object_qs.filter(pk=self.form_pk)
self.form_instance = get_object_or_404(object_qs)
super().__init__(model_admin)
示例12: __init__
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def __init__(self, model_admin, parent_pk):
self.parent_pk = unquote(parent_pk)
object_qs = model_admin.model._default_manager.get_queryset()
object_qs = object_qs.filter(pk=self.parent_pk)
self.parent_instance = get_object_or_404(object_qs)
super().__init__(model_admin)
示例13: change_view
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def change_view(self, request, object_id, form_url='', extra_context=None):
context = extra_context or {}
obj = self.get_object(request, unquote(object_id))
if obj:
context.update({
'title': force_text(obj.plugin),
})
return super(FormSubmissionAdmin, self).change_view(
request, object_id, form_url=form_url,
extra_context=context)
示例14: user_change_password
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def user_change_password(self, request, id, form_url=''):
if not self.has_change_permission(request):
raise PermissionDenied
user = self.get_object(request, unquote(id))
if user is None:
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {
'name': force_text(self.model._meta.verbose_name),
'key': escape(id),
})
if request.method == 'POST':
form = self.change_password_form(user, request.POST)
if form.is_valid():
form.save()
change_message = self.construct_change_message(request, form, None)
self.log_change(request, user, change_message)
msg = ugettext('Password changed successfully.')
messages.success(request, msg)
update_session_auth_hash(request, form.user)
return HttpResponseRedirect('..')
else:
form = self.change_password_form(user)
fieldsets = [(None, {'fields': list(form.base_fields)})]
adminForm = admin.helpers.AdminForm(form, fieldsets, {})
context = {
'title': _('Change password: %s') % escape(user.get_username()),
'adminForm': adminForm,
'form_url': form_url,
'form': form,
'is_popup': (IS_POPUP_VAR in request.POST or
IS_POPUP_VAR in request.GET),
'add': True,
'change': False,
'has_delete_permission': False,
'has_change_permission': True,
'has_absolute_url': False,
'opts': self.model._meta,
'original': user,
'save_as': False,
'show_save': True,
}
context.update(admin.site.each_context(request))
request.current_app = self.admin_site.name
return TemplateResponse(request,
self.change_user_password_template or
'admin/auth/user/change_password.html',
context)
示例15: user_change_password
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import unquote [as 别名]
def user_change_password(self, request, id, form_url=''):
if not self.has_change_permission(request):
raise PermissionDenied
user = self.get_object(request, unquote(id))
if user is None:
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {
'name': self.model._meta.verbose_name,
'key': escape(id),
})
if request.method == 'POST':
form = self.change_password_form(user, request.POST)
if form.is_valid():
form.save()
change_message = self.construct_change_message(request, form, None)
self.log_change(request, user, change_message)
msg = gettext('Password changed successfully.')
messages.success(request, msg)
update_session_auth_hash(request, form.user)
return HttpResponseRedirect(
reverse(
'%s:%s_%s_change' % (
self.admin_site.name,
user._meta.app_label,
user._meta.model_name,
),
args=(user.pk,),
)
)
else:
form = self.change_password_form(user)
fieldsets = [(None, {'fields': list(form.base_fields)})]
adminForm = admin.helpers.AdminForm(form, fieldsets, {})
context = {
'title': _('Change password: %s') % escape(user.get_username()),
'adminForm': adminForm,
'form_url': form_url,
'form': form,
'is_popup': (IS_POPUP_VAR in request.POST or
IS_POPUP_VAR in request.GET),
'add': True,
'change': False,
'has_delete_permission': False,
'has_change_permission': True,
'has_absolute_url': False,
'opts': self.model._meta,
'original': user,
'save_as': False,
'show_save': True,
}
context.update(self.admin_site.each_context(request))
request.current_app = self.admin_site.name
return TemplateResponse(
request,
self.change_user_password_template or
'admin/auth/user/change_password.html',
context,
)