Python django.contrib.admin.utils.quote() Examples
The following are 30
code examples of django.contrib.admin.utils.quote().
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: test_logentry.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_recentactions_without_content_type(self): """ If a LogEntry is missing content_type it will not display it in span tag under the hyperlink. """ response = self.client.get(reverse('admin:index')) link = reverse('admin:admin_utils_article_change', args=(quote(self.a1.pk),)) should_contain = """<a href="%s">%s</a>""" % (escape(link), escape(repr(self.a1))) self.assertContains(response, should_contain) should_contain = "Article" self.assertContains(response, should_contain) logentry = LogEntry.objects.get(content_type__model__iexact='article') # If the log entry doesn't have a content type it should still be # possible to view the Recent Actions part (#10275). logentry.content_type = None logentry.save() should_contain = should_contain.encode() counted_presence_before = response.content.count(should_contain) response = self.client.get(reverse('admin:index')) counted_presence_after = response.content.count(should_contain) self.assertEqual(counted_presence_before - 1, counted_presence_after)
Example #3
Source File: test_logentry.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_logentry_change_message(self): """ LogEntry.change_message is stored as a dumped JSON structure to be able to get the message dynamically translated at display time. """ post_data = { 'site': self.site.pk, 'title': 'Changed', 'hist': 'Some content', 'created_0': '2008-03-12', 'created_1': '11:54', } change_url = reverse('admin:admin_utils_article_change', args=[quote(self.a1.pk)]) response = self.client.post(change_url, post_data) self.assertRedirects(response, reverse('admin:admin_utils_article_changelist')) logentry = LogEntry.objects.filter(content_type__model__iexact='article').latest('id') self.assertEqual(logentry.get_change_message(), 'Changed title and hist.') with translation.override('fr'): self.assertEqual(logentry.get_change_message(), 'Modification de title et hist.') add_url = reverse('admin:admin_utils_article_add') post_data['title'] = 'New' response = self.client.post(add_url, post_data) self.assertRedirects(response, reverse('admin:admin_utils_article_changelist')) logentry = LogEntry.objects.filter(content_type__model__iexact='article').latest('id') self.assertEqual(logentry.get_change_message(), 'Added.') with translation.override('fr'): self.assertEqual(logentry.get_change_message(), 'Ajout.')
Example #4
Source File: test_logentry.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_recentactions_without_content_type(self): """ If a LogEntry is missing content_type it will not display it in span tag under the hyperlink. """ response = self.client.get(reverse('admin:index')) link = reverse('admin:admin_utils_article_change', args=(quote(self.a1.pk),)) should_contain = """<a href="%s">%s</a>""" % (escape(link), escape(repr(self.a1))) self.assertContains(response, should_contain) should_contain = "Article" self.assertContains(response, should_contain) logentry = LogEntry.objects.get(content_type__model__iexact='article') # If the log entry doesn't have a content type it should still be # possible to view the Recent Actions part (#10275). logentry.content_type = None logentry.save() should_contain = should_contain.encode() counted_presence_before = response.content.count(should_contain) response = self.client.get(reverse('admin:index')) counted_presence_after = response.content.count(should_contain) self.assertEqual(counted_presence_before - 1, counted_presence_after)
Example #5
Source File: test_logentry.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_logentry_change_message(self): """ LogEntry.change_message is stored as a dumped JSON structure to be able to get the message dynamically translated at display time. """ post_data = { 'site': self.site.pk, 'title': 'Changed', 'hist': 'Some content', 'created_0': '2008-03-12', 'created_1': '11:54', } change_url = reverse('admin:admin_utils_article_change', args=[quote(self.a1.pk)]) response = self.client.post(change_url, post_data) self.assertRedirects(response, reverse('admin:admin_utils_article_changelist')) logentry = LogEntry.objects.filter(content_type__model__iexact='article').latest('id') self.assertEqual(logentry.get_change_message(), 'Changed title and hist.') with translation.override('fr'): self.assertEqual(logentry.get_change_message(), 'Modification de title et hist.') add_url = reverse('admin:admin_utils_article_add') post_data['title'] = 'New' response = self.client.post(add_url, post_data) self.assertRedirects(response, reverse('admin:admin_utils_article_changelist')) logentry = LogEntry.objects.filter(content_type__model__iexact='article').latest('id') self.assertEqual(logentry.get_change_message(), 'Added.') with translation.override('fr'): self.assertEqual(logentry.get_change_message(), 'Ajout.')
Example #6
Source File: admin_helpers.py From hypha with BSD 3-Clause "New" or "Revised" License | 6 votes |
def add_child_button(self, pk, child_verbose_name, **kwargs): """Build a add child button, to easily add a child under meta term.""" instance = self.model.objects.get(pk=pk) if instance.is_archived or instance.get_parent() and instance.get_parent().is_archived: return classnames = self.prepare_classnames( start=self.edit_button_classnames + ['icon', 'icon-plus'], add=kwargs.get('classnames_add'), exclude=kwargs.get('classnames_exclude') ) return { 'classname': classnames, 'label': 'Add %s %s' % ( child_verbose_name, self.verbose_name), 'title': 'Add %s %s under this one' % ( child_verbose_name, self.verbose_name), 'url': self.url_helper.get_action_url('add_child', quote(pk)), }
Example #7
Source File: admin.py From wagtail-torchbox with MIT License | 6 votes |
def get_buttons_for_obj(self, obj, exclude=None, classnames_add=None, classnames_exclude=None): exclude = exclude or [] classnames_add = classnames_add or [] classnames_exclude = classnames_exclude or [] btns = super(TaxonomyButtonHelper, self).get_buttons_for_obj( obj, exclude=exclude, classnames_add=classnames_add, classnames_exclude=classnames_exclude ) ph = self.permission_helper usr = self.request.user pk = quote(getattr(obj, self.opts.pk.attname)) if('usage' not in exclude and ph.user_can_edit_obj(usr, obj)): btns.append( self.usage_button(pk, classnames_add, classnames_exclude) ) return btns
Example #8
Source File: helpers.py From wagtailmodeladmin with MIT License | 6 votes |
def get_buttons_for_obj(self, obj, exclude=[], classnames_add=[], classnames_exclude=[]): ph = self.permission_helper pk = quote(getattr(obj, self.opts.pk.attname)) btns = [] if('inspect' not in exclude and self.inspect_view_enabled): btns.append( self.inspect_button(pk, classnames_add, classnames_exclude) ) if('edit' not in exclude and ph.can_edit_object(self.user, obj)): btns.append( self.edit_button(pk, classnames_add, classnames_exclude) ) if('delete' not in exclude and ph.can_delete_object(self.user, obj)): btns.append( self.delete_button(pk, classnames_add, classnames_exclude) ) return btns
Example #9
Source File: tests.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_after_delete_snippet_hook(self): advert = Advert.objects.create( url='http://www.example.com/', text='Test hook', ) def hook_func(request, instances): self.assertIsInstance(request, HttpRequest) self.assertQuerysetEqual(instances, ["<Advert: Test hook>"]) return HttpResponse("Overridden!") with self.register_hook('after_delete_snippet', hook_func): response = self.client.post( reverse('wagtailsnippets:delete', args=('tests', 'advert', quote(advert.pk), )) ) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, b"Overridden!")
Example #10
Source File: wagtail_hooks.py From longclaw with MIT License | 6 votes |
def get_buttons_for_obj(self, obj, exclude=None, classnames_add=None, classnames_exclude=None): if exclude is None: exclude = [] if classnames_add is None: classnames_add = [] if classnames_exclude is None: classnames_exclude = [] ph = self.permission_helper usr = self.request.user pk = quote(getattr(obj, self.opts.pk.attname)) btns = [] if ph.user_can_inspect_obj(usr, obj): btns.append(self.detail_button( pk, classnames_add, classnames_exclude)) btns.append(self.cancel_button( pk, classnames_add, classnames_exclude)) return btns
Example #11
Source File: modeladmin.py From wagtailmenus with MIT License | 5 votes |
def get_buttons_for_obj(self, obj, exclude=[], classnames_add=[], classnames_exclude=[]): ph = self.permission_helper usr = self.request.user pk = quote(getattr(obj, self.opts.pk.attname)) btns = super().get_buttons_for_obj( obj, exclude, classnames_add, classnames_exclude) if('copy' not in exclude and ph.user_can_create(usr)): btns.append( self.copy_button(pk, classnames_add, classnames_exclude) ) return btns
Example #12
Source File: button.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def delete_button(self, pk, classnames_add=None, classnames_exclude=None): if classnames_add is None: classnames_add = [] if classnames_exclude is None: classnames_exclude = [] classnames = self.delete_button_classnames + classnames_add cn = self.finalise_classname(classnames, classnames_exclude) return { 'url': self.url_helper.get_action_url('delete', quote(pk)), 'label': _('Delete'), 'classname': cn, 'title': _('Delete this %s') % self.verbose_name, }
Example #13
Source File: button.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def unpublish_button(self, pk, classnames_add=None, classnames_exclude=None): if classnames_add is None: classnames_add = [] if classnames_exclude is None: classnames_exclude = [] classnames = self.unpublish_button_classnames + classnames_add cn = self.finalise_classname(classnames, classnames_exclude) return { 'url': self.url_helper.get_action_url('unpublish', quote(pk)), 'label': _('Unpublish'), 'classname': cn, 'title': _('Unpublish this %s') % self.verbose_name, }
Example #14
Source File: button.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def copy_button(self, pk, classnames_add=None, classnames_exclude=None): if classnames_add is None: classnames_add = [] if classnames_exclude is None: classnames_exclude = [] classnames = self.copy_button_classnames + classnames_add cn = self.finalise_classname(classnames, classnames_exclude) return { 'url': self.url_helper.get_action_url('copy', quote(pk)), 'label': _('Copy'), 'classname': cn, 'title': _('Copy this %s') % self.verbose_name, }
Example #15
Source File: wagtail_hooks.py From wagtailstreamforms with MIT License | 5 votes |
def button(self, pk, action, label, title, classnames_add, classnames_exclude): cn = self.finalise_classname(classnames_add, classnames_exclude) button = { "url": self.url_helper.get_action_url(action, quote(pk)), "label": label, "classname": cn, "title": title, } return button
Example #16
Source File: admin_urls.py From python with Apache License 2.0 | 5 votes |
def admin_urlquote(value): return quote(value)
Example #17
Source File: models.py From python with Apache License 2.0 | 5 votes |
def get_admin_url(self): """ Returns the admin URL to edit the object represented by this log entry. """ if self.content_type and self.object_id: url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model) try: return reverse(url_name, args=(quote(self.object_id),)) except NoReverseMatch: pass return None
Example #18
Source File: admin_urls.py From openhgsenti with Apache License 2.0 | 5 votes |
def admin_urlquote(value): return quote(value)
Example #19
Source File: models.py From openhgsenti with Apache License 2.0 | 5 votes |
def get_admin_url(self): """ Returns the admin URL to edit the object represented by this log entry. """ if self.content_type and self.object_id: url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model) try: return reverse(url_name, args=(quote(self.object_id),)) except NoReverseMatch: pass return None
Example #20
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 #21
Source File: helpers.py From wagtailmodeladmin with MIT License | 5 votes |
def get_buttons_for_obj(self, obj, exclude=[], classnames_add=[], classnames_exclude=[]): user = self.user ph = self.permission_helper pk = quote(getattr(obj, self.opts.pk.attname)) btns = [] if('inspect' not in exclude and self.inspect_view_enabled): btns.append( self.inspect_button(pk, classnames_add, classnames_exclude) ) if('edit' not in exclude and ph.can_edit_object(user, obj)): btns.append( self.edit_button(pk, classnames_add, classnames_exclude) ) if('copy' not in exclude and ph.can_copy_object(user, obj)): btns.append( self.copy_button(pk, classnames_add, classnames_exclude) ) if('unpublish' not in exclude and ph.can_unpublish_object(user, obj)): btns.append( self.unpublish_button(pk, classnames_add, classnames_exclude) ) if('delete' not in exclude and ph.can_delete_object(user, obj)): btns.append( self.delete_button(pk, classnames_add, classnames_exclude) ) return btns
Example #22
Source File: admin_urls.py From python2017 with MIT License | 5 votes |
def admin_urlquote(value): return quote(value)
Example #23
Source File: models.py From python2017 with MIT License | 5 votes |
def get_admin_url(self): """ Returns the admin URL to edit the object represented by this log entry. """ if self.content_type and self.object_id: url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model) try: return reverse(url_name, args=(quote(self.object_id),)) except NoReverseMatch: pass return None
Example #24
Source File: admin.py From wagtail-torchbox with MIT License | 5 votes |
def usage_button(self, pk, classnames_add=[], classnames_exclude=[]): classnames = self.usage_button_classnames + classnames_add cn = self.finalise_classname(classnames, classnames_exclude) return { 'url': self.url_helper.get_action_url('usage', quote(pk)), 'label': _('Usage'), 'classname': cn, 'title': _('Usage of %s') % self.verbose_name, }
Example #25
Source File: models.py From bioforum with MIT License | 5 votes |
def get_admin_url(self): """ Return the admin URL to edit the object represented by this log entry. """ if self.content_type and self.object_id: url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model) try: return reverse(url_name, args=(quote(self.object_id),)) except NoReverseMatch: pass return None
Example #26
Source File: admin_urls.py From bioforum with MIT License | 5 votes |
def admin_urlquote(value): return quote(value)
Example #27
Source File: models.py From django-actions-logger with MIT License | 5 votes |
def get_admin_url(self): """ Returns the admin URL to edit the object represented by this log entry. """ if self.content_type and self.object_id: url_name = 'admin:%s_%s_change' % ( self.content_type.app_label, self.content_type.model ) try: return reverse(url_name, args=(quote(self.object_id),)) except NoReverseMatch: pass return None
Example #28
Source File: test_logentry.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_logentry_change_message_localized_datetime_input(self): """ Localized date/time inputs shouldn't affect changed form data detection. """ post_data = { 'site': self.site.pk, 'title': 'Changed', 'hist': 'Some content', 'created_0': '12/03/2008', 'created_1': '11:54', } with translation.override('fr'): change_url = reverse('admin:admin_utils_article_change', args=[quote(self.a1.pk)]) response = self.client.post(change_url, post_data) self.assertRedirects(response, reverse('admin:admin_utils_article_changelist')) logentry = LogEntry.objects.filter(content_type__model__iexact='article').latest('id') self.assertEqual(logentry.get_change_message(), 'Changed title and hist.')
Example #29
Source File: test_logentry.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_logentry_get_admin_url(self): """ LogEntry.get_admin_url returns a URL to edit the entry's object or None for nonexistent (possibly deleted) models. """ logentry = LogEntry.objects.get(content_type__model__iexact='article') expected_url = reverse('admin:admin_utils_article_change', args=(quote(self.a1.pk),)) self.assertEqual(logentry.get_admin_url(), expected_url) self.assertIn('article/%d/change/' % self.a1.pk, logentry.get_admin_url()) logentry.content_type.model = "nonexistent" self.assertIsNone(logentry.get_admin_url())
Example #30
Source File: models.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def get_admin_url(self): """ Returns the admin URL to edit the object represented by this log entry. """ if self.content_type and self.object_id: url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model) try: return reverse(url_name, args=(quote(self.object_id),)) except NoReverseMatch: pass return None