# Path: dwitter/utils.py
# def length_of_code(code):
#     """
#     Centralize the character counting to one place
#     """
#     return len(code.replace('\r\n', '\n'))


import re
from django.db import models
from django.utils.functional import cached_property
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
from django.dispatch import receiver
from django.db.models.signals import pre_delete, post_save, m2m_changed
from math import log
from datetime import datetime
from .utils import length_of_code
    likes = models.ManyToManyField(User, related_name="liked", blank=True)
    hotness = models.FloatField(default=1.0, db_index=True)
    deleted = models.BooleanField(default=False)

    author = models.ForeignKey(User, on_delete=models.SET(get_sentinel_user),
                               null=True, blank=True)

    objects = NotDeletedDweetManager()
    with_deleted = models.Manager()

    class Meta:
        ordering = ('-posted',)

    def delete(self):
        self.deleted = True
        self.save()

    def save(self, *args, **kwargs):
        self.calculate_hotness((self.pk is None))
        super(Dweet, self).save(*args, **kwargs)

    @cached_property
    def top_comment(self):
        """
        Return the top comment. This is mainly a caching optimization to avoid queries
        """
        return self.comments.first()

    @cached_property
    def dweet_length(self):

# Path: dwitter/utils.py
# def length_of_code(code):
#     """
#     Centralize the character counting to one place
#     """
#     return len(code.replace('\r\n', '\n'))


# Path: dwitter/models.py
import re
from django.db import models
from django.utils.functional import cached_property
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
from django.dispatch import receiver
from django.db.models.signals import pre_delete, post_save, m2m_changed
from math import log
from datetime import datetime
from .utils import length_of_code

    likes = models.ManyToManyField(User, related_name="liked", blank=True)
    hotness = models.FloatField(default=1.0, db_index=True)
    deleted = models.BooleanField(default=False)

    author = models.ForeignKey(User, on_delete=models.SET(get_sentinel_user),
                               null=True, blank=True)

    objects = NotDeletedDweetManager()
    with_deleted = models.Manager()

    class Meta:
        ordering = ('-posted',)

    def delete(self):
        self.deleted = True
        self.save()

    def save(self, *args, **kwargs):
        self.calculate_hotness((self.pk is None))
        super(Dweet, self).save(*args, **kwargs)

    @cached_property
    def top_comment(self):
        """
        Return the top comment. This is mainly a caching optimization to avoid queries
        """
        return self.comments.first()

    @cached_property
    def dweet_length(self):

        return length_of_code(self.code)