from patch.include import *
from tqdm import tqdm


@app_context(commit=True)
def notify_email_create_persons():
    """
    Для тестирования патча: ( cd /opt/eva-app; python3 -m patch.202412261443_notify_email_create_persons )
    Здесь можно работать с моделями через models.CmfTask и т.д.
    Для прогрессбара используйте:
    for task in tqdm(models.CmfTask.list()):
        ...
    """
    print('Запуск патча notify_email_create_persons')

    with cmfutil.disable_acl(), cmfutil.disable_notify():
        for rule in models.CmfProjectNotifySchemeRule.list(fields=['notify_email']):
            if rule.notify_email:
                rule.save(emit=False, notify=False)


if __name__ == "__main__":
    notify_email_create_persons()
