Commit 83508b52 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Add task to publish messages

parent 4b5475df
from django.db.models.signals import pre_save, post_save
from django.dispatch import receiver
from .models import Lesson, Unit
from .tasks import publish_lesson, publish_unit
from .models import Lesson, Unit, ProfessorMessage
from .tasks import publish_lesson, publish_unit, publish_message
from .scheduling.models import ScheduledTask
from celery.result import AsyncResult
......@@ -82,3 +82,8 @@ def post_lesson_created_or_updated(sender, instance: Lesson, **kwargs):
@receiver(post_save, sender=Unit)
def post_unit_created_or_updated(sender, instance: Lesson, **kwargs):
create_first_task(instance)
@receiver(post_save, sender=ProfessorMessage)
def post_professor_message_created(sender, instance: ProfessorMessage, **kwargs):
publish_message.apply_async(args=[instance.id], eta=instance.release_date)
from .models import Lesson, Unit
#fro celery.decorators import task
from celery import Celery
app = Celery()
@app.task()
def publish_lesson(object_id):
lesson = Lesson.objects.filter(id=object_id)
......@@ -19,3 +19,12 @@ def publish_unit(object_id):
unit = unit.first()
unit.status = 'published'
unit.save()
@app.task()
def publish_message(object_id):
message = ProfessorMessage.objects.filter(id=object_id)
if message.exists():
message = lesson.first()
message.status = 'published'
message.save()
message.send()
......@@ -203,7 +203,7 @@ class ProfessorMessageViewSet(viewsets.ModelViewSet):
| Q(groups__in=self.request.user.groups.all())
| Q(professor=self.request.user)
)
queryset = queryset.filter(query).order_by('-id').distinct()
queryset = queryset.filter(query, status='published').order_by('-id').distinct()
classroom = self.request.query_params.get('classroom', None)
if classroom:
......
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