<commit_before>from django.db import models
from django.utils.translation import ugettext_lazy as _

from django_handleref.manager import HandleRefManager

try:
    import reversion

    def handle_version(**kwargs):
        for instance in kwargs.get("instances"):
            instance.version = instance.version + 1
            instance.save()

    reversion.post_revision_commit.connect(handle_version)
except ImportError:
    pass

class HandleRefModel(models.Model):
    
    """
    Provides timestamps for creation and change times,
    versioning (using django-reversion) as well as
    the ability to soft-delete
    """

    id = models.AutoField(primary_key=True)
    status = models.CharField(_('Status'), max_length=255, blank=True)
    created = models.DateTimeField(_('Created'), auto_now_add=True)
    updated = models.DateTimeField(_('Updated'), auto_now=True)
    version = models.IntegerField(default=0)

    handleref = HandleRefManager()
    objects = models.Manager()

    class Meta:
        get_latest_by = 'updated'
        ordering = ('-updated', '-created',)
        abstract = True

    @property
    def handle(self):
        if not self._ref_tag:
            self._ref_tag = self.__class__.__name__.lower()
        return self._ref_tag + str(self.id)

    def __unicode__(self):
        if not hasattr(self, "name"): 
          name = self.__class__.__name__
        else:
          name = self.name
        return name + '-' + self.handle

    def delete(self, hard=False):
        
        """
        Override the vanilla delete functionality to soft-delete
        instead. Soft-delete is accomplished by setting the
        status field to "deleted"

        Arguments:

        hard <bool=False> if true, do a hard delete instead, effectively
        removing the object from the database
        """

        if hard:
            return models.Model.delete(self)
        self.status = "deleted"
        self.save()
        if hasattr(self, "delete_cascade"):
            for key in self.delete_cascade:
                for child in getattr(self, key).all():
                    child.delete()

<commit_msg>delete(): pass hard when cascading<commit_after>from django.db import models
from django.utils.translation import ugettext_lazy as _

from django_handleref.manager import HandleRefManager

try:
    import reversion

    def handle_version(**kwargs):
        for instance in kwargs.get("instances"):
            instance.version = instance.version + 1
            instance.save()

    reversion.post_revision_commit.connect(handle_version)
except ImportError:
    pass

class HandleRefModel(models.Model):
    
    """
    Provides timestamps for creation and change times,
    versioning (using django-reversion) as well as
    the ability to soft-delete
    """

    id = models.AutoField(primary_key=True)
    status = models.CharField(_('Status'), max_length=255, blank=True)
    created = models.DateTimeField(_('Created'), auto_now_add=True)
    updated = models.DateTimeField(_('Updated'), auto_now=True)
    version = models.IntegerField(default=0)

    handleref = HandleRefManager()
    objects = models.Manager()

    class Meta:
        get_latest_by = 'updated'
        ordering = ('-updated', '-created',)
        abstract = True

    @property
    def handle(self):
        if not self._ref_tag:
            self._ref_tag = self.__class__.__name__.lower()
        return self._ref_tag + str(self.id)

    def __unicode__(self):
        if not hasattr(self, "name"): 
          name = self.__class__.__name__
        else:
          name = self.name
        return name + '-' + self.handle

    def delete(self, hard=False):
        
        """
        Override the vanilla delete functionality to soft-delete
        instead. Soft-delete is accomplished by setting the
        status field to "deleted"

        Arguments:

        hard <bool=False> if true, do a hard delete instead, effectively
        removing the object from the database
        """

        if hard:
            return models.Model.delete(self)
        self.status = "deleted"
        self.save()
        if hasattr(self, "delete_cascade"):
            for key in self.delete_cascade:
                for child in getattr(self, key).all():
                    child.delete(hard=hard)


{'fraction_non_alphanumeric': 0.09453197405004633, 'fraction_numerical': 0.0023169601482854493, 'mean_word_length': 2.439840637450199, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2729617', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1169, 'n_words': 322}