本文整理汇总了Python中django.db.models.signals.post_save.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python post_save.disconnect方法的具体用法?Python post_save.disconnect怎么用?Python post_save.disconnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.signals.post_save
的用法示例。
在下文中一共展示了post_save.disconnect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _disconnect
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [as 别名]
def _disconnect(cls):
"""
Disconnect signal from current model
"""
pre_save.disconnect(
notify_items_pre_save, sender=cls,
dispatch_uid='knocker_pre_save_{0}'.format(cls.__name__)
)
post_save.disconnect(
notify_items_post_save, sender=cls,
dispatch_uid='knocker_post_save_{0}'.format(cls.__name__)
)
pre_delete.disconnect(
notify_items_pre_delete, sender=cls,
dispatch_uid='knocker_pre_delete_{0}'.format(cls.__name__)
)
post_delete.disconnect(
notify_items_post_delete, sender=cls,
dispatch_uid='knocker_post_delete_{0}'.format(cls.__name__)
)
示例2: unregister
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [as 别名]
def unregister(self, model):
"""
Unregisters the given model with Algolia engine.
If the given model is not registered with Algolia engine, a
RegistrationError will be raised.
"""
if not self.is_registered(model):
raise RegistrationError(
'{} is not registered with Algolia engine'.format(model))
# Perform the unregistration.
del self.__registered_models[model]
# Disconnect from the signalling framework.
post_save.disconnect(self.__post_save_receiver, model)
pre_delete.disconnect(self.__pre_delete_receiver, model)
logger.info('UNREGISTER %s', model)
示例3: test_update_fields_signals
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [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)
示例4: test_empty_update_fields
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [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)
示例5: test_add_vars
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [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))
示例6: test_edit_vars
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [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))
示例7: test_delete_vars
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [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))
示例8: test_add_item
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [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))
示例9: test_attachment_executed
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [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))
示例10: test_email_open
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [as 别名]
def test_email_open(self):
def handler(instance, **kwarg):
# get email open event
if instance.target_tracker.key != TRACKER_EMAIL_OPEN:
# 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()
mail_html = mail.outbox[-1].alternatives[0][0]
tracker_url = mail_html.split('src="')[-1].split('"')[0]
# 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))
示例11: test_edit_campaign_report_item
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [as 别名]
def test_edit_campaign_report_item(self):
def handler(context, **kwarg):
context['tabs_layout']['Test'] = context['tabs_layout']. \
pop('Other')
make_campaign_report.connect(handler)
# test
content = self.get()
self.assertIn('<a href="#test" aria-controls="test" role="tab" '
'data-toggle="tab">Test</a>', content)
self.assertIn('id="test"', content)
self.assertNotIn('<a href="#other" aria-controls="other" '
'role="tab" data-toggle="tab">Other</a>', content)
self.assertNotIn('id="other"', content)
# clean
self.assertTrue(make_campaign_report.disconnect(handler))
示例12: setUpClass
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [as 别名]
def setUpClass(cls):
"""Set up each test class."""
super().setUpClass()
post_save.disconnect(storage_callback, sender=Sources)
cls.customer_data = cls._create_customer_data()
cls.user_data = cls._create_user_data()
cls.request_context = cls._create_request_context(cls.customer_data, cls.user_data)
cls.schema_name = cls.customer_data.get("schema_name")
cls.tenant = Tenant.objects.get_or_create(schema_name=cls.schema_name)[0]
cls.tenant.save()
cls.headers = cls.request_context["request"].META
cls.provider_uuid = UUID("00000000-0000-0000-0000-000000000001")
cls.factory = RequestFactory()
示例13: setUpClass
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [as 别名]
def setUpClass(cls):
"""Set up the test class."""
super().setUpClass()
post_save.disconnect(storage_callback, sender=Sources)
account = "12345"
IdentityHeaderMiddleware.create_customer(account)
示例14: setUp
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [as 别名]
def setUp(self):
"""Test case setup."""
super().setUp()
post_save.disconnect(storage_callback, sender=Sources)
self.name = "Test Source"
self.application_type = 2
self.source_id = 1
self.authentication = "testauth"
示例15: set_api
# 需要导入模块: from django.db.models.signals import post_save [as 别名]
# 或者: from django.db.models.signals.post_save import disconnect [as 别名]
def set_api(sender, instance, **kwargs):
# Always reset the _bot instance after save, in case the token changes.
instance._bot = BotAPI(instance.token)
# set webhook
url = None
cert = None
if instance.enabled:
webhook = reverse('telegrambot:webhook', kwargs={'token': instance.token})
from django.contrib.sites.models import Site
current_site = Site.objects.get_current()
if instance.https_port is None:
url = 'https://' + current_site.domain + webhook
else:
url = 'https://' + current_site.domain + ':' + str(instance.https_port) + webhook
if instance.ssl_certificate:
instance.ssl_certificate.open()
cert = instance.ssl_certificate
instance._bot.setWebhook(webhook_url=url,
certificate=cert)
logger.info("Success: Webhook url %s for bot %s set" % (url, str(instance)))
# complete Bot instance with api data
if not instance.user_api:
bot_api = instance._bot.getMe()
botdict = bot_api.to_dict()
modelfields = [f.name for f in User._meta.get_fields()]
params = {k: botdict[k] for k in botdict.keys() if k in modelfields}
user_api, _ = User.objects.get_or_create(**params)
instance.user_api = user_api
# Prevent signal recursion, and save.
post_save.disconnect(set_api, sender=sender)
instance.save()
post_save.connect(set_api, sender=sender)
logger.info("Success: Bot api info for bot %s set" % str(instance))