2023-08-26 14:10:10 +03:00
|
|
|
from django.db.models.signals import post_save, pre_save
|
2023-08-26 09:36:47 +03:00
|
|
|
from django.dispatch import receiver
|
|
|
|
|
2023-08-26 10:44:23 +03:00
|
|
|
from pitch_deck_generator.decks.models import PitchDeck, QuestionAnswer
|
|
|
|
from pitch_deck_generator.decks.tasks import (
|
|
|
|
generate_numeric_values,
|
2023-08-26 14:10:10 +03:00
|
|
|
qenerate_answer_qr,
|
2023-08-26 10:44:23 +03:00
|
|
|
run_pitch_deck_calculation,
|
2023-08-26 14:10:10 +03:00
|
|
|
save_answer_to_deck,
|
2023-08-26 10:44:23 +03:00
|
|
|
)
|
2023-08-26 09:36:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_save, sender=PitchDeck)
|
2023-08-26 14:10:10 +03:00
|
|
|
def pitch_deck_create(sender, instance: PitchDeck, created, **kwargs):
|
2023-08-26 09:36:47 +03:00
|
|
|
if created:
|
2023-08-26 14:10:10 +03:00
|
|
|
run_pitch_deck_calculation.apply_async(kwargs={"pk": instance.pk}, delay=1)
|
2023-08-26 10:44:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_save, sender=QuestionAnswer)
|
2023-08-26 14:10:10 +03:00
|
|
|
def question_answer_create(sender, instance: QuestionAnswer, created, **kwargs):
|
2023-08-26 10:44:23 +03:00
|
|
|
if created:
|
|
|
|
if instance.question.inner_tag == "category":
|
2023-08-26 14:10:10 +03:00
|
|
|
generate_numeric_values.apply_async(
|
|
|
|
kwargs={"pk": instance.deck.pk}, countdown=1
|
|
|
|
)
|
|
|
|
elif instance.question.inner_tag in ["finance_model"]:
|
|
|
|
qenerate_answer_qr.apply_async(kwargs={"pk": instance.pk}, countdown=1)
|
|
|
|
save_answer_to_deck.apply_async(kwargs={"pk": instance.pk}, countdown=5)
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(pre_save, sender=QuestionAnswer)
|
2023-08-26 17:16:07 +03:00
|
|
|
def question_answer_update(sender, instance: QuestionAnswer, **kwargs):
|
2023-08-26 14:10:10 +03:00
|
|
|
if instance.id:
|
|
|
|
if instance.question.inner_tag == "category":
|
|
|
|
generate_numeric_values.apply_async(
|
|
|
|
kwargs={"pk": instance.deck.pk}, countdown=1
|
|
|
|
)
|
|
|
|
elif instance.question.inner_tag in ["finance_model"]:
|
|
|
|
qenerate_answer_qr.apply_async(kwargs={"pk": instance.pk}, countdown=1)
|
|
|
|
save_answer_to_deck.apply_async(kwargs={"pk": instance.pk}, countdown=5)
|