<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import

from random import randrange

from django.conf import settings
from django.db import models
from django.urls import reverse
from django.utils.encoding import python_2_unicode_compatible

# Create your models here.
class QuoteManager(models.Manager):

    use_for_related_fields = True

    def get_random(self):
        """
        Gets a random message from database
        """
        size = int(self.latest('id').id)
        quote = None
        while not quote:
            rand_id = randrange(1,size)
            try:
                quote = self.approved().get(pk=rand_id)
                if quote:
                    break
            except Quote.DoesNotExist:
                continue
        return quote

    def approved(self):
        return self.exclude(votes__lt=-3)

@python_2_unicode_compatible
class Quote(models.Model):
    message = models.CharField("Desahógate aquí", max_length=140, unique=True)
    date_created = models.DateTimeField(auto_now_add=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True)
    is_annonymous = models.BooleanField(default=1, blank=True)
    votes = models.IntegerField(default=0, null=True, blank=True)

    objects = QuoteManager()

    class Meta:
        ordering = ['-date_created']

    def __str__(self):
        return "%s" % self.message

    def get_absolute_url(self):
        return reverse('quotes:quote', args=[self.id])

    def vote(self, how):
        if how == "up":
            self.votes += 1
        elif how == "down":
            self.votes -= 1
        self.save()
        return self.votes<commit_msg>Removes saving the instance on vote<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import

from random import randrange

from django.conf import settings
from django.db import models
from django.urls import reverse
from django.utils.encoding import python_2_unicode_compatible

# Create your models here.
class QuoteManager(models.Manager):

    use_for_related_fields = True

    def get_random(self):
        """
        Gets a random message from database
        """
        size = int(self.latest('id').id)
        quote = None
        while not quote:
            rand_id = randrange(1,size)
            try:
                quote = self.approved().get(pk=rand_id)
                if quote:
                    break
            except Quote.DoesNotExist:
                continue
        return quote

    def approved(self):
        return self.exclude(votes__lt=-3)

@python_2_unicode_compatible
class Quote(models.Model):
    message = models.CharField("Desahógate aquí", max_length=140, unique=True)
    date_created = models.DateTimeField(auto_now_add=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True)
    is_annonymous = models.BooleanField(default=1, blank=True)
    votes = models.IntegerField(default=0, null=True, blank=True)

    objects = QuoteManager()

    class Meta:
        ordering = ['-date_created']

    def __str__(self):
        return "%s" % self.message

    def get_absolute_url(self):
        return reverse('quotes:quote', args=[self.id])

    def vote(self, how):
        """
        Makes one vote in the direction specified
        Returns the new total of votes
        """
        if how == "up":
            self.votes += 1
        elif how == "down":
            self.votes -= 1
        return self.votes
{'fraction_non_alphanumeric': 0.09673758865248228, 'fraction_numerical': 0.006808510638297872, 'mean_word_length': 2.460255152109912, 'pattern_counts': {'":': 4, '<': 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': '4087195', 'n_tokens_mistral': 1035, 'n_tokens_neox': 995, 'n_words': 258}