Python django.contrib.admin.utils.unquote() Examples
The following are 22
code examples of django.contrib.admin.utils.unquote().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.admin.utils
, or try the search function
.
Example #1
Source File: chooser.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
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} )
Example #2
Source File: __init__.py From django-subadmin with MIT License | 5 votes |
def get_parent_instance(self, parent_id): return get_object_or_404(self.parent_model, pk=unquote(parent_id))
Example #3
Source File: admin.py From djangocms-forms with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #4
Source File: admin_views.py From hypha with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #5
Source File: admin_views.py From hypha with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #6
Source File: admin.py From cleanerversion with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: snippets.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 })
Example #8
Source File: admin.py From lexpredict-contraxsuite with GNU Affero General Public License v3.0 | 5 votes |
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
Example #9
Source File: admin.py From django-connected with BSD 3-Clause "New" or "Revised" License | 5 votes |
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')
Example #10
Source File: views.py From wagtailmenus with MIT License | 5 votes |
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()
Example #11
Source File: admin.py From django-admin-view-permission with BSD 2-Clause "Simplified" License | 5 votes |
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)
Example #12
Source File: admin.py From django-herald with MIT License | 5 votes |
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)
Example #13
Source File: __init__.py From django-subadmin with MIT License | 5 votes |
def base_url_args(self): return [unquote(arg) for arg in self.view_args]
Example #14
Source File: admin.py From Hands-On-Application-Development-with-PyCharm with MIT License | 4 votes |
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, **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, )
Example #15
Source File: snippets.py From wagtail with BSD 3-Clause "New" or "Revised" License | 4 votes |
def edit(request, app_label, model_name, pk): model = get_snippet_model_from_url_params(app_label, model_name) permission = get_permission_name('change', model) if not request.user.has_perm(permission): return permission_denied(request) instance = get_object_or_404(model, pk=unquote(pk)) edit_handler = get_snippet_edit_handler(model) edit_handler = edit_handler.bind_to(instance=instance, request=request) form_class = edit_handler.get_form_class() if request.method == 'POST': form = form_class(request.POST, request.FILES, instance=instance) if form.is_valid(): form.save() messages.success( request, _("%(snippet_type)s '%(instance)s' updated.") % { 'snippet_type': capfirst(model._meta.verbose_name), 'instance': instance }, buttons=[ messages.button(reverse( 'wagtailsnippets:edit', args=(app_label, model_name, quote(instance.pk)) ), _('Edit')) ] ) for fn in hooks.get_hooks('after_edit_snippet'): result = fn(request, instance) if hasattr(result, 'status_code'): return result return redirect('wagtailsnippets:list', app_label, model_name) else: messages.validation_error( request, _("The snippet could not be saved due to errors."), form ) else: form = form_class(instance=instance) edit_handler = edit_handler.bind_to(form=form) return TemplateResponse(request, 'wagtailsnippets/snippets/edit.html', { 'model_opts': model._meta, 'instance': instance, 'edit_handler': edit_handler, 'form': form, })
Example #16
Source File: snippets.py From wagtail with BSD 3-Clause "New" or "Revised" License | 4 votes |
def delete(request, app_label, model_name, pk=None): model = get_snippet_model_from_url_params(app_label, model_name) permission = get_permission_name('delete', model) if not request.user.has_perm(permission): return permission_denied(request) if pk: instances = [get_object_or_404(model, pk=unquote(pk))] else: ids = request.GET.getlist('id') instances = model.objects.filter(pk__in=ids) count = len(instances) if request.method == 'POST': for instance in instances: instance.delete() if count == 1: message_content = _("%(snippet_type)s '%(instance)s' deleted.") % { 'snippet_type': capfirst(model._meta.verbose_name), 'instance': instance } else: # This message is only used in plural form, but we'll define it with ngettext so that # languages with multiple plural forms can be handled correctly (or, at least, as # correctly as possible within the limitations of verbose_name_plural...) message_content = ngettext( "%(count)d %(snippet_type)s deleted.", "%(count)d %(snippet_type)s deleted.", count ) % { 'snippet_type': capfirst(model._meta.verbose_name_plural), 'count': count } messages.success(request, message_content) for fn in hooks.get_hooks('after_delete_snippet'): result = fn(request, instances) if hasattr(result, 'status_code'): return result return redirect('wagtailsnippets:list', app_label, model_name) return TemplateResponse(request, 'wagtailsnippets/snippets/confirm_delete.html', { 'model_opts': model._meta, 'count': count, 'instances': instances, 'submit_url': ( reverse('wagtailsnippets:delete-multiple', args=(app_label, model_name)) + '?' + urlencode([('id', instance.pk) for instance in instances]) ), })
Example #17
Source File: admin.py From bioforum with MIT License | 4 votes |
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, )
Example #18
Source File: admin.py From openhgsenti with Apache License 2.0 | 4 votes |
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( 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)
Example #19
Source File: admin.py From python2017 with MIT License | 4 votes |
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( 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, )
Example #20
Source File: admin.py From django_mqtt with GNU General Public License v2.0 | 4 votes |
def user_change_password(self, request, object_id, form_url=''): if not self.has_change_permission(request): raise PermissionDenied acl = self.get_object(request, unquote(object_id)) if acl 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(object_id), }) if request.method == 'POST': form = self.change_password_form(acl, request.POST) if form.is_valid(): form.save() change_message = self.construct_change_message(request, form, None) self.log_change(request, acl, change_message) msg = ugettext('Password changed successfully.') messages.success(request, msg) return HttpResponseRedirect( reverse( '%s:%s_%s_change' % ( self.admin_site.name, acl._meta.app_label, acl._meta.model_name, ), args=(acl.pk,), ) ) else: form = self.change_password_form(acl) fieldsets = [(None, {'fields': list(form.base_fields)})] adminForm = admin.helpers.AdminForm(form, fieldsets, {}) context = { 'title': _('Change password: %s') % escape(acl), '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': acl, 'save_as': False, 'show_save': True, } context.update(self.admin_site.each_context(request)) request.current_app = self.admin_site.name return TemplateResponse( request, 'admin/django_mqtt/acl/change_password.html', context, )
Example #21
Source File: admin.py From GTDWeb with GNU General Public License v2.0 | 4 votes |
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)
Example #22
Source File: admin.py From DjangoUnleashed-1.8 with BSD 2-Clause "Simplified" License | 4 votes |
def user_change_password( self, request, user_id, form_url=''): if not self.has_change_permission( request): raise PermissionDenied user = self.get_object( request, unquote(user_id)) if user is None: raise Http404( '{name} object with primary key ' '{key} does not exist.'.format( name=force_text( self.model ._meta.verbose_name), key=escape(user_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) success( request, 'Password changed.') update_session_auth_hash( request, form.user) return HttpResponseRedirect('..') else: form = self.change_password_form(user) context = { 'title': 'Change password: {}'.format( escape(user.get_username())), 'form_url': form_url, 'form': form, 'is_popup': ( IS_POPUP_VAR in request.POST or IS_POPUP_VAR in request.GET), 'opts': self.model._meta, 'original': user, } context.update( admin.site.each_context(request)) request.current_app = self.admin_site.name return TemplateResponse( request, self.change_user_password_template, context)