from patch.include import *
from tqdm import tqdm


@app_context(commit=True)
def loop_emptylists():
    """
    Для тестирования патча: ( cd /opt/eva-app; python3 -m patch.202408222147_loop_emptylists )
    Здесь можно работать с моделями через models.CmfTask и т.д.
    Для прогрессбара используйте:
    for task in tqdm(models.CmfTask.list()):
        ...
    """
    print('Запуск патча loop_emptylists')
    with cmfutil.disable_acl(), cmfutil.disable_notify():
        for proj in models.CmfProject.list():
            wl = models.CmfEmailList.get(parent=proj, type='white')
            if not wl:
                wl = models.CmfEmailList(parent=proj, type='white')
                wl.save(only_data=True, emit=False, notify=False)
            bl = models.CmfEmailList.get(parent=proj, type='black')
            if not bl:
                bl = models.CmfEmailList(parent=proj, type='black')
                bl.save(only_data=True, emit=False, notify=False)


if __name__ == "__main__":
    loop_emptylists()
