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


Python post_save.connect方法代碼示例

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


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

示例1: contribute_to_class

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def contribute_to_class(self, cls, name, *args, **kwargs):
        @classproperty
        def river(_self):
            return RiverObject(_self)

        self.field_name = name

        self._add_to_class(cls, self.field_name + "_transition_approvals",
                           GenericRelation('%s.%s' % (TransitionApproval._meta.app_label, TransitionApproval._meta.object_name)))
        self._add_to_class(cls, self.field_name + "_transitions", GenericRelation('%s.%s' % (Transition._meta.app_label, Transition._meta.object_name)))

        if id(cls) not in workflow_registry.workflows:
            self._add_to_class(cls, "river", river)

        super(StateField, self).contribute_to_class(cls, name, *args, **kwargs)

        if id(cls) not in workflow_registry.workflows:
            post_save.connect(_on_workflow_object_saved, self.model, False, dispatch_uid='%s_%s_riverstatefield_post' % (self.model, name))
            post_delete.connect(_on_workflow_object_deleted, self.model, False, dispatch_uid='%s_%s_riverstatefield_post' % (self.model, name))

        workflow_registry.add(self.field_name, cls) 
開發者ID:javrasya,項目名稱:django-river,代碼行數:23,代碼來源:state.py

示例2: ready

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def ready(self):
        # The app is now ready. Include any monkey patches here.

        # Monkey patch CSRF to switch to session based CSRF. Session
        # based CSRF will prevent attacks from apps under the same
        # domain. If you're planning to host your app under it's own
        # domain you can remove session_csrf and use Django's CSRF
        # library. See also
        # https://github.com/mozilla/sugardough/issues/38
        session_csrf.monkeypatch()

        # Connect signals.
        from atmo.jobs.models import SparkJob
        from atmo.jobs.signals import assign_group_perm, remove_group_perm

        post_save.connect(
            assign_group_perm,
            sender=SparkJob,
            dispatch_uid="sparkjob_post_save_assign_perm",
        )
        pre_delete.connect(
            remove_group_perm,
            sender=SparkJob,
            dispatch_uid="sparkjob_pre_delete_remove_perm",
        ) 
開發者ID:mozilla,項目名稱:telemetry-analysis-service,代碼行數:27,代碼來源:apps.py

示例3: _connect

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def _connect(self):
        """
        Connect the signal listing.
        """

        # this is used to capture the current state for the model
        post_init.connect(
            self.post_init_receiver, sender=self.model_cls, dispatch_uid=id(self)
        )

        post_save.connect(
            self.post_save_receiver, sender=self.model_cls, dispatch_uid=id(self)
        )

        post_delete.connect(
            self.post_delete_receiver, sender=self.model_cls, dispatch_uid=id(self)
        ) 
開發者ID:hishnash,項目名稱:djangochannelsrestframework,代碼行數:19,代碼來源:model_observer.py

示例4: _connect

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def _connect(cls):
        """
        Connect signal to current model
        """
        pre_save.connect(
            notify_items_pre_save, sender=cls,
            dispatch_uid='knocker_pre_save_{0}'.format(cls.__name__)
        )
        post_save.connect(
            notify_items_post_save, sender=cls,
            dispatch_uid='knocker_post_save_{0}'.format(cls.__name__)
        )
        pre_delete.connect(
            notify_items_pre_delete, sender=cls,
            dispatch_uid='knocker_pre_delete_{0}'.format(cls.__name__)
        )
        post_delete.connect(
            notify_items_post_delete, sender=cls,
            dispatch_uid='knocker_post_delete_{0}'.format(cls.__name__)
        ) 
開發者ID:nephila,項目名稱:django-knocker,代碼行數:22,代碼來源:mixins.py

示例5: register

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def register(self, model, index_cls=AlgoliaIndex, auto_indexing=None):
        """
        Registers the given model with Algolia engine.

        If the given model is already registered with Algolia engine, a
        RegistrationError will be raised.
        """
        # Check for existing registration.
        if self.is_registered(model):
            raise RegistrationError(
                '{} is already registered with Algolia engine'.format(model))

        # Perform the registration.
        if not issubclass(index_cls, AlgoliaIndex):
            raise RegistrationError(
                '{} should be a subclass of AlgoliaIndex'.format(index_cls))
        index_obj = index_cls(model, self.client, self.__settings)
        self.__registered_models[model] = index_obj

        if (isinstance(auto_indexing, bool) and
                auto_indexing) or self.__auto_indexing:
            # Connect to the signalling framework.
            post_save.connect(self.__post_save_receiver, model)
            pre_delete.connect(self.__pre_delete_receiver, model)
            logger.info('REGISTER %s', model) 
開發者ID:algolia,項目名稱:algoliasearch-django,代碼行數:27,代碼來源:registration.py

示例6: ready

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def ready(self):
        """
        connects the ``config_modified`` signal
        to the ``update_config`` celery task
        which will be executed in the background
        """
        config_modified.connect(
            self.config_modified_receiver, dispatch_uid='connection.update_config'
        )
        Config = load_model('config', 'Config')
        Credentials = load_model('connection', 'Credentials')
        post_save.connect(
            Credentials.auto_add_credentials_to_device,
            sender=Config,
            dispatch_uid='connection.auto_add_credentials',
        ) 
開發者ID:openwisp,項目名稱:openwisp-controller,代碼行數:18,代碼來源:apps.py

示例7: setup_dynmodel_signals

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def setup_dynmodel_signals():
    """
    Attach signals to our dynamically generated models. Here, we
    only attach dynamically-generated signals to non-CSV backed
    models.
    """
    logger.debug("Setting up dynamic model signals...")
    models.DynamicModel._POST_SAVE_SIGNALS.append(build_and_link_metadata_fk)
    for dynmodel in models.DynamicModel.objects.all():
        if dynmodel.get_attr("type") != MODEL_TYPES.CSV:
            logger.debug("Skipping non-CSV model for signal: %s" % dynmodel)
            continue
        Model = getattr(models, dynmodel.name)
        logger.debug("Attaching post-save signal to dynmodel: %s model: %s" % (
            dynmodel, Model
        ))
        post_save.connect(attach_blank_meta_to_record, sender=Model) 
開發者ID:propublica,項目名稱:django-collaborative,代碼行數:19,代碼來源:signals.py

示例8: test_update_fields_signals

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def test_update_fields_signals(self):
        p = Person.objects.create(name='Sara', gender='F')
        pre_save_data = []

        def pre_save_receiver(**kwargs):
            pre_save_data.append(kwargs['update_fields'])
        pre_save.connect(pre_save_receiver)
        post_save_data = []

        def post_save_receiver(**kwargs):
            post_save_data.append(kwargs['update_fields'])
        post_save.connect(post_save_receiver)
        p.save(update_fields=['name'])
        self.assertEqual(len(pre_save_data), 1)
        self.assertEqual(len(pre_save_data[0]), 1)
        self.assertIn('name', pre_save_data[0])
        self.assertEqual(len(post_save_data), 1)
        self.assertEqual(len(post_save_data[0]), 1)
        self.assertIn('name', post_save_data[0])

        pre_save.disconnect(pre_save_receiver)
        post_save.disconnect(post_save_receiver) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:24,代碼來源:tests.py

示例9: test_empty_update_fields

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def test_empty_update_fields(self):
        s = Person.objects.create(name='Sara', gender='F')
        pre_save_data = []

        def pre_save_receiver(**kwargs):
            pre_save_data.append(kwargs['update_fields'])
        pre_save.connect(pre_save_receiver)
        post_save_data = []

        def post_save_receiver(**kwargs):
            post_save_data.append(kwargs['update_fields'])
        post_save.connect(post_save_receiver)
        # Save is skipped.
        with self.assertNumQueries(0):
            s.save(update_fields=[])
        # Signals were skipped, too...
        self.assertEqual(len(pre_save_data), 0)
        self.assertEqual(len(post_save_data), 0)

        pre_save.disconnect(pre_save_receiver)
        post_save.disconnect(post_save_receiver) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:23,代碼來源:tests.py

示例10: create_enterprise_enrollment_receiver

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def create_enterprise_enrollment_receiver(sender, instance, **kwargs):     # pylint: disable=unused-argument
    """
    Watches for post_save signal for creates on the CourseEnrollment table.

    Spin off an async task to generate an EnterpriseCourseEnrollment if appropriate.
    """
    if kwargs.get('created') and instance.user:
        user_id = instance.user.id
        try:
            ecu = EnterpriseCustomerUser.objects.get(user_id=user_id)
        except ObjectDoesNotExist:
            return
        logger.info((
            "User %s is an EnterpriseCustomerUser. "
            "Spinning off task to check if course is within User's "
            "Enterprise's EnterpriseCustomerCatalog."
        ), user_id)

        create_enterprise_enrollment.delay(
            str(instance.course_id),
            ecu.id,
        )


# Don't connect this receiver if we dont have access to CourseEnrollment model 
開發者ID:edx,項目名稱:edx-enterprise,代碼行數:27,代碼來源:signals.py

示例11: test_add_vars

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def test_add_vars(self):
        # add value handler
        def handler(vars_data, **kwarg):
            vars_data.append({
                'name': 'test_var',
                'description': 'Is a test!',
                'value': 'Hello!',
            })

        make_template_vars.connect(handler)

        # test value
        var_data = self.get('test_var')
        self.assertIsNotNone(var_data)
        self.assertEqual(var_data['value'], 'Hello!')
        self.assertEqual(var_data['description'], 'Is a test!')

        # test replace
        content = replace_template_vars('{{ test_var }}')
        self.assertEqual(content, 'Hello!')

        # clean
        self.assertTrue(make_template_vars.disconnect(handler)) 
開發者ID:atexio,項目名稱:mercure,代碼行數:25,代碼來源:signal.py

示例12: test_edit_vars

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def test_edit_vars(self):
        # add value handler
        def handler(vars_data, **kwarg):
            var_data = self._search_name(vars_data, 'email')
            self.assertIsNotNone(var_data)
            var_data['value'] = 'Hello Word!'

        make_template_vars.connect(handler)

        # test value
        var_data = self.get('email')
        self.assertIsNotNone(var_data)
        self.assertEqual(var_data['value'], 'Hello Word!')

        # test replace
        content = replace_template_vars('{{ email }}')
        self.assertEqual(content, 'Hello Word!')

        # clean
        self.assertTrue(make_template_vars.disconnect(handler)) 
開發者ID:atexio,項目名稱:mercure,代碼行數:22,代碼來源:signal.py

示例13: test_delete_vars

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def test_delete_vars(self):
        # add value handler
        def handler(vars_data, **kwarg):
            var_data = self._search_name(vars_data, 'email')
            self.assertIsNotNone(var_data)
            vars_data.remove(var_data)

        make_template_vars.connect(handler)

        # test value
        var_data = self.get('email')
        self.assertIsNone(var_data)

        # test replace
        content = replace_template_vars('{{ email }}')
        self.assertEqual(content, '{{ email }}')

        # clean
        self.assertTrue(make_template_vars.disconnect(handler)) 
開發者ID:atexio,項目名稱:mercure,代碼行數:21,代碼來源:signal.py

示例14: test_add_item

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def test_add_item(self):
        # add value handler
        def handler(urls, **kwarg):
            urls.append({
                'name': 'test',
                'url': 'http://google.fr',
            })

        make_menu.connect(handler)

        # test
        item = self.get('test')
        self.assertIsNotNone(item)
        self.assertEqual(item['url'], 'http://google.fr')

        # clean
        self.assertTrue(make_menu.disconnect(handler)) 
開發者ID:atexio,項目名稱:mercure,代碼行數:19,代碼來源:signal.py

示例15: test_attachment_executed

# 需要導入模塊: from django.db.models.signals import post_save [as 別名]
# 或者: from django.db.models.signals.post_save import connect [as 別名]
def test_attachment_executed(self):
        def handler(instance, **kwarg):
            # get post on landing page event
            if instance.target_tracker.key != TRACKER_ATTACHMENT_EXECUTED:
                # ignore other target event
                return

            self.assertEqual(instance.ip, '127.0.0.1')
            self.assertEqual(instance.user_agent, 'Outlook')
            raise SuccessException()

        post_save.connect(handler, sender=TrackerInfos)

        # call tracker
        self.send_campaign()
        attachment = json.loads(mail.outbox[-1].attachments[0][1].decode())
        tracker_url = attachment['tracker_url']

        # test if handler has call
        with self.assertRaises(SuccessException):
            self.client.defaults['HTTP_USER_AGENT'] = 'Outlook'
            self.client.get(tracker_url)

        # clean
        self.assertTrue(post_save.disconnect(handler, sender=TrackerInfos)) 
開發者ID:atexio,項目名稱:mercure,代碼行數:27,代碼來源:signal.py


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