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


Python models.CHANGE屬性代碼示例

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


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

示例1: change

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def change(request, object, message_or_fields):
    """
    Log that an object has been successfully changed.

    The argument *message_or_fields* must be a sequence of modified field names
    or a custom change message.
    """
    if isinstance(message_or_fields, str):
        message = message_or_fields
    else:
        message = get_change_message(message_or_fields)
    models.LogEntry.objects.log_action(
        user_id=request.user.pk,
        content_type_id=ContentType.objects.get_for_model(object).pk,
        object_id=object.pk,
        object_repr=force_str(object),
        action_flag=models.CHANGE,
        change_message=message,
    ) 
開發者ID:GamesDoneQuick,項目名稱:donation-tracker,代碼行數:21,代碼來源:logutil.py

示例2: test_log_actions

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def test_log_actions(self):
        ma = ModelAdmin(Band, self.site)
        mock_request = MockRequest()
        mock_request.user = User.objects.create(username='bill')
        content_type = get_content_type_for_model(self.band)
        tests = (
            (ma.log_addition, ADDITION, {'added': {}}),
            (ma.log_change, CHANGE, {'changed': {'fields': ['name', 'bio']}}),
            (ma.log_deletion, DELETION, str(self.band)),
        )
        for method, flag, message in tests:
            with self.subTest(name=method.__name__):
                created = method(mock_request, self.band, message)
                fetched = LogEntry.objects.filter(action_flag=flag).latest('id')
                self.assertEqual(created, fetched)
                self.assertEqual(fetched.action_flag, flag)
                self.assertEqual(fetched.content_type, content_type)
                self.assertEqual(fetched.object_id, str(self.band.pk))
                self.assertEqual(fetched.user, mock_request.user)
                if flag == DELETION:
                    self.assertEqual(fetched.change_message, '')
                    self.assertEqual(fetched.object_repr, message)
                else:
                    self.assertEqual(fetched.change_message, str(message))
                    self.assertEqual(fetched.object_repr, str(self.band)) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:27,代碼來源:tests.py

示例3: lookups

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def lookups(self, request, model_admin):
        return (
            (admin_models.ADDITION, 'Added'),
            (admin_models.CHANGE, 'Changed'),
            (admin_models.DELETION, 'Deleted'),
        ) 
開發者ID:GamesDoneQuick,項目名稱:donation-tracker,代碼行數:8,代碼來源:filters.py

示例4: log_change

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def log_change(self, request, object, message):
        """
        Log that an object has been successfully changed.

        The default implementation creates an admin LogEntry object.
        """
        from django.contrib.admin.models import LogEntry, CHANGE
        LogEntry.objects.log_action(
            user_id=request.user.pk,
            content_type_id=get_content_type_for_model(object).pk,
            object_id=object.pk,
            object_repr=force_text(object),
            action_flag=CHANGE,
            change_message=message
        ) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:17,代碼來源:options.py

示例5: log_change

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def log_change(self, request, object, message):
        """
        Log that an object has been successfully changed.

        The default implementation creates an admin LogEntry object.
        """
        from django.contrib.admin.models import LogEntry, CHANGE
        return LogEntry.objects.log_action(
            user_id=request.user.pk,
            content_type_id=get_content_type_for_model(object).pk,
            object_id=object.pk,
            object_repr=str(object),
            action_flag=CHANGE,
            change_message=message,
        ) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:17,代碼來源:options.py

示例6: disable_action

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def disable_action(modeladmin, request, queryset):
    queryset.update(is_active=False)
    ct = ContentType.objects.get_for_model(queryset.model)
    for entry in queryset:
        LogEntry.objects.log_action(user_id=request.user.id,
                                    content_type_id=ct.pk,
                                    object_id=entry.pk,
                                    object_repr=entry.username,
                                    action_flag=CHANGE,
                                    change_message=_("Disabled"))
    messages.add_message(request, messages.INFO, '%d disabled' % queryset.count()) 
