Exemple #1
0
 def get_context_data(self, **kwargs):
     o =  self.object
     task_id = get_uuid()
     self.object.task_id = task_id
     self.object.save()
     join_files_task.apply_async([o], task_id=task_id)
     ctx = super(UserTaskRunView,self).get_context_data(**kwargs)
Exemple #2
0
from django.core.signals import request_finished
from django.dispatch import receiver

# from django.core.signals import request_finished
from django.db.models.signals import post_save, post_delete
from annotator.tasks import annotate_file


@receiver(post_save, sender=UserFile, dispatch_uid="update_annotation")
def update_annotation(sender, **kwargs):
    obj = kwargs["instance"]
    try:
        annotation = UserFileAnnotation.objects.get(userfile=obj)
    except UserFileAnnotation.DoesNotExist, e:
        annotation = UserFileAnnotation(userfile=obj)

    task_id = get_uuid()
    annotation.pending = True
    annotation.content_type = None
    annotation.task_id = task_id
    annotation.save()

    # run celery task
    annotate_file.apply_async((obj, annotation), task_id=task_id)


@receiver(post_delete, sender=UserFile)
def mymodel_delete(sender, instance, **kwargs):
    # Pass false so FileField doesn't save the model.
    instance.data_file.delete(False)