Python django.contrib.admin.utils.model_ngettext() Examples
The following are 7
code examples of django.contrib.admin.utils.model_ngettext().
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: admin.py From django-freeradius with GNU General Public License v3.0 | 6 votes |
def delete_selected_groups(self, request, queryset): if self.get_default_queryset(request, queryset).exists(): msg = _('Cannot proceed with the delete operation because ' 'the batch of items contains the default group, ' 'which cannot be deleted') self.message_user(request, msg, messages.ERROR) return False if not self.has_delete_permission(request): raise PermissionDenied n = queryset.count() if n: queryset.delete() self.message_user(request, _("Successfully deleted %(count)d %(items)s.") % { "count": n, "items": model_ngettext(self.opts, n) }, messages.SUCCESS) return None
Example #2
Source File: admin.py From openwisp-radius with GNU General Public License v3.0 | 6 votes |
def delete_selected_groups(self, request, queryset): if self.get_default_queryset(request, queryset).exists(): msg = _( 'Cannot proceed with the delete operation because ' 'the batch of items contains the default group, ' 'which cannot be deleted' ) self.message_user(request, msg, messages.ERROR) return False if not self.has_delete_permission(request): raise PermissionDenied n = queryset.count() if n: queryset.delete() self.message_user( request, _('Successfully deleted %(count)d %(items)s.') % {'count': n, 'items': model_ngettext(self.opts, n)}, messages.SUCCESS, ) return None
Example #3
Source File: admin.py From openwisp-users with BSD 3-Clause "New" or "Revised" License | 5 votes |
def make_inactive(self, request, queryset): queryset.update(is_active=False) count = queryset.count() if count: self.message_user( request, _( f'Successfully made {count} ' f'{model_ngettext(self.opts, count)} inactive.' ), messages.SUCCESS, )
Example #4
Source File: admin.py From openwisp-users with BSD 3-Clause "New" or "Revised" License | 5 votes |
def make_active(self, request, queryset): queryset.update(is_active=True) count = queryset.count() if count: self.message_user( request, _( f'Successfully made {count} ' f'{model_ngettext(self.opts, count)} active.' ), messages.SUCCESS, )
Example #5
Source File: base.py From django2-project-template with MIT License | 5 votes |
def hard_delete_selected(modeladmin, request, queryset): opts = modeladmin.model._meta # # pylint: disable=W0212 deletable_objects, model_count, perms_needed, protected = modeladmin.get_deleted_objects(queryset, request) if request.POST.get('post') and not protected: if perms_needed: raise PermissionDenied if queryset.count(): number_of_rows_deleted, __ = queryset.hard_delete() # __ = deleted_items if number_of_rows_deleted == 1: message_bit = _('1 record was') else: message_bit = _('%(number_of_rows)s records were') % dict(number_of_rows=number_of_rows_deleted) message = _('%(message_bit)s deleted') % dict(message_bit=message_bit) modeladmin.message_user(request, message) return None objects_name = model_ngettext(queryset) if perms_needed or protected: title = _('Cannot delete %(name)s') % {'name': objects_name} else: title = _('Are you sure?') context = { **modeladmin.admin_site.each_context(request), 'title': title, 'objects_name': str(objects_name), 'deletable_objects': [deletable_objects], 'model_count': dict(model_count).items(), 'queryset': queryset, 'perms_lacking': perms_needed, 'protected': protected, 'opts': opts, 'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME, 'media': modeladmin.media, } request.current_app = modeladmin.admin_site.name return TemplateResponse(request, 'admin/hard_delete_selected_confirmation.html', context)
Example #6
Source File: admin.py From django-users2 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def activate_users(self, request, queryset): """ Activates the selected users, if they are not already activated. """ n = 0 for user in queryset: if not user.is_active: user.activate() n += 1 self.message_user( request, _('Successfully activated %(count)d %(items)s.') % {'count': n, 'items': model_ngettext(self.opts, n)}, messages.SUCCESS)
Example #7
Source File: admin.py From django-users2 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def send_activation_email(self, request, queryset): """ Send activation emails for the selected users, if they are not already activated. """ n = 0 for user in queryset: if not user.is_active and settings.USERS_VERIFY_EMAIL: send_activation_email(user=user, request=request) n += 1 self.message_user( request, _('Activation emails sent to %(count)d %(items)s.') % {'count': n, 'items': model_ngettext(self.opts, n)}, messages.SUCCESS)