<commit_before>import re

from django.core.management.base import NoArgsCommand, CommandError

from django.template.defaultfilters import slugify

from optparse import make_option

from core.models import PlaceKind, Place

class Command(NoArgsCommand):
    help = 'Standardize the form of ward names with regard to / and - separators'

    option_list = NoArgsCommand.option_list + (
        make_option('--commit', action='store_true', dest='commit', help='Actually update the database'),
        )

    def handle_noargs(self, **options):

        for ward in Place.objects.filter(kind=PlaceKind.objects.get(slug='ward')):
            # print "ward is:", ward
            new_version = re.sub(r'(\w) *([/-]) *(\w)', '\\1 \\2 \\3', ward.name)
            if new_version != ward.name:
                if options['commit']:
                    print "changing:", ward.name, "to", new_version
                    ward.name = new_version
                    ward.slug = 'ward-' + slugify(ward.name)
                    ward.save()
                else:
                    print "would change:", ward.name, "to", new_version, "if --commit were specified"
<commit_msg>Update ward names even if just the slug would have changed<commit_after>import re

from django.core.management.base import NoArgsCommand, CommandError

from django.template.defaultfilters import slugify

from optparse import make_option

from core.models import PlaceKind, Place

def slugify_place_name(place_name):
    return 'ward-' + slugify(place_name)

class Command(NoArgsCommand):
    help = 'Standardize the form of ward names with regard to / and - separators'

    option_list = NoArgsCommand.option_list + (
        make_option('--commit', action='store_true', dest='commit', help='Actually update the database'),
        )

    def handle_noargs(self, **options):

        for ward in Place.objects.filter(kind=PlaceKind.objects.get(slug='ward')):
            # print "ward is:", ward
            new_version = re.sub(r'(\w) *([/-]) *(\w)', '\\1 \\2 \\3', ward.name)
            new_version_slug = slugify_place_name(new_version)
            if (new_version != ward.name) or (new_version_slug != ward.slug):
                if options['commit']:
                    print "changing:", ward.name, "to", new_version
                    ward.name = new_version
                    ward.slug = new_version_slug
                    ward.save()
                else:
                    print "would change:", ward.name, "to", new_version, "if --commit were specified"

{'fraction_non_alphanumeric': 0.11894446632532493, 'fraction_numerical': 0.0023631350925561244, 'mean_word_length': 2.427800269905533, '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': '4551909', 'n_tokens_mistral': 724, 'n_tokens_neox': 694, 'n_words': 195}