Example #1
0
def remove_old_documents():
    output = []
    randomizedDocument_list = RandomizedDocument.objects.filter(active=True).exclude(mopDocument__clearance=Clearance.CLEARANCE_WHITE)
    for randomizedDocument in randomizedDocument_list:
        if randomizedDocument.dueAt and randomizedDocument.dueAt < now():
            randomizedDocument.active = False
            randomizedDocument.save()
            output.append(randomizedDocument.serial)
            
            mopDocumentInstance_list = MopDocumentInstance.objects.filter(randomizedDocument=randomizedDocument).filter(status=MopDocumentInstance.STATUS_ACTIVE)
            for mopDocumentInstance in mopDocumentInstance_list:
                mopDocumentInstance.status = MopDocumentInstance.STATUS_REVOKED
                mopDocumentInstance.save()
                
                mail = Mail()
                mail.mop = mopDocumentInstance.mop
                mail.type = Mail.TYPE_RECEIVED
                mail.processed = True
                mail.unit = mopDocumentInstance.randomizedDocument.unit
                mail.subject = Mail.SUBJECT_REVOKE_DOCUMENT
                mail.bodyType = Mail.BODY_REVOKING_DOCUMENT
                mail.mopDocumentInstance = mopDocumentInstance
                mail.trust = mopDocumentInstance.getTrustFinal()
                mail.save()
                
                mopDocumentInstance.mop.mopTracker.addTrust(mopDocumentInstance.getTrustFinal(), True)
                mopDocumentInstance.mop.mopTracker.save()
                
    return output