<commit_before>from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from mptt.models import MPTTModel, TreeForeignKey
import mistune


class ContentTypeAware(models.Model):
    def get_content_type(self):
        """
        :return: Content type for this instance.
        """
        return ContentType.objects.get_for_model(self)

    def get_content_type_id(self):
        """

        :return: Content type ID for this instance
        """
        return self.get_content_type().pk

    class Meta:
        abstract = True

class MttpContentTypeAware(MPTTModel):
    def get_content_type(self):
        """
        :return: Content type for this instance.
        """
        return ContentType.objects.get_for_model(self)

    def get_content_type_id(self):
        """

        :return: Content type ID for this instance
        """
        return self.get_content_type().pk

    class Meta:
        abstract = True


class RedditUser(models.Model):
    user = models.OneToOneField(User)

    def __unicode__(self):
        return "<RedditUser:{}>".format(self.user.username)


class Submission(ContentTypeAware):
    author = models.ForeignKey(RedditUser)
    title = models.CharField(max_length=250)
    url = models.URLField(null=True, blank=True)
    text = models.TextField(max_length=5000, blank=True)
    ups = models.IntegerField(default=0)
    downs = models.IntegerField(default=0)
    score = models.IntegerField(default=0)
    timestamp = models.DateTimeField(default=timezone.now)
    comment_count = models.IntegerField(default=0)

    @property
    def author_name(self):
        return self.author.user.username

    @property
    def linked_url(self):
        if self.url:
            return "{}".format(self.url)
        else:
            return "/comments/{}".format(self.id)

    @property<commit_msg>Add optional user info fields to RedditUser model, code refactoring<commit_after>from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from mptt.models import MPTTModel, TreeForeignKey
import mistune


class ContentTypeAware(models.Model):
    def get_content_type(self):
        """:return: Content type for this instance."""
        return ContentType.objects.get_for_model(self)

    def get_content_type_id(self):
        """:return: Content type ID for this instance"""
        return self.get_content_type().pk

    class Meta:
        abstract = True


class MttpContentTypeAware(MPTTModel):
    def get_content_type(self):
        """:return: Content type for this instance."""
        return ContentType.objects.get_for_model(self)

    def get_content_type_id(self):
        """:return: Content type ID for this instance"""
        return self.get_content_type().pk

    class Meta:
        abstract = True


class RedditUser(models.Model):
    user = models.OneToOneField(User)
    first_name = models.CharField(max_length=35,null=True, default=None)
    last_name = models.CharField(max_length=35, null=True, default=None)
    email = models.EmailField(null=True, blank=True, default=None)
    about_text = models.TextField(blank=True,null=True, max_length=500, default=None)
    about_html = models.TextField(blank=True,null=True,default=None)
    gravatar_hash = models.CharField(max_length=32,null=True,blank=True, default=None)
    display_picture = models.NullBooleanField(default=False)
    homepage = models.URLField(null=True, blank=True, default=None)
    twitter = models.CharField(null=True,blank=True, max_length=15, default=None)
    github = models.CharField(null=True, max_length=39, default=None)

    comment_karma = models.IntegerField(default=0)
    link_karma = models.IntegerField(default=0)

    def __unicode__(self):
        return "<RedditUser:{}>".format(self.user.username)


class Submission(ContentTypeAware):
    author = models.ForeignKey(RedditUser)
    title = models.CharField(max_length=250)
    url = models.URLField(null=True, blank=True)
    text = models.TextField(max_length=5000, blank=True)
    ups = models.IntegerField(default=0)
    downs = models.IntegerField(default=0)
    score = models.IntegerField(default=0)
    timestamp = models.DateTimeField(default=timezone.now)
    comment_count = models.IntegerField(default=0)

    @property
    def author_name(self):
        return self.author.user.username

    @property
    def linked_url(self):
        if self.url:
            return "{}".format(self.url)
        else:
            return "/comments/{}".format(self.id)

    @property
{'fraction_non_alphanumeric': 0.10291985918409609, 'fraction_numerical': 0.0076620418306067506, 'mean_word_length': 3.617590822179732, 'pattern_counts': {'":': 4, '<': 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': '1019386', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1404, 'n_words': 300}