<commit_before>from datetime import datetime
from dimagi.ext.couchdbkit import *

DELETED_SUFFIX = '-Deleted'

class DeleteRecord(Document):
    base_doc = 'DeleteRecord'
    domain = StringProperty()
    datetime = DateTimeProperty()

class DeleteDocRecord(DeleteRecord):
    doc_id = StringProperty()

    def undo(self):
        doc = self.get_doc()
        doc.doc_type = doc.doc_type.rstrip(DELETED_SUFFIX)
        doc.save()

class UndoableDocument(Document):
    def soft_delete(self, domain_included=True):
        if not self.doc_type.endswith(DELETED_SUFFIX):
            self.doc_type += DELETED_SUFFIX
            extra_args = {}
            if domain_included:
                extra_args["domain"] = self.domain

            record = self.create_delete_record(
                doc_id=self.get_id,
                datetime=datetime.utcnow(),
                **extra_args
            )
            record.save()
            self.save()
            return record<commit_msg>add is_deleted utility method<commit_after>from datetime import datetime
from dimagi.ext.couchdbkit import *

DELETED_SUFFIX = '-Deleted'


class DeleteRecord(Document):
    base_doc = 'DeleteRecord'
    domain = StringProperty()
    datetime = DateTimeProperty()


class DeleteDocRecord(DeleteRecord):
    doc_id = StringProperty()

    def undo(self):
        doc = self.get_doc()
        doc.doc_type = doc.doc_type.rstrip(DELETED_SUFFIX)
        doc.save()


class UndoableDocument(Document):
    def soft_delete(self, domain_included=True):
        if not self.doc_type.endswith(DELETED_SUFFIX):
            self.doc_type += DELETED_SUFFIX
            extra_args = {}
            if domain_included:
                extra_args["domain"] = self.domain

            record = self.create_delete_record(
                doc_id=self.get_id,
                datetime=datetime.utcnow(),
                **extra_args
            )
            record.save()
            self.save()
            return record


def is_deleted(doc):
    """
    Guess if a document is deleted. Returns False if we're not sure.
    """
    try:
        return doc['doc_type'].endswith(DELETED_SUFFIX)
    except KeyError:
        return False
{'fraction_non_alphanumeric': 0.09128065395095368, 'fraction_numerical': 0.0, 'mean_word_length': 2.244477172312224, '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': '2853240', 'n_tokens_mistral': 665, 'n_tokens_neox': 642, 'n_words': 127}