<commit_before>import django
from django.db.models import signals


def is_db_expression(value):
    try:
        # django < 1.8
        from django.db.models.expressions import ExpressionNode
        return isinstance(value, ExpressionNode)
    except ImportError:
        # django >= 1.8  (big refactoring in Lookup/Expressions/Transforms)
        from django.db.models.expressions import BaseExpression, Combinable
        return isinstance(value, (BaseExpression, Combinable))


def save_specific_fields(instance, fields_list):

    if django.VERSION >= (1, 5):
        instance.save(update_fields=fields_list.keys())
    else:
        # dirtyfields is by default returning dirty fields with their old value
        # We should pass the new value(s) to update the database
        new_fields_list = {field_name: getattr(instance, field_name)
                           for field_name, field_value in fields_list.items()}

        # django < 1.5 does not support update_fields option on save method
        instance.__class__.objects.filter(pk=instance.pk).update(**new_fields_list)

        # dirtyfield is based on post_save signal to save last database value in memory.
        # As update() method does not trigger this signal, we launch it explicitly.
        signals.post_save.send(sender=instance.__class__, instance=instance)<commit_msg>Adding pre_save signal sending in django 1.4, to be coherent with post_save sending.<commit_after>import django
from django.db.models import signals


def is_db_expression(value):
    try:
        # django < 1.8
        from django.db.models.expressions import ExpressionNode
        return isinstance(value, ExpressionNode)
    except ImportError:
        # django >= 1.8  (big refactoring in Lookup/Expressions/Transforms)
        from django.db.models.expressions import BaseExpression, Combinable
        return isinstance(value, (BaseExpression, Combinable))


def save_specific_fields(instance, fields_list):

    if django.VERSION >= (1, 5):
        instance.save(update_fields=fields_list.keys())
    else:
        # dirtyfields is by default returning dirty fields with their old value
        # We should pass the new value(s) to update the database
        new_fields_list = {field_name: getattr(instance, field_name)
                           for field_name, field_value in fields_list.items()}

        # dirtyfield is based on post_save signal to save last database value in memory.
        # As we need to manually launch post_save signal, we also launch pre_save
        # to be coherent with django 'classic' save signals.
        signals.pre_save.send(sender=instance.__class__, instance=instance)

        # django < 1.5 does not support update_fields option on save method
        instance.__class__.objects.filter(pk=instance.pk).update(**new_fields_list)

        # dirtyfield is based on post_save signal to save last database value in memory.
        # As update() method does not trigger this signal, we launch it explicitly.
        signals.post_save.send(sender=instance.__class__, instance=instance)
{'fraction_non_alphanumeric': 0.07184655396618986, 'fraction_numerical': 0.005851755526657998, 'mean_word_length': 3.197817189631651, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4860794', 'n_tokens_mistral': 814, 'n_tokens_neox': 792, 'n_words': 270}