def on_create_dbaction(sender, instance, created, **kwargs): from core.tasks import SendEmailTask from dbapp.tasks import EmailMsg email_msg = EmailMsg(instance) # print email_msg.get_msg_html() # print email_msg.get_msg_text() # print email_msg.get_subject_text() if created: DbActionRes(dbaction=instance).save() admins = _user.objects.filter(is_superuser=True) for admin in admins: SendEmailTask().delay(subject=email_msg.get_subject_text(), message=email_msg.get_msg_text(), message_html=email_msg.get_msg_html(), recipient=admin.email) if not created and int(instance.execute_status) == 0: admins = _user.objects.filter(is_superuser=True) for admin in admins: SendEmailTask().delay(subject=email_msg.get_subject_text(), message=email_msg.get_msg_text(), message_html=email_msg.get_msg_html(), recipient=admin.email) if int(instance.execute_status) == 2: from .tasks import execute_dml sqlstring = instance.sql host = instance.db.dbhost user = instance.db.dbuser password = instance.db.dbpass port = instance.db.dbport database = instance.db.dbname execute_dml.delay( user=user, password=password, database=database, host=host, port=port, sqlstring=sqlstring, id=instance.dbactionres.id, autocommit=True, ) # SendEmailTask().apply_async(kwargs=dict(subject=email_msg.get_subject_text(), # message=email_msg.get_msg_text(), # message_html=email_msg.get_msg_html(), # recipient=instance.user.email # ), # countdown=10) if int(instance.execute_status) == 1: SendEmailTask().delay(subject=email_msg.get_subject_text(), message=email_msg.get_msg_text(), message_html=email_msg.get_msg_html(), recipient=instance.user.email)
def on_save_dbactionres(sender, instance, created, **kwargs): if not created and instance.execute_result: from core.tasks import SendEmailTask from dbapp.tasks import EmailMsg print instance.dbaction.execute_status instance_copy = copy.deepcopy(instance) instance_copy.execute_status = str(instance.dbaction.execute_status) instance_copy.datetime = instance.dbaction.datetime instance_copy.sql = instance.dbaction.sql instance_copy.user = instance.dbaction.user email_msg = EmailMsg(instance_copy) SendEmailTask().delay(subject=email_msg.get_subject_text(), message=email_msg.get_msg_text(), message_html=email_msg.get_msg_html(), recipient=instance_copy.user.email, )