<commit_before># -*- coding: utf-8 -*-

from datetime import date

from django.core.management.base import BaseCommand
from django.db import transaction
from django.utils.text import slugify

from candidates.models import (
    AreaExtra, OrganizationExtra, PostExtra, PartySet
)
from elections.models import AreaType, Election
from popolo.models import Area, Organization, Post
import requests

class Command(BaseCommand):

    def get_or_create_organization(self, slug, name):
        try:
            org_extra = OrganizationExtra.objects.get(slug=slug)
            org = org_extra.base
            org.name = name
            org.save()
        except OrganizationExtra.DoesNotExist:
            org = Organization.objects.create(name=name)
            org_extra = OrganizationExtra.objects.create(base=org, slug=slug)
        return org

    def handle(self, *args, **options):
        with transaction.atomic():
            # Create all the AreaType objects first:
            area_type, created = AreaType.objects.get_or_create(
                name='CRCANTON',
                defaults={'source': 'MapIt'},
            )
            # Now the Election objects (and the organizations they're
            # associated with)
            elections = []
            for election_data in [
                    {
                        'slug': 'mun-al-2016',
                        'for_post_role': 'Alcalde',
                        'name': u'Elección de Alcaldes 2016',
                        'organization_name': 'Alcaldía Municipal',
                        'organization_slug': 'alcaldia-municipal',
                        'party_lists_in_use': False,
                    },
                    {
                        'slug': 'mun-re-2016',
                        'for_post_role': 'Regidor',
                        'name': u'Elección de Regidores 2016',
                        'organization_name': 'Consejo Municipal',
                        'organization_slug': 'consejo-municipal',
                        'party_lists_in_use': True,
                        'default_party_list_members_to_show': 3,
                    },
            ]:
                org = self.get_or_create_organization(
                    election_data['organization_slug'],
                    election_data['organization_name'],
                )
                del election_data['organization_name']
                del election_data['organization_slug']
                election_data['organization'] = org
                consistent_data = {<commit_msg>Fix Unicode / non-Unicode comparison warnings in cr_create_basic_site<commit_after># -*- coding: utf-8 -*-

from datetime import date

from django.core.management.base import BaseCommand
from django.db import transaction
from django.utils.text import slugify

from candidates.models import (
    AreaExtra, OrganizationExtra, PostExtra, PartySet
)
from elections.models import AreaType, Election
from popolo.models import Area, Organization, Post
import requests

class Command(BaseCommand):

    def get_or_create_organization(self, slug, name):
        try:
            org_extra = OrganizationExtra.objects.get(slug=slug)
            org = org_extra.base
            org.name = name
            org.save()
        except OrganizationExtra.DoesNotExist:
            org = Organization.objects.create(name=name)
            org_extra = OrganizationExtra.objects.create(base=org, slug=slug)
        return org

    def handle(self, *args, **options):
        with transaction.atomic():
            # Create all the AreaType objects first:
            area_type, created = AreaType.objects.get_or_create(
                name='CRCANTON',
                defaults={'source': 'MapIt'},
            )
            # Now the Election objects (and the organizations they're
            # associated with)
            elections = []
            for election_data in [
                    {
                        'slug': 'mun-al-2016',
                        'for_post_role': 'Alcalde',
                        'name': u'Elección de Alcaldes 2016',
                        'organization_name': u'Alcaldía Municipal',
                        'organization_slug': 'alcaldia-municipal',
                        'party_lists_in_use': False,
                    },
                    {
                        'slug': 'mun-re-2016',
                        'for_post_role': 'Regidor',
                        'name': u'Elección de Regidores 2016',
                        'organization_name': u'Consejo Municipal',
                        'organization_slug': 'consejo-municipal',
                        'party_lists_in_use': True,
                        'default_party_list_members_to_show': 3,
                    },
            ]:
                org = self.get_or_create_organization(
                    election_data['organization_slug'],
                    election_data['organization_name'],
                )
                del election_data['organization_name']
                del election_data['organization_slug']
                election_data['organization'] = org
                consistent_data = {
{'fraction_non_alphanumeric': 0.08724311748739821, 'fraction_numerical': 0.006979449398991857, 'mean_word_length': 1.6267820773930755, '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': '1689479', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1232, 'n_words': 284}