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


Python post_save.send方法代碼示例

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


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

示例1: add_participants

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def add_participants(self, request, *participants_ids):
        """
        Ensures the current user has the authorization to add the participants.
        By default, a user can add a participant if he himself is a participant.
        A callback can be added in the settings here.
        """
        participants_ids_returned_by_callback = getattr(settings, 'REST_MESSAGING_ADD_PARTICIPANTS_CALLBACK', self._limit_participants)(request, *participants_ids)
        participations = []
        ids = []
        for participant_id in participants_ids_returned_by_callback:
            participations.append(Participation(participant_id=participant_id, thread=self))
            ids.append(participant_id)

        Participation.objects.bulk_create(participations)
        post_save.send(Thread, instance=self, created=True, created_and_add_participants=True, request_participant_id=request.rest_messaging_participant.id)

        return ids 
開發者ID:raphaelgyory,項目名稱:django-rest-messaging,代碼行數:19,代碼來源:models.py

示例2: ajax_change_status

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def ajax_change_status(request):
    if not request.is_ajax():
        return HttpResponseForbidden()

    post_dict = dict(request.POST)
    if 'statuses_id[]' in post_dict and 'profile_ids[]' in post_dict:
        statuses = UserStatus.objects.filter(id__in=post_dict['statuses_id[]'])
        for profile in UserProfile.objects.filter(id__in=post_dict['profile_ids[]']):
            for status in statuses:
                profile.set_status(status)

            post_save.send(UserProfile, instance=profile, created=False)
            reversion.set_user(request.user)
            reversion.set_comment("Change from user status bulk change")

    return HttpResponse("OK") 
開發者ID:znick,項目名稱:anytask,代碼行數:18,代碼來源:views.py

示例3: test_pre_social_login

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def test_pre_social_login(self):
        """Test the pre-social-login Allauth signal handling."""
        mock_obj = mock.Mock()

        discord_login = SocialLogin(self.django_user, self.social_user)
        github_login = SocialLogin(self.django_user, self.social_user_github)
        unmapped_login = SocialLogin(self.django_user, self.social_unmapped)

        with mock.patch.object(AllauthSignalListener, "_apply_groups", mock_obj):
            AllauthSignalListener()

            # Don't attempt to apply groups if the user doesn't have a linked Discord account
            pre_social_login.send(SocialLogin, sociallogin=github_login)
            mock_obj.assert_not_called()

            # Don't attempt to apply groups if the user hasn't joined the Discord server
            pre_social_login.send(SocialLogin, sociallogin=unmapped_login)
            mock_obj.assert_not_called()

            # Attempt to apply groups if everything checks out
            pre_social_login.send(SocialLogin, sociallogin=discord_login)
            mock_obj.assert_called_with(self.discord_user, self.social_user) 
開發者ID:python-discord,項目名稱:site,代碼行數:24,代碼來源:test_signal_listener.py

示例4: test_social_added

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def test_social_added(self):
        """Test the social-account-added Allauth signal handling."""
        mock_obj = mock.Mock()

        discord_login = SocialLogin(self.django_user, self.social_user)
        github_login = SocialLogin(self.django_user, self.social_user_github)
        unmapped_login = SocialLogin(self.django_user, self.social_unmapped)

        with mock.patch.object(AllauthSignalListener, "_apply_groups", mock_obj):
            AllauthSignalListener()

            # Don't attempt to apply groups if the user doesn't have a linked Discord account
            social_account_added.send(SocialLogin, sociallogin=github_login)
            mock_obj.assert_not_called()

            # Don't attempt to apply groups if the user hasn't joined the Discord server
            social_account_added.send(SocialLogin, sociallogin=unmapped_login)
            mock_obj.assert_not_called()

            # Attempt to apply groups if everything checks out
            social_account_added.send(SocialLogin, sociallogin=discord_login)
            mock_obj.assert_called_with(self.discord_user, self.social_user) 
開發者ID:python-discord,項目名稱:site,代碼行數:24,代碼來源:test_signal_listener.py

