<commit_before>from django.core.management.base import BaseCommand, CommandError
from django.contrib.sites.models import Site


class Command(BaseCommand):
    """
    Disable a custom domain

    Also requires running `disable_custom_domain` on AMC
    """

    def add_arguments(self, parser):
        parser.add_argument(
            'domain',
            help='The custom domain disabled.',
            type=str,
        )

    def handle(self, *args, **options):
        domain = options['domain']
        try:
            # find the site that matches the custom domain to disable
            s = Site.objects.get(domain=domain)

            # update it's corresponding Site
            ad = s.alternative_domain
            s.domain = ad.domain
            s.save()<commit_msg>atomic transaction for disable_custom_domain command<commit_after>from django.core.management.base import BaseCommand, CommandError
from django.contrib.sites.models import Site
from django.db import transaction


class Command(BaseCommand):
    """
    Disable a custom domain

    Also requires running `disable_custom_domain` on AMC
    """

    def add_arguments(self, parser):
        parser.add_argument(
            'domain',
            help='The custom domain disabled.',
            type=str,
        )

    @transaction.atomic
    def handle(self, *args, **options):
        domain = options['domain']
        try:
            # find the site that matches the custom domain to disable
            s = Site.objects.get(domain=domain)

            # update it's corresponding Site
            ad = s.alternative_domain
            s.domain = ad.domain
            s.save()
{'fraction_non_alphanumeric': 0.08478653036680697, 'fraction_numerical': 0.0, 'mean_word_length': 2.212355212355212, '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': '537860', 'n_tokens_mistral': 428, 'n_tokens_neox': 413, 'n_words': 126}