django-signals

Django: how to execute code ONLY after the first time a M2M relationship is added?

一个人想着一个人 提交于 2019-12-11 19:00:16
问题 I'm trying to get create_reminder_send_message() executed THE FIRST TIME the Reminder object is saved AND the Reminder.users is saved. The code as it is executes every time I update the object... what am I missing? How can I accomplish what I want? class Reminder(models.Model): METHODS = ( ('EM', 'Send Email'), ('TS', 'Create Dashboard Task'), ('ET', 'Both (recommended)') ) info = models.TextField() method = models.CharField(max_length=3, choices=METHODS, db_index=True, help_text='''How

Why does the signal not trigger?

浪尽此生 提交于 2019-12-11 07:15:46
问题 Sitting over a day on it. Really can't understand why this signal is not triggered when a user is activated, no error log, no exception in the admin on activation. Can anybody help? The following code should result in a log message in the apache error.log when a user, right? import logging from django.dispatch import receiver from registration.signals import user_activated @receiver(user_activated) def registered_callback(sender, **kwargs): logger = logging.getLogger("user-activated") logger

Django models, signals and email sending delay

我们两清 提交于 2019-12-11 04:08:03
问题 I have added a signal to my model, which sends email to some email addresses once a model is saved (via models.signals.post_save.connect signal and send_mail for email sending). This idea still makes delay for the users, when they save the model at the site, they have to wait until all those emails are sent and thats when they receive response from the server. Before trying signals, I had tried to wrap the save method of my model, and after super(Foo, self).save(*args, **kwargs) I was sending

django signals: fail silently? any better way of debugging mistakes?

☆樱花仙子☆ 提交于 2019-12-11 03:49:38
问题 It seems that django signals has a "fail silently" paradigm. When I make a small spelling error in my signals function, for example:- def new_users_handler(send, user, response, details, **kwargs): print "new_users_handler function executes" user.is_new = True if user.is_new: if "id" in response: from urllib2 import urlopen, HTTPError from django.template.defaultfilters import slugify from django.core.files.base import ContentFile try: url = None if sender == FacebookBackend: url = "http:/

django signals. how to create a unique dispatch id?

自闭症网瘾萝莉.ら 提交于 2019-12-11 02:39:48
问题 sometimes signals in django are triggered twice. In the docs it says that a good way to create a (unique) dispatch_uid is either the path or name of the module[1] or the id of any hashable object[2]. Today I tried this: import time my_signal.connect(my_function, dispatch_uid=str(time.time())) However I am afraid that in a multiuser environment (like in the case of a web site). This might be broken. What is a good and safe way to create such an id in a multiuser environment? [1] https://code

Use signals in Django 1.9

我与影子孤独终老i 提交于 2019-12-10 10:04:23
问题 In Django 1.8, I was able to do the following with my signals, and all was well: __init__.py: from .signals import * signals.py: @receiver(pre_save, sender=Comment) def process_hashtags(sender, instance, **kwargs): html = [] for word in instance.hashtag_field.value_to_string(instance).split(): if word.startswith('#'): word = render_to_string('hashtags/_link.html', {'hashtag': word.lower()[1:]}) html.append(word) instance.hashtag_enabled_text = ' '.join(html) In Django 1.9, I get this error:

Django pass self to models.SET on_delete

天大地大妈咪最大 提交于 2019-12-08 08:01:55
问题 I want to modify a foreign key value when its deleted from the database. So I looked upon the doc and used on_delete=models.SET(foo) method. https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.SET This is my model definition class OrderLine(models.Model): product = models.ForeignKey(Product, on_delete=models.SET(getDuplicateProduct), null=True) quantity = models.PositiveSmallIntegerField(default=1) finalPricePerUnit = models.PositiveIntegerField() order = models

Django refresh page if change data by other user

隐身守侯 提交于 2019-12-08 02:03:17
问题 I have a test django app. In one page the test show the same question to all users. I'd like that when a user answers correctly, send a signal to other active user's browser to refresh to the next question. I have been learning about signals in django I learning work with them but I don't now how send the "refresh signal" to client browser. I think that it can do with a javascript code that check if a certain value (actual question) change and if change reload the page but I don't know this

Redefinition of AppConfig.ready()

故事扮演 提交于 2019-12-07 09:33:51
问题 Django 1.9. Trying to learn signals. In the documentation for AppConfig.ready() it is said that "Subclasses can override this method to perform initialization tasks such as registering signals." (https://docs.djangoproject.com/en/1.9/ref/applications/#django.apps.AppConfig.ready). some_app/apps.py class SomeAppConfig(AppConfig): name = 'some_app' def ready(self): print("Redefined ready method in some_app") demo_signals/settings.py INSTALLED_APPS = [ ... "some_app.apps.SomeAppConfig", ] python

Django - When should I use signals and when should I override save method?

谁说胖子不能爱 提交于 2019-12-07 03:13:02
问题 Personally I like using signals: from django.db import models from django.db.models.signals import pre_save class MyModel(models.Model): ... def custom_action_before_saving(sender, instance, *args, **kwargs): ... pre_save.connect(custom_action_before_saving, sender=MyModel) But I wonder if there're some times or task when is better override the save method in a model class: from django.db import models class MyModel(models.Model): ... def save(self): ... super(MyModel, self).save() I am