開發者ID:openwisp,項目名稱:django-freeradius,代碼行數:13,代碼來源:admin_actions.py

示例7: enable_action

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def enable_action(modeladmin, request, queryset):
    queryset.update(is_active=True)
    ct = ContentType.objects.get_for_model(queryset.model)
    for entry in queryset:
        LogEntry.objects.log_action(user_id=request.user.id,
                                    content_type_id=ct.pk,
                                    object_id=entry.pk,
                                    object_repr=entry.username,
                                    action_flag=CHANGE,
                                    change_message=_("Enabled"))
    messages.add_message(request, messages.INFO, '%d enabled' % queryset.count()) 
開發者ID:openwisp,項目名稱:django-freeradius,代碼行數:13,代碼來源:admin_actions.py

示例8: log_change

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def log_change(self, request, object, message):
        """
        Log that an object has been successfully changed.

        The default implementation creates an admin LogEntry object.
        """
        from django.contrib.admin.models import LogEntry, CHANGE
        return LogEntry.objects.log_action(
            user_id=request.user.pk,
            content_type_id=get_content_type_for_model(object).pk,
            object_id=object.pk,
            object_repr=force_text(object),
            action_flag=CHANGE,
            change_message=message,
        ) 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:17,代碼來源:options.py

示例9: log_change

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def log_change(self, request, object, message):
        """
        Log that an object has been successfully changed.

        The default implementation creates an admin LogEntry object.
        """
        from django.contrib.admin.models import LogEntry, CHANGE
        LogEntry.objects.log_action(
            user_id=request.user.pk,
            content_type_id=get_content_type_for_model(object).pk,
            object_id=object.pk,
            object_repr=force_text(object),
            action_flag=CHANGE,
            change_message=message,
        ) 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:17,代碼來源:options.py

示例10: perform_action

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def perform_action(self, request, action, queryset):
        try:
            method = getattr(Subscription, action)
        except AttributeError:
            self.message_user(request, 'Illegal action.', level=messages.ERROR)
            return

        failed_count = 0
        queryset_count = queryset.count()
        for entry in queryset:
            try:
                method(entry)
                entry.save()

                LogEntry.objects.log_action(
                    user_id=request.user.id,
                    content_type_id=ContentType.objects.get_for_model(entry).pk,
                    object_id=entry.id,
                    object_repr=force_text(entry),
                    action_flag=CHANGE,
                    change_message='{action} action initiated by user.'.format(
                        action=action.replace('_', ' ').strip().capitalize()
                    )
                )
            except TransitionNotAllowed:
                failed_count += 1
        if failed_count:
            if failed_count == queryset_count:
                self.message_user(request, 'Illegal state change attempt.',
                                  level=messages.ERROR)
            else:
                self.message_user(request, '%d state(s) changed (%d failed).' %
                                  (queryset_count - failed_count, failed_count),
                                  level=messages.WARNING)
        else:
            self.message_user(request, 'Successfully changed %d state(s).' %
                              queryset_count) 
開發者ID:silverapp,項目名稱:silver,代碼行數:39,代碼來源:admin.py

示例11: _call_method_on_queryset

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def _call_method_on_queryset(self, request, method, queryset, action):
        results = {}
        for document in queryset:
            results[document] = {}
            try:
                results[document]['success'] = True
                results[document]['result'] = method(document)

                document.save()

                LogEntry.objects.log_action(
                    user_id=request.user.id,
                    content_type_id=ContentType.objects.get_for_model(document).pk,
                    object_id=document.id,
                    object_repr=force_text(document),
                    action_flag=CHANGE,
                    change_message='{action} action initiated by user.'.format(
                        action=action.replace('_', ' ').strip().capitalize()
                    )
                )
            except TransitionNotAllowed as error:
                results[document]['result'] = mark_safe(error)
                results[document]['success'] = False
            except ValueError as error:
                results[document]['result'] = force_text(error)
                results[document]['success'] = False
            except AttributeError:
                results[document]['success'] = False
                results[document]['result'] = ""

        return results 
開發者ID:silverapp,項目名稱:silver,代碼行數:33,代碼來源:admin.py

示例12: setUp

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def setUp(self):
        self.user = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
        self.site = Site.objects.create(domain='example.org')
        self.a1 = Article.objects.create(
            site=self.site,
            title="Title",
            created=datetime(2008, 3, 12, 11, 54),
        )
        content_type_pk = ContentType.objects.get_for_model(Article).pk
        LogEntry.objects.log_action(
            self.user.pk, content_type_pk, self.a1.pk, repr(self.a1), CHANGE,
            change_message='Changed something'
        )
        self.client.force_login(self.user) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:16,代碼來源:test_logentry.py

示例13: test_logentry_unicode

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def test_logentry_unicode(self):
        log_entry = LogEntry()

        log_entry.action_flag = ADDITION
        self.assertTrue(str(log_entry).startswith('Added '))

        log_entry.action_flag = CHANGE
        self.assertTrue(str(log_entry).startswith('Changed '))

        log_entry.action_flag = DELETION
        self.assertTrue(str(log_entry).startswith('Deleted '))

        # Make sure custom action_flags works
        log_entry.action_flag = 4
        self.assertEqual(str(log_entry), 'LogEntry Object') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:17,代碼來源:test_logentry.py

示例14: test_log_action

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def test_log_action(self):
        content_type_pk = ContentType.objects.get_for_model(Article).pk
        log_entry = LogEntry.objects.log_action(
            self.user.pk, content_type_pk, self.a1.pk, repr(self.a1), CHANGE,
            change_message='Changed something else',
        )
        self.assertEqual(log_entry, LogEntry.objects.latest('id')) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:9,代碼來源:test_logentry.py

示例15: test_proxy_model_content_type_is_used_for_log_entries

# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import CHANGE [as 別名]
def test_proxy_model_content_type_is_used_for_log_entries(self):
        """
        Log entries for proxy models should have the proxy model's contenttype
        (#21084).
        """
        proxy_content_type = ContentType.objects.get_for_model(ArticleProxy, for_concrete_model=False)
        post_data = {
            'site': self.site.pk, 'title': "Foo", 'hist': "Bar",
            'created_0': '2015-12-25', 'created_1': '00:00',
        }
        changelist_url = reverse('admin:admin_utils_articleproxy_changelist')

        # add
        proxy_add_url = reverse('admin:admin_utils_articleproxy_add')
        response = self.client.post(proxy_add_url, post_data)
        self.assertRedirects(response, changelist_url)
        proxy_addition_log = LogEntry.objects.latest('id')
        self.assertEqual(proxy_addition_log.action_flag, ADDITION)
        self.assertEqual(proxy_addition_log.content_type, proxy_content_type)

        # change
        article_id = proxy_addition_log.object_id
        proxy_change_url = reverse('admin:admin_utils_articleproxy_change', args=(article_id,))
        post_data['title'] = 'New'
        response = self.client.post(proxy_change_url, post_data)
        self.assertRedirects(response, changelist_url)
        proxy_change_log = LogEntry.objects.latest('id')
        self.assertEqual(proxy_change_log.action_flag, CHANGE)
        self.assertEqual(proxy_change_log.content_type, proxy_content_type)

        # delete
        proxy_delete_url = reverse('admin:admin_utils_articleproxy_delete', args=(article_id,))
        response = self.client.post(proxy_delete_url, {'post': 'yes'})
        self.assertRedirects(response, changelist_url)
        proxy_delete_log = LogEntry.objects.latest('id')
        self.assertEqual(proxy_delete_log.action_flag, DELETION)
        self.assertEqual(proxy_delete_log.content_type, proxy_content_type) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:39,代碼來源:test_logentry.py


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