<commit_before>from __future__ import unicode_literals

from django.db import models


class BaseInfo(models.Model):
    """Base class containing all models common information."""

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        abstract = True


class Users(BaseInfo):
    """User model defined."""

    USER_ROLE = (
        ('A', 'Admin'),
        ('U', 'User'),
    )

    name = models.CharField(max_length=200)
    email = models.EmailField(max_length=254)
    role = models.CharField(max_length=2, choices=USER_ROLE)


class Authors(BaseInfo):
    """Book author models defined."""

    name = models.CharField(max_length=200)


class Books(BaseInfo):
    """Book model defined."""

    title = models.CharField(max_length=100)
    edition = models.CharField(max_length=100)
    publisher = models.CharField(max_length=100)
    description = models.TextField()
    isbn = models.CharField(max_length=50)
    quantity = models.CharField(max_length=10)
    status = models.CharField(max_length=100) # add status based on qty
    author = models.ForeignKey('Authors',
                               related_name="myauthor",
                               on_delete=models.CASCADE)


class Reviews(BaseInfo):
    """Book review model defined."""

    comment = models.TextField()
    user = models.ForeignKey('Users',
                             related_name="myuser",
                             on_delete=models.CASCADE)
    book = models.ForeignKey('Books',
                             related_name="mybook",
                             on_delete=models.CASCADE)


class History(BaseInfo):
    """User history model defined."""

    lending_date = models.DateTimeField(auto_now_add=True)
    expreturn_date = models.DateTimeField(auto_now_add=False,
                                          auto_now=False, blank=False)  # increment by 14 days
    return_date = models.DateTimeField(auto_now_add=False,
                                       auto_now=False, blank=True, null=True)
    status = models.CharField(max_length=100)
    book = models.ForeignKey('Books',
                             related_name="mybook",
                             on_delete=models.CASCADE)
    user = models.ForeignKey('Users',
                             related_name="myuser",
                             on_delete=models.CASCADE)
<commit_msg>add property methods to models<commit_after>from __future__ import unicode_literals

from django.db import models


class BaseInfo(models.Model):
    """Base class containing all models common information."""

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        abstract = True


class Users(BaseInfo):
    """User model defined."""

    USER_ROLE = (
        ('A', 'Admin'),
        ('U', 'User'),
    )

    name = models.CharField(max_length=200)
    email = models.EmailField(max_length=254)
    role = models.CharField(max_length=2, choices=USER_ROLE)


class Authors(BaseInfo):
    """Book author models defined."""

    name = models.CharField(max_length=200)


class Books(BaseInfo):
    """Book model defined."""

    title = models.CharField(max_length=100)
    edition = models.CharField(max_length=100)
    publisher = models.CharField(max_length=100)
    description = models.TextField()
    isbn = models.CharField(max_length=50)
    quantity = models.IntegerField()
    author = models.ForeignKey('Authors',
                               related_name="myauthor",
                               on_delete=models.CASCADE)

    def _check_status(self):
        if self.quantity <= 0:
            return "Not Available"
        else:
            return "Available"
    status = property(_check_status)


class Reviews(BaseInfo):
    """Book review model defined."""

    comment = models.TextField()
    # ratings needs to be implemented here.
    user = models.ForeignKey('Users',
                             related_name="myuser",
                             on_delete=models.CASCADE)
    book = models.ForeignKey('Books',
                             related_name="mybook",
                             on_delete=models.CASCADE)


class History(BaseInfo):
    """User history model defined."""

    lending_date = models.DateTimeField(auto_now_add=True)
    return_date = models.DateTimeField(auto_now_add=False,
                                       auto_now=False,
                                       blank=True, null=True)
    returned = models.BooleanField(default=False)

    def _expected_return_date(self):
        import datetime
        present_day = datetime.date.today()
        day_14 = datetime.timedelta(weeks=2)
        return_date = present_day + day_14
        return return_date

    exptdreturn_date = property(_expected_return_date)

    book = models.ForeignKey('Books',
                             related_name="mybook",
                             on_delete=models.CASCADE)
    user = models.ForeignKey('Users',
                             related_name="myuser",
                             on_delete=models.CASCADE)

{'fraction_non_alphanumeric': 0.10125603864734299, 'fraction_numerical': 0.011207729468599034, 'mean_word_length': 2.2329793878825734, 'pattern_counts': {'":': 0, '<': 4, '<?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': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1664292', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1395, 'n_words': 273}