Skip to content

Commit

Permalink
source for email/name: migrate from AMS to RHSSO
Browse files Browse the repository at this point in the history
  • Loading branch information
goneri committed Aug 29, 2024
1 parent 57e421e commit 631ccba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
28 changes: 28 additions & 0 deletions ansible_ai_connect/users/migrations/0014_auto_20240829_1738.py
Original file line number Diff line number Diff line change
@@ -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),
]
7 changes: 3 additions & 4 deletions ansible_ai_connect/users/reports/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down

0 comments on commit 631ccba

Please sign in to comment.