Esempio n. 1
0
    def rollback(task, project_id, cluster_ids, new_project_id):

        task.log_error('Rollback Reassigning Document Cluster documents.')
        log = CeleryTaskLogger(task)

        documents = Document.objects.filter(documentcluster__pk__in=cluster_ids)

        for document in documents:
            signals.document_deleted.send(task.__name__, user=None, document=document)

        documents.update(project_id=project_id, document_type=DocumentType.generic())

        for document in documents:
            signals.document_changed.send(task.__name__, log=log, document=document)

        p_cl = ProjectClustering.objects.get(document_clusters__pk=cluster_ids[0])
        reassignings = p_cl.metadata.get('reassigning', [])
        reassigning = {
            'date': now().isoformat(),
            'new_project_id': new_project_id,
            'cluster_ids': cluster_ids,
            'status': FAILURE,
        }
        reassignings.append(reassigning)
        p_cl.metadata['reassigning'] = reassignings
        p_cl.save()
Esempio n. 2
0
    def rollback(task, project_clustering_id, project_id, new_project_id, reassign_cluster_ids):
        """
        Undo reassigning, update ProjectClustering.metadata
        """
        task.log_error('Rollback Reassigning Document Cluster documents.')
        log = CeleryTaskLogger(task)

        p_cl = ProjectClustering.objects.get(id=project_clustering_id)

        # get reassigned documents queryset
        documents = Document.objects.filter(documentcluster__pk__in=reassign_cluster_ids)

        # update rawdb cache for target doc type
        for document in documents:
            signals.document_deleted.send(task.__name__, user=None, document=document)

        # get back Doc Type to Generic Doc Type
        documents.update(project_id=project_id, document_type=DocumentType.generic())

        # update rawdb cache forGeneric Doc Type
        for document in documents:
            signals.document_changed.send(task.__name__, log=log, document=document)

        # update info about reassignings in metadata
        reassignings = p_cl.metadata.get('reassigning', [])
        reassigning = {
            'date': now().isoformat(),
            'new_project_id': new_project_id,
            'cluster_ids': reassign_cluster_ids,
            'status': FAILURE,
        }
        reassignings.append(reassigning)
        p_cl.metadata['reassigning'] = reassignings
        p_cl.save()
Esempio n. 3
0
 def save(self, **kwargs):
     if not self.type:
         self.type = DocumentType.generic()
     old_instance = Project.objects.filter(pk=self.pk).first()
     res = super().save(**kwargs)
     self._fire_saved()
     with transaction.atomic():
         transaction.on_commit(lambda: self._fire_saved(old_instance))
     return res
 def save(self, **kwargs):
     if not self.type:
         self.type = DocumentType.generic()
     return super().save(**kwargs)