<commit_before># -*- encoding: utf-8 -*-
from django.contrib.sites.models import Site


def clean_and_save(model_instance):
    """
    Validate and save a model instance.

    Calling 'save' or 'create' (e.g. 'TimeRecord.objects.create') does not call
    the validation methods.

    We have to call 'full_clean' after 'save' because in some cases, the 'save'
    method updates the row.
    """
    model_instance.save()
    model_instance.full_clean()
    return model_instance


def init_site(pk, name, domain):
    """Use this for setting up initial sites."""
    try:
        site = Site.objects.get(pk=pk)
        site.name = name
        site.domain = domain
        site.save()
    except Site.DoesNotExist:
        site = clean_and_save(
            Site(**dict(pk=pk, name=name, domain=domain))
        )
    return site<commit_msg>Remove 'init_site' because I can't get 'Site' working with Django 1.9<commit_after># -*- encoding: utf-8 -*-


def clean_and_save(model_instance):
    """
    Validate and save a model instance.

    Calling 'save' or 'create' (e.g. 'TimeRecord.objects.create') does not call
    the validation methods.

    We have to call 'full_clean' after 'save' because in some cases, the 'save'
    method updates the row.
    """
    model_instance.save()
    model_instance.full_clean()
    return model_instance


# from django.contrib.sites.models import Site
# def init_site(pk, name, domain):
#     """Use this for setting up initial sites."""
#     try:
#         site = Site.objects.get(pk=pk)
#         site.name = name
#         site.domain = domain
#         site.save()
#     except Site.DoesNotExist:
#         site = clean_and_save(
#             Site(**dict(pk=pk, name=name, domain=domain))
#         )
#     return site
{'fraction_non_alphanumeric': 0.11694915254237288, 'fraction_numerical': 0.0022598870056497176, 'mean_word_length': 2.6515463917525772, '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': '740133', 'n_tokens_mistral': 548, 'n_tokens_neox': 534, 'n_words': 161}