from patch.include import *

import phonenumbers
from tqdm import tqdm


@app_context(commit=True)
def patch():
    ugrp = models.CmfPersonGroup.get(id="CmfPersonGroup:00000000-0000-0000-0000-000000000028")
    ugrp.name = "Все"
    ugrp.code = "Users"
    ugrp.save(only_data=True)

    ugrp = models.CmfPersonGroup.get(id="CmfPersonGroup:00000000-0000-0000-0000-000000000013")
    ugrp.name = "Admins"
    ugrp.code = "Admins"
    ugrp.save(only_data=True)

    myfolders = models.CmfProject.list(filter=['project_type', '=', 'home'])
    # myfolders=models.CmfProject.list(filter=['code', 'LIKE', '%@%'])
    for f in tqdm(myfolders):
        print(f.code)
        f.project_type = 'section'
        f.name = f.code
        f.cmf_owner = "CmfPerson:00000000-0000-0000-0000-000000000001"
        f.save(only_data=True)

    chat = models.CmfChatGroup.get(code='user')
    if chat:
        chat.code = 'Users'
#         chat.save(only_data=True)


if __name__ == "__main__":
    patch()
