<commit_before># -*- coding: utf-8 -*-
"""
Migrate data from the legacy system

Before edX added support for custom registration pages,
we built our own from scratch for CME.
Now that the platform supports customization of the registration form,
we can do away with our custom implementation, after migrating the data.
"""
from __future__ import unicode_literals
import logging

from django.conf import settings
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from django.db import migrations, models, transaction, IntegrityError

from ...models import ExtraInfo
from cme_registration.models import CmeUserProfile
from student.models import UserProfile


log = logging.getLogger(__name__)


class Command(BaseCommand):
    """
    Migrate data from the legacy system
    """
    help = __doc__

    def add_arguments(self, parser):
        parser.add_argument(
            '-i',
            '--insert',
            action='store_true',
            default=False,
            help='Insert new records into the database',
        )

    def handle(self, *args, **kwargs):
        users = User.objects.all()
        for user in users:
            try:
                info_old = CmeUserProfile.objects.get(pk=user.profile.id)
            except (UserProfile.DoesNotExist, CmeUserProfile.DoesNotExist):
                info_old = CmeUserProfile()
            info_new = ExtraInfo()
            info_new.id = user.id
            info_new.user_id = user.id
            info_new.address_1 = info_old.address_1 or ''
            info_new.address_2 = info_old.address_2 or ''
            info_new.affiliation = info_old.affiliation or 'Not affiliated with Stanford Medicine'
            info_new.birth_date = info_old.birth_date or '01/01'
            info_new.city = info_old.city_cme or ''
            info_new.country = info_old.country_cme or ''
            info_new.county_province = info_old.county_province or ''
            info_new.first_name = info_old.first_name or ''
            info_new.last_name = info_old.last_name or ''<commit_msg>Added a log line for users that don't have an entry in CmeUserProfile.<commit_after># -*- coding: utf-8 -*-
"""
Migrate data from the legacy system

Before edX added support for custom registration pages,
we built our own from scratch for CME.
Now that the platform supports customization of the registration form,
we can do away with our custom implementation, after migrating the data.
"""
from __future__ import unicode_literals
import logging

from django.conf import settings
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from django.db import migrations, models, transaction, IntegrityError

from ...models import ExtraInfo
from cme_registration.models import CmeUserProfile
from student.models import UserProfile


log = logging.getLogger(__name__)


class Command(BaseCommand):
    """
    Migrate data from the legacy system
    """
    help = __doc__

    def add_arguments(self, parser):
        parser.add_argument(
            '-i',
            '--insert',
            action='store_true',
            default=False,
            help='Insert new records into the database',
        )

    def handle(self, *args, **kwargs):
        users = User.objects.all()
        for user in users:
            try:
                info_old = CmeUserProfile.objects.get(pk=user.profile.id)
            except (UserProfile.DoesNotExist, CmeUserProfile.DoesNotExist):
                info_old = CmeUserProfile()
                log.info(
                    "CmeUserProfile not found for user_id: %(user_id)s",
                    {
                        'user_id': user.id,
                    }
                )
            info_new = ExtraInfo()
            info_new.id = user.id
            info_new.user_id = user.id
            info_new.address_1 = info_old.address_1 or ''
            info_new.address_2 = info_old.address_2 or ''
            info_new.affiliation = info_old.affiliation or 'Not affiliated with Stanford Medicine'
            info_new.birth_date = info_old.birth_date or '01/01'
            info_new.city = info_old.city_cme or ''
            info_new.country = info_old.country_cme or ''
            info_new.county_province = info_old.county_province or ''
            info_new.first_name = info_old.first_name or ''
            info_new.last_name = info_old.last_name or ''
{'fraction_non_alphanumeric': 0.07908968003605228, 'fraction_numerical': 0.00405588102748986, 'mean_word_length': 2.414615384615385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5741791', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1210, 'n_words': 355}