(self, transactions, rebuild_transaction, unarchived_form_id=None)
:param transactions:        The transactions required to rebuild the case
        :param rebuild_transaction: The transaction to add for this rebuild
        :param unarchived_form_id:  If this rebuild was triggered by a form being unarchived then this is
                                    its ID.
:param transactions:        The transactions required to rebuild the case
        :param rebuild_transaction: The transaction to add for this rebuild
        :param unarchived_form_id:  If this rebuild was triggered by a form being unarchived then this is
                                    its ID.
: param transactions : The transactions required to rebuild the case : param rebuild_transaction : The transaction to add for this rebuild : param unarchived_form_id : If this rebuild was triggered by a form being unarchived then this is its ID .
def rebuild_from_transactions(self, transactions, rebuild_transaction, unarchived_form_id=None):
        """
        :param transactions:        The transactions required to rebuild the case
        :param rebuild_transaction: The transaction to add for this rebuild
        :param unarchived_form_id:  If this rebuild was triggered by a form being unarchived then this is
                                    its ID.
        """
        already_deleted = False
        if self.case.is_deleted:
            # we exclude the transaction of the form being unarchived since it would
            # have been revoked prior to the rebuild.
            primary_transactions = [
                tx for tx in transactions
                if not tx.is_case_rebuild and tx.form_id != unarchived_form_id
            ]
            if primary_transactions:
                # already deleted means it was explicitly set to "deleted",
                # as opposed to getting set to that because it has no 'real' transactions
                already_deleted = True

        self._reset_case_state()

        original_indices = {index.identifier: index for index in self.case.indices}
        original_attachments = {attach.name: attach for attach in self.case.get_attachments()}

        real_transactions = []
        for transaction in transactions:
            if transaction.is_form_transaction and transaction.is_relevant:
                self._apply_form_transaction(transaction)
                real_transactions.append(transaction)
                if not transaction.is_saved():
                    self.case.track_create(transaction)

        self._delete_old_related_models(
            original_indices,
            self.case.get_live_tracked_models(CommCareCaseIndexSQL)
        )
        self._delete_old_related_models(
            original_attachments,
            self.case.get_live_tracked_models(CaseAttachmentSQL),
            key="name",
        )

        self.case.deleted = already_deleted or not bool(real_transactions)

        self.case.track_create(rebuild_transaction)
        if not self.case.modified_on:
            self.case.modified_on = rebuild_transaction.server_date
def rebuild_from_transactions ( self , transactions , rebuild_transaction , unarchived_form_id = None ) : already_deleted = False if self . case . is_deleted : # we exclude the transaction of the form being unarchived since it would # have been revoked prior to the rebuild. primary_transactions = [ tx for tx in transactions if not tx . is_case_rebuild and tx . form_id != unarchived_form_id ] if primary_transactions : # already deleted means it was explicitly set to "deleted", # as opposed to getting set to that because it has no 'real' transactions already_deleted = True self . _reset_case_state ( ) original_indices = { index . identifier : index for index in self . case . indices } original_attachments = { attach . name : attach for attach in self . case . get_attachments ( ) } real_transactions = [ ] for transaction in transactions : if transaction . is_form_transaction and transaction . is_relevant : self . _apply_form_transaction ( transaction ) real_transactions . append ( transaction ) if not transaction . is_saved ( ) : self . case . track_create ( transaction ) self . _delete_old_related_models ( original_indices , self . case . get_live_tracked_models ( CommCareCaseIndexSQL ) ) self . _delete_old_related_models ( original_attachments , self . case . get_live_tracked_models ( CaseAttachmentSQL ) , key = "name" , ) self . case . deleted = already_deleted or not bool ( real_transactions ) self . case . track_create ( rebuild_transaction ) if not self . case . modified_on : self . case . modified_on = rebuild_transaction . server_date