當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.model_ngettext方法代碼示例

本文整理匯總了Python中django.contrib.admin.utils.model_ngettext方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.model_ngettext方法的具體用法?Python utils.model_ngettext怎麽用?Python utils.model_ngettext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.contrib.admin.utils的用法示例。


在下文中一共展示了utils.model_ngettext方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: delete_selected_groups

# 需要導入模塊: from django.contrib.admin import utils [as 別名]
# 或者: from django.contrib.admin.utils import model_ngettext [as 別名]
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 
開發者ID:openwisp,項目名稱:django-freeradius,代碼行數:18,代碼來源:admin.py

示例2: delete_selected_groups

# 需要導入模塊: from django.contrib.admin import utils [as 別名]
# 或者: from django.contrib.admin.utils import model_ngettext [as 別名]
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 
開發者ID:openwisp,項目名稱:openwisp-radius,代碼行數:23,代碼來源:admin.py

示例3: make_inactive

# 需要導入模塊: from django.contrib.admin import utils [as 別名]
# 或者: from django.contrib.admin.utils import model_ngettext [as 別名]
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,
            ) 
開發者ID:openwisp,項目名稱:openwisp-users,代碼行數:14,代碼來源:admin.py

示例4: make_active

# 需要導入模塊: from django.contrib.admin import utils [as 別名]
# 或者: from django.contrib.admin.utils import model_ngettext [as 別名]
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,
            ) 
開發者ID:openwisp,項目名稱:openwisp-users,代碼行數:14,代碼來源:admin.py

示例5: hard_delete_selected

# 需要導入模塊: from django.contrib.admin import utils [as 別名]
# 或者: from django.contrib.admin.utils import model_ngettext [as 別名]
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) 
開發者ID:vigo,項目名稱:django2-project-template,代碼行數:43,代碼來源:base.py

示例6: activate_users

# 需要導入模塊: from django.contrib.admin import utils [as 別名]
# 或者: from django.contrib.admin.utils import model_ngettext [as 別名]
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) 
開發者ID:mishbahr,項目名稱:django-users2,代碼行數:17,代碼來源:admin.py

示例7: send_activation_email

# 需要導入模塊: from django.contrib.admin import utils [as 別名]
# 或者: from django.contrib.admin.utils import model_ngettext [as 別名]
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) 
開發者ID:mishbahr,項目名稱:django-users2,代碼行數:16,代碼來源:admin.py


注:本文中的django.contrib.admin.utils.model_ngettext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。