<commit_before>import uuid

import re
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save

from social.app.models.node import Node

class Author(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

    displayName = models.CharField(max_length=512)

    ### Optional Attributes

    user = models.OneToOneField(User, related_name='user', blank=True, null=True)

    # https://github.com/join
    github = models.URLField(default='', blank=True)

    bio = models.TextField(default='', blank=True)

    ### Meta Attributes
    activated = models.BooleanField(default=False)

    node = models.ForeignKey(Node, on_delete=models.CASCADE)

    followed_authors = models.ManyToManyField(
        'self',
        symmetrical=False,
        # Ensures no backwards relation is created
        # No need to for an author to see who follows them
        related_name='+',
        blank=True)

    outgoing_friend_requests = models.ManyToManyField(
        'self',
        symmetrical=False,
        related_name='incoming_friend_requests',
        blank=True
    )

    friends = models.ManyToManyField('self', blank=True)

    def follows(self, author):
        return self != author and len(self.followed_authors.filter(id=author.id)) > 0

    def friends_with(self, author):
        return self != author and len(self.friends.filter(id=author.id)) > 0

    def has_outgoing_friend_request_for(self, author):
        return self != author and len(self.outgoing_friend_requests.filter(id=author.id)) > 0

    def has_incoming_friend_request_from(self, author):
        return self != author and len(self.incoming_friend_requests.filter(id=author.id)) > 0

    def can_follow(self, author):
        return not (
            self == author
            or not self.activated
            or not author.activated
            or self.follows(author)
        )

    def can_send_a_friend_request_to(self, author):
        return not (
            self == author
            or not self.activated
            or not author.activated
            or self.friends_with(author)
            or self.has_outgoing_friend_request_for(author)
            or self.has_incoming_friend_request_from(author)
        )

    def add_friend_request(self, author):
        self.outgoing_friend_requests.add(author)
        self.followed_authors.add(author)

    def accept_friend_request(self, author):
        if self.incoming_friend_requests.filter(id=author.id):
            self.incoming_friend_requests.remove(author)
            self.friends.add(author)
            self.followed_authors.add(author)
        else:
            raise Exception("Attempted to accept a friend request that does not exist.")

    def __str__(self):
        return '%s' % self.displayName

    @classmethod
    def get_id_from_uri(cls, uri):
        match = re.match(r'^(.+)//(.+)/author/(?P<pk>[0-9a-z\\-]+)', uri)
        return match.group('pk')


def create_profile(sender, **kwargs):
    from social.tasks import get_github_activity
    user = kwargs["instance"]
    if not user.is_staff:
        user_profile = Author(user=user)
        get_github_activity(str(userprofile.id))
        user_profile.displayName = user_profile.user.first_name + ' ' + user_profile.user.last_name
        user_profile.node = Node.objects.get(local=True)
        user_profile.save()

post_save.connect(create_profile, sender=User)

User.profile = property(lambda u: Author.objects.get_or_create(user=u)[0])<commit_msg>Is this right?<commit_after>import uuid

import re
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save

from social.app.models.node import Node

class Author(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

    displayName = models.CharField(max_length=512)

    ### Optional Attributes

    user = models.OneToOneField(User, related_name='user', blank=True, null=True)

    # https://github.com/join
    github = models.URLField(default='', blank=True)

    bio = models.TextField(default='', blank=True)

    ### Meta Attributes
    activated = models.BooleanField(default=False)

    node = models.ForeignKey(Node, on_delete=models.CASCADE)

    followed_authors = models.ManyToManyField(
        'self',
        symmetrical=False,
        # Ensures no backwards relation is created
        # No need to for an author to see who follows them
        related_name='+',
        blank=True)

    outgoing_friend_requests = models.ManyToManyField(
        'self',
        symmetrical=False,
        related_name='incoming_friend_requests',
        blank=True
    )

    friends = models.ManyToManyField('self', blank=True)

    def follows(self, author):
        return self != author and len(self.followed_authors.filter(id=author.id)) > 0

    def friends_with(self, author):
        return self != author and len(self.friends.filter(id=author.id)) > 0

    def has_outgoing_friend_request_for(self, author):
        return self != author and len(self.outgoing_friend_requests.filter(id=author.id)) > 0

    def has_incoming_friend_request_from(self, author):
        return self != author and len(self.incoming_friend_requests.filter(id=author.id)) > 0

    def can_follow(self, author):
        return not (
            self == author
            or not self.activated
            or not author.activated
            or self.follows(author)
        )

    def can_send_a_friend_request_to(self, author):
        return not (
            self == author
            or not self.activated
            or not author.activated
            or self.friends_with(author)
            or self.has_outgoing_friend_request_for(author)
            or self.has_incoming_friend_request_from(author)
        )

    def add_friend_request(self, author):
        self.outgoing_friend_requests.add(author)
        self.followed_authors.add(author)

    def accept_friend_request(self, author):
        if self.incoming_friend_requests.filter(id=author.id):
            self.incoming_friend_requests.remove(author)
            self.friends.add(author)
            self.followed_authors.add(author)
        else:
            raise Exception("Attempted to accept a friend request that does not exist.")

    def __str__(self):
        return '%s' % self.displayName

    @classmethod
    def get_id_from_uri(cls, uri):
        match = re.match(r'^(.+)//(.+)/author/(?P<pk>[0-9a-z\\-]+)', uri)
        return match.group('pk')

def create_profile(sender, **kwargs):
    from social.tasks import get_github_activity
    user = kwargs["instance"]
    if not user.is_staff and kwargs["created"]:
        user_profile = Author(user=user)
        user_profile.displayName = user_profile.user.first_name + ' ' + user_profile.user.last_name
        user_profile.node = Node.objects.get(local=True)
        user_profile.save()
        if user_profile.github != "":
            get_github_activity(user_profile.id)

def update_profile(sender, **kwargs):
    from social.tasks import get_github_activity
    user = kwargs["instance"]
    if not user.is_staff and kwargs["updated"]:
        user_profile = Author(user=user)
        if user_profile.github != "":
            get_github_activity(user_profile.id)

post_save.connect(create_profile, sender=User)
post_save.connect(update_profile, sender=User)

User.profile = property(lambda u: Author.objects.get_or_create(user=u)[0])
{'fraction_non_alphanumeric': 0.1039978748837827, 'fraction_numerical': 0.002922034798778058, 'mean_word_length': 3.0010626992561105, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '1434255', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2216, 'n_words': 460}