from patch.include import *
from cmf.include import *
from tqdm import tqdm
import os


@app_context(commit=True)
def patch():
    with cmfutil.disable_acl(), cmfutil.disable_notify():
        while True:
            limit = 500
            docs = models.CmfDocument.list(filter=['need_approve', '==', 'True'], slice=[0, limit])
            if not docs:
                break
            for doc in tqdm(docs):
                doc.need_approve = False
                doc.save(only_data=True)
            models.CmfDocument.dp.commit()


if __name__ == "__main__":
    patch()
