<commit_before>from __future__ import unicode_literals

from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import transaction

from waldur_core.core.utils import DryRunCommand

User = get_user_model()


class Command(DryRunCommand):
    help_text = 'Append civil number with country code for OpenID users.'

    def handle(self, dry_run, *args, **options):
        conf = settings.WALDUR_AUTH_OPENID
        country_code = conf['COUNTRY_CODE']
        registration_method = conf['NAME']

        with transaction.atomic():
            users = User.objects.filter(registration_method=registration_method)\
                .exclude(civil_number__startswith=country_code)\
                .exclude(civil_number='') \
                .exclude(civil_number=None)
            count = users.count()
            if not dry_run:
                for user in users:
                    user.civil_number = '%s%s' % (country_code, user.civil_number)
                    user.save(update_fields=['civil_number'])

        self.stdout.write(self.style.SUCCESS('Civil numbers have been updated for %s users.' % count))<commit_msg>Print out civil_number before and after [WAL-2172]<commit_after>from __future__ import unicode_literals

from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import transaction

from waldur_core.core.utils import DryRunCommand

User = get_user_model()


class Command(DryRunCommand):
    help_text = 'Append civil number with country code for OpenID users.'

    def handle(self, dry_run, *args, **options):
        conf = settings.WALDUR_AUTH_OPENID
        country_code = conf['COUNTRY_CODE']
        registration_method = conf['NAME']

        with transaction.atomic():
            users = User.objects.filter(registration_method=registration_method)\
                .exclude(civil_number__startswith=country_code)\
                .exclude(civil_number='') \
                .exclude(civil_number=None)
            count = users.count()
            for user in users:
                new_civil_number = '%s%s' % (country_code, user.civil_number)
                self.stdout.write('Username: %s, before: %s, after: %s' % (
                    user.username, user.civil_number, new_civil_number))
                if not dry_run:
                    user.civil_number = new_civil_number
                    user.save(update_fields=['civil_number'])

        self.stdout.write(self.style.SUCCESS('Civil numbers have been updated for %s users.' % count))
{'fraction_non_alphanumeric': 0.09194053208137715, 'fraction_numerical': 0.001564945226917058, 'mean_word_length': 2.695086705202312, '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': '3523642', 'n_tokens_mistral': 743, 'n_tokens_neox': 687, 'n_words': 166}