diff --git a/ansible_ai_connect/users/migrations/0014_auto_20240829_1738.py b/ansible_ai_connect/users/migrations/0014_auto_20240829_1738.py new file mode 100644 index 000000000..b80096e8b --- /dev/null +++ b/ansible_ai_connect/users/migrations/0014_auto_20240829_1738.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.15 on 2024-08-29 17:38 + +from django.db import migrations + + +def email_names_from_db(apps, schema_editor): + User = apps.get_model("users", "User") + for user in User.objects.all(): + if user.first_name: + continue + ams = user.get("ams") + if not ams: + continue + user.first_name = ams.get("first_name") + user.familty_name = ams.get("last_name") + user.email = ams.get("email") + user.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("users", "0013_user_email_verified_user_family_name_user_given_name_and_more"), + ] + + operations = [ + migrations.RunPython(email_names_from_db), + ] diff --git a/ansible_ai_connect/users/reports/generators.py b/ansible_ai_connect/users/reports/generators.py index 1af24719e..166070272 100644 --- a/ansible_ai_connect/users/reports/generators.py +++ b/ansible_ai_connect/users/reports/generators.py @@ -105,13 +105,12 @@ def generate( writer = csv.writer(output) writer.writerow(["First name", "Last name", "Email", "Plan name", "Trial started"]) for user in users: - ams = user.get("ams") for plan in user.get("userplan_set"): if plan.get("accept_marketing"): row_data = [ - ams.get("first_name"), - ams.get("last_name"), - ams.get("email"), + user.first_name, + user.familty_name, + user.email, plan.get("plan").get("name"), plan.get("created_at"), ]