当前位置: 首页>>代码示例>>Python>>正文


Python pre_save.connect方法代码示例

本文整理汇总了Python中django.db.models.signals.pre_save.connect方法的典型用法代码示例。如果您正苦于以下问题:Python pre_save.connect方法的具体用法?Python pre_save.connect怎么用?Python pre_save.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.signals.pre_save的用法示例。


在下文中一共展示了pre_save.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_request

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def process_request(self, request):
        """
        Gets the current user from the request and prepares and connects a signal receiver with the user already
        attached to it.
        """
        # Initialize thread local storage
        threadlocal.actionslog = {
            'signal_duid': (self.__class__, time.time()),
            'remote_ip': request.META.get('REMOTE_ADDR'),
        }

        # In case of proxy, set 'original' address
        if request.META.get('HTTP_X_FORWARDED_FOR'):
            threadlocal.actionslog['remote_ip'] = request.META.get('HTTP_X_FORWARDED_FOR').split(',')[0]

        # Connect signal for automatic logging
        if hasattr(request, 'user') and hasattr(request.user, 'is_authenticated') and request.user.is_authenticated():
            set_user = curry(self.set_user, request.user)
            pre_save.connect(set_user, sender=LogAction, dispatch_uid=threadlocal.actionslog['signal_duid'], weak=False) 
开发者ID:shtalinberg,项目名称:django-actions-logger,代码行数:21,代码来源:middleware.py

示例2: ready

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def ready(self):
        from .signals.datasample.pre_save import data_sample_pre_save

        from .signals.algo.post_delete import algo_post_delete
        from .signals.objective.post_delete import objective_post_delete
        from .signals.datasample.post_delete import data_sample_post_delete
        from .signals.datamanager.post_delete import datamanager_post_delete
        from .signals.model.post_delete import model_post_delete

        # registering signals with the model's string label
        from substrapp.models import Algo, Objective, DataSample, DataManager, Model

        pre_save.connect(data_sample_pre_save, sender=DataSample)

        post_delete.connect(algo_post_delete, sender=Algo)
        post_delete.connect(objective_post_delete, sender=Objective)
        post_delete.connect(data_sample_post_delete, sender=DataSample)
        post_delete.connect(datamanager_post_delete, sender=DataManager)
        post_delete.connect(model_post_delete, sender=Model) 
开发者ID:SubstraFoundation,项目名称:substra-backend,代码行数:21,代码来源:apps.py

示例3: _connect

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_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

示例4: test_update_fields_signals

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_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

示例5: test_empty_update_fields

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_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

示例6: ready

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def ready(self):
        from .models import clear_usersettings_cache
        from .shortcuts import get_usersettings_model

        usersettings_model = get_usersettings_model()
        pre_save.connect(clear_usersettings_cache, sender=usersettings_model)
        pre_delete.connect(clear_usersettings_cache, sender=usersettings_model) 
开发者ID:mishbahr,项目名称:django-usersettings2,代码行数:9,代码来源:apps.py

示例7: register_pre_save_on_AUTH_USER_MODER_change

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def register_pre_save_on_AUTH_USER_MODER_change(sender, setting, value, enter, **kwargs):
    if setting == "AUTH_USER_MODEL" and value != USER_MODEL:
        if enter:
            pre_save.connect(useraudit.password_expiry.user_pre_save, sender=value)
        else:
            pre_save.disconnect(useraudit.password_expiry.user_pre_save, sender=value) 
开发者ID:muccg,项目名称:django-useraudit,代码行数:8,代码来源:tests.py

示例8: test_signal

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def test_signal(self):
        def handler(sender, user=None, **kwargs):
            self.handler_called = True
            self.assertEquals(sender, type(self.user))
            self.assertEquals(user, self.user)
        login_failure_limit_reached.connect(handler)

        self.handler_called = False

        _ = authenticate(username=self.username, password="INCORRECT")
        _ = authenticate(username=self.username, password="INCORRECT")

        login_failure_limit_reached.disconnect(handler)

        self.assertTrue(self.handler_called) 
开发者ID:muccg,项目名称:django-useraudit,代码行数:17,代码来源:tests.py

示例9: register

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def register():
    pre_save.connect(check_status_change, sender=Segment) 
开发者ID:wagtail,项目名称:wagtail-personalisation,代码行数:4,代码来源:receivers.py

示例10: ready

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def ready(self):
        from node.models import IncomingNode
        from node.signals.node.pre_save import node_pre_save

        pre_save.connect(node_pre_save, sender=IncomingNode) 
开发者ID:SubstraFoundation,项目名称:substra-backend,代码行数:7,代码来源:apps.py

示例11: pre_post_save_wrapper

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def pre_post_save_wrapper(self):
        self.pre_save_called = False
        self.post_save_called = False

        self.bar

        def pre_save_handler(sender, instance, **kwargs):
            # Assert that a pre_save handler gets the proper information on which fields have changed
            # (hence the translations have not yet been saved to the db).

            self.pre_save_called = True

            field_fr = instance._linguist_translations["title"].get("fr", None)
            field_en = instance._linguist_translations["title"].get("en", None)

            assert field_fr.has_changed
            assert not field_en.has_changed

        pre_save.connect(pre_save_handler, sender=BarModel)

        def post_save_handler(sender, instance, **kwargs):
            # Assert that a post_save handler that refreshes the model gets the saved translations
            # (hence the translations have been saved to the db).

            self.post_save_called = True

            title_fr = instance.title_fr
            title_en = instance.title_en

            instance = BarModel.objects.get(pk=instance.pk)

            assert instance.title_fr == title_fr
            assert instance.title_en == title_en

        post_save.connect(post_save_handler, sender=BarModel)

        yield

        pre_save.disconnect(pre_save_handler, sender=BarModel)
        post_save.disconnect(post_save_handler, sender=BarModel) 
开发者ID:ulule,项目名称:django-linguist,代码行数:42,代码来源:test_signals.py

示例12: register_signal_handlers

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def register_signal_handlers():
    Image = get_image_model()
    Rendition = Image.get_rendition_model()

    pre_save.connect(pre_save_image_feature_detection, sender=Image)
    post_delete.connect(post_delete_file_cleanup, sender=Image)
    post_delete.connect(post_delete_file_cleanup, sender=Rendition)
    post_delete.connect(post_delete_purge_rendition_cache, sender=Rendition) 
开发者ID:wagtail,项目名称:wagtail,代码行数:10,代码来源:signal_handlers.py

示例13: __init__

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def __init__(self):
        post_save.connect(self.user_model_updated, sender=DiscordUser)

        post_delete.connect(self.mapping_model_deleted, sender=RoleMapping)
        pre_save.connect(self.mapping_model_updated, sender=RoleMapping)

        pre_social_login.connect(self.social_account_updated)
        social_account_added.connect(self.social_account_updated)
        social_account_updated.connect(self.social_account_updated)
        social_account_removed.connect(self.social_account_removed)

        user_logged_in.connect(self.user_logged_in) 
开发者ID:python-discord,项目名称:site,代码行数:14,代码来源:signals.py

示例14: connect_app_models_pre_save_signal

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def connect_app_models_pre_save_signal(app, models=None):
    for model in models or app.get_models():
        pre_save.connect(validate_model, sender=model, dispatch_uid=str(model)) 
开发者ID:product-definition-center,项目名称:product-definition-center,代码行数:5,代码来源:utils.py

示例15: ready

# 需要导入模块: from django.db.models.signals import pre_save [as 别名]
# 或者: from django.db.models.signals.pre_save import connect [as 别名]
def ready(self):
        from django.db.models.signals import post_save, pre_save, pre_delete
        from .models import TestExecution, TestRun
        from tcms import signals

        post_save.connect(signals.handle_emails_post_run_save, sender=TestRun)
        pre_save.connect(signals.pre_save_clean, sender=TestRun)
        pre_delete.connect(signals.handle_comments_pre_delete, TestExecution) 
开发者ID:kiwitcms,项目名称:Kiwi,代码行数:10,代码来源:apps.py


注:本文中的django.db.models.signals.pre_save.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。