示例5: test_social_updated

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def test_social_updated(self):
        """Test the social-account-updated Allauth signal handling."""
        mock_obj = mock.Mock()

        discord_login = SocialLogin(self.django_user, self.social_user)
        github_login = SocialLogin(self.django_user, self.social_user_github)
        unmapped_login = SocialLogin(self.django_user, self.social_unmapped)

        with mock.patch.object(AllauthSignalListener, "_apply_groups", mock_obj):
            AllauthSignalListener()

            # Don't attempt to apply groups if the user doesn't have a linked Discord account
            social_account_updated.send(SocialLogin, sociallogin=github_login)
            mock_obj.assert_not_called()

            # Don't attempt to apply groups if the user hasn't joined the Discord server
            social_account_updated.send(SocialLogin, sociallogin=unmapped_login)
            mock_obj.assert_not_called()

            # Attempt to apply groups if everything checks out
            social_account_updated.send(SocialLogin, sociallogin=discord_login)
            mock_obj.assert_called_with(self.discord_user, self.social_user) 
開發者ID:python-discord,項目名稱:site,代碼行數:24,代碼來源:test_signal_listener.py

示例6: test_social_removed

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def test_social_removed(self):
        """Test the social-account-removed Allauth signal handling."""
        mock_obj = mock.Mock()

        with mock.patch.object(AllauthSignalListener, "_apply_groups", mock_obj):
            AllauthSignalListener()

            # Don't attempt to remove groups if the user doesn't have a linked Discord account
            social_account_removed.send(SocialLogin, socialaccount=self.social_user_github)
            mock_obj.assert_not_called()

            # Don't attempt to remove groups if the social account doesn't map to a Django user
            social_account_removed.send(SocialLogin, socialaccount=self.social_unmapped)
            mock_obj.assert_not_called()

            # Attempt to remove groups if everything checks out
            social_account_removed.send(SocialLogin, socialaccount=self.social_user)
            mock_obj.assert_called_with(self.discord_user, self.social_user, deletion=True) 
開發者ID:python-discord,項目名稱:site,代碼行數:20,代碼來源:test_signal_listener.py

示例7: get_or_create_thread

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def get_or_create_thread(self, request, name=None, *participant_ids):
        """
        When a Participant posts a message to other participants without specifying an existing Thread,
        we must
        1. Create a new Thread if they have not yet opened the discussion.
        2. If they have already opened the discussion and multiple Threads are not allowed for the same users, we must
            re-attach this message to the existing thread.
        3. If they have already opened the discussion and multiple Threads are allowed, we simply create a new one.
        """

        # we get the current participant
        # or create him if he does not exit

        participant_ids = list(participant_ids)
        if request.rest_messaging_participant.id not in participant_ids:
            participant_ids.append(request.rest_messaging_participant.id)

        # we need at least one other participant
        if len(participant_ids) < 2:
            raise Exception('At least two participants are required.')

        if getattr(settings, "REST_MESSAGING_THREAD_UNIQUE_FOR_ACTIVE_RECIPIENTS", True) is True:
            # if we limit the number of threads by active participants
            # we ensure a thread is not already running
            existing_threads = self.get_active_threads_involving_all_participants(*participant_ids)
            if len(list(existing_threads)) > 0:
                return existing_threads[0]

        # we have no existing Thread or multiple Thread instances are allowed
        thread = Thread.objects.create(name=name)

        # we add the participants
        thread.add_participants(request, *participant_ids)

        # we send a signal to say the thread with participants is created
        post_save.send(Thread, instance=thread, created=True, created_and_add_participants=True, request_participant_id=request.rest_messaging_participant.id)

        return thread 
開發者ID:raphaelgyory,項目名稱:django-rest-messaging,代碼行數:40,代碼來源:models.py

示例8: remove_participant

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def remove_participant(self, request, participant):
        removable_participants_ids = self.get_removable_participants_ids(request)
        if participant.id in removable_participants_ids:
            participation = Participation.objects.get(participant=participant, thread=self, date_left=None)
            participation.date_left = now()
            participation.save()
            post_save.send(Thread, instance=self, created=False, remove_participant=True, removed_participant=participant, request_participant_id=request.rest_messaging_participant.id)
            return participation
        else:
            raise Exception('The participant may not be removed.') 
開發者ID:raphaelgyory,項目名稱:django-rest-messaging,代碼行數:12,代碼來源:models.py

示例9: on_model_pre_create

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def on_model_pre_create(self, model, instance):
        try:
            model_cls, django_instance = self.get_django_instance(model, instance)
            pre_save.send(model_cls, raw=True, using=self, instance=django_instance, update_fields=[])
        except Exception as e:
            logger.warning('[!] on_model_pre_create signal failed: {}'.format(str(e))) 
開發者ID:jet-admin,項目名稱:jet-bridge,代碼行數:8,代碼來源:configuration.py

示例10: on_model_post_create

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def on_model_post_create(self, model, instance):
        try:
            model_cls, django_instance = self.get_django_instance(model, instance)
            post_save.send(model_cls, raw=True, using=self, instance=django_instance, created=True, update_fields=[])
        except Exception as e:
            logger.warning('[!] on_model_post_create signal failed: {}'.format(str(e))) 
開發者ID:jet-admin,項目名稱:jet-bridge,代碼行數:8,代碼來源:configuration.py

示例11: on_model_pre_update

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def on_model_pre_update(self, model, instance):
        try:
            model_cls, django_instance = self.get_django_instance(model, instance)
            pre_save.send(model_cls, raw=True, using=self, instance=django_instance, update_fields=[])
        except Exception as e:
            logger.warning('[!] on_model_pre_update signal failed: {}'.format(str(e))) 
開發者ID:jet-admin,項目名稱:jet-bridge,代碼行數:8,代碼來源:configuration.py

示例12: on_model_post_update

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def on_model_post_update(self, model, instance):
        try:
            model_cls, django_instance = self.get_django_instance(model, instance)
            post_save.send(model_cls, raw=True, using=self, instance=django_instance, created=False, update_fields=[])
        except Exception as e:
            logger.warning('[!] on_model_post_update signal failed: {}'.format(str(e))) 
開發者ID:jet-admin,項目名稱:jet-bridge,代碼行數:8,代碼來源:configuration.py

示例13: on_model_pre_delete

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def on_model_pre_delete(self, model, instance):
        try:
            model_cls, django_instance = self.get_django_instance(model, instance)
            pre_delete.send(model_cls, using=self, instance=django_instance)
            self.pre_delete_django_instance = django_instance
        except Exception as e:
            logger.warning('[!] on_model_pre_delete signal failed: {}'.format(str(e))) 
開發者ID:jet-admin,項目名稱:jet-bridge,代碼行數:9,代碼來源:configuration.py

示例14: run_journal_signals

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def run_journal_signals():
    """
    Gets and saves all journal objects forcing them to fire signals, 1.2 -> 1.3 introduced a couple of signals
    so we want them to be fired on upgrade.
    :return: None
    """
    print('Processing journal signals')
    journals = journal_models.Journal.objects.all()

    for journal in journals:
        print('Firing signals for {journal_code}'.format(journal_code=journal.code), end='...')

        post_save.send(journal_models.Journal, instance=journal, created=True)

        print(' [OK]') 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:17,代碼來源:12_13.py

示例15: test_model_save

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import send [as 別名]
def test_model_save(self):
        """Test signal handling for when Discord user model objects are saved to DB."""
        mock_obj = mock.Mock()

        with mock.patch.object(AllauthSignalListener, "_apply_groups", mock_obj):
            AllauthSignalListener()

            post_save.send(
                DiscordUser,
                instance=self.discord_user,
                raw=True,
                created=None,        # Not realistic, but we don't use it
                using=None,          # Again, we don't use it
                update_fields=False  # Always false during integration testing
            )

            mock_obj.assert_not_called()

            post_save.send(
                DiscordUser,
                instance=self.discord_user,
                raw=False,
                created=None,        # Not realistic, but we don't use it
                using=None,          # Again, we don't use it
                update_fields=False  # Always false during integration testing
            )

            mock_obj.assert_called_with(self.discord_user, self.social_user) 
開發者ID:python-discord,項目名稱:site,代碼行數:30,代碼來源:test_signal_listener.py


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