当前位置: 首页>>代码示例>>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;未经允许,请勿转载。