Commit f1141e45 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Create task to publish unit/lessons

parent dbbe84e0
from django.db.models.signals import pre_save
from django.dispatch import receiver
from .models import Lesson, Unit
from .tasks import publish_lesson, publish_unit
@receiver(pre_save, sender=Lesson)
def lesson_created_or_updated(sender, instance: Lesson, **kwargs):
previous_lesson = Lesson.objects.get(
if (not or instance.release_date != previous_lesson.release_date) and instance.release_date:
publish_lesson.apply_async(args=[], eta=instance.release_date)
@receiver(pre_save, sender=Unit)
def unit_created_or_updated(sender, instance: Unit, **kwargs):
previous_unit = Unit.objects.get(
publish_unit.apply_async(args=[], eta=instance.release_date)
from .models import Lesson, Unit
from celery.decorators import task
def publish_lesson(object_id):
lesson = Lesson.objects.filter(id=object_id)
if lesson.exists():
lesson = lesson.first()
lesson.status = 'published'
def publish_unit(object_id):
unit = Unit.objects.filter(id=object_id)
if unit.exists():
unit = unit.first()
unit.status = 'published'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment