Beispiel #1
0
class GeneratedNote(Status):
    """these are app-generated messages about user activity"""
    @property
    def pure_content(self):
        """indicate the book in question for mastodon (or w/e) users"""
        message = self.content
        books = ", ".join(f'<a href="{book.remote_id}">"{book.title}"</a>'
                          for book in self.mention_books.all())
        return f"{self.user.display_name} {message} {books}"

    activity_serializer = activitypub.GeneratedNote
    pure_type = "Note"


ReadingStatusChoices = models.TextChoices("ReadingStatusChoices",
                                          ["to-read", "reading", "read"])


class BookStatus(Status):
    """Shared fields for comments, quotes, reviews"""

    book = fields.ForeignKey("Edition",
                             on_delete=models.PROTECT,
                             activitypub_field="inReplyToBook")
    pure_type = "Note"

    reading_status = fields.CharField(max_length=255,
                                      choices=ReadingStatusChoices.choices,
                                      null=True,
                                      blank=True)
Beispiel #2
0
""" make a list of books!! """
from django.apps import apps
from django.db import models

from bookwyrm import activitypub
from bookwyrm.settings import DOMAIN
from .activitypub_mixin import CollectionItemMixin, OrderedCollectionMixin
from .base_model import BookWyrmModel
from . import fields


CurationType = models.TextChoices(
    "Curation",
    [
        "closed",
        "open",
        "curated",
    ],
)


class List(OrderedCollectionMixin, BookWyrmModel):
    """ a list of books """

    name = fields.CharField(max_length=100)
    user = fields.ForeignKey(
        "User", on_delete=models.PROTECT, activitypub_field="owner"
    )
    description = fields.TextField(blank=True, null=True, activitypub_field="summary")
    privacy = fields.PrivacyField()
    curation = fields.CharField(
class Infected(models.Model):
    STATUS_CHOICES = models.TextChoices('StatusType',
                                        'Infected Deceased Off-Isolated')

    name = models.CharField(max_length=30)
    status = models.CharField(max_length=12, choices=STATUS_CHOICES.choices)
Beispiel #4
0
class ProductionLogs(models.Model):
    Severity = models.TextChoices('Severity', 'INFO WARN ERROR FATAL')

    producer = models.ForeignKey('Producer', on_delete=models.CASCADE)
    severity = models.CharField(choices=Severity.choices, max_length=6)
    content = models.TextField()
Beispiel #5
0
 def test_textchoices_functional_api(self):
     Medal = models.TextChoices('Medal', 'GOLD SILVER BRONZE')
     self.assertEqual(Medal.labels, ['Gold', 'Silver', 'Bronze'])
     self.assertEqual(Medal.values, ['GOLD', 'SILVER', 'BRONZE'])
     self.assertEqual(Medal.names, ['GOLD', 'SILVER', 'BRONZE'])
Beispiel #6
0
 def test_label_member(self):
     # label can be used as a member.
     Stationery = models.TextChoices('Stationery', 'label stamp sticker')
     self.assertEqual(Stationery.label.label, 'Label')
     self.assertEqual(Stationery.label.value, 'label')
     self.assertEqual(Stationery.label.name, 'label')
Beispiel #7
0
 def test_property_names_conflict_with_member_names(self):
     with self.assertRaises(AttributeError):
         models.TextChoices('Properties', 'choices labels names values')
Beispiel #8
0
""" manages interfaces with external sources of book data """
from django.db import models
from bookwyrm.connectors.settings import CONNECTORS

from .base_model import BookWyrmModel

ConnectorFiles = models.TextChoices("ConnectorFiles", CONNECTORS)


class Connector(BookWyrmModel):
    """ book data source connectors """

    identifier = models.CharField(max_length=255, unique=True)
    priority = models.IntegerField(default=2)
    name = models.CharField(max_length=255, null=True, blank=True)
    local = models.BooleanField(default=False)
    connector_file = models.CharField(max_length=255,
                                      choices=ConnectorFiles.choices)
    api_key = models.CharField(max_length=255, null=True, blank=True)

    base_url = models.CharField(max_length=255)
    books_url = models.CharField(max_length=255)
    covers_url = models.CharField(max_length=255)
    search_url = models.CharField(max_length=255, null=True, blank=True)
    isbn_search_url = models.CharField(max_length=255, null=True, blank=True)

    politeness_delay = models.IntegerField(null=True, blank=True)  # seconds
    max_query_count = models.IntegerField(null=True, blank=True)
    # how many queries executed in a unit of time, like a day
    query_count = models.IntegerField(default=0)
    # when to reset the query count back to 0 (ie, after 1 day)
Beispiel #9
0
        super().save(*args, **kwargs)

    class Meta:
        unique_together = ('user', 'book', 'name')


class ReadThrough(FedireadsModel):
    ''' Store progress through a book in the database. '''
    user = models.ForeignKey('User', on_delete=models.PROTECT)
    book = models.ForeignKey('Book', on_delete=models.PROTECT)
    pages_read = models.IntegerField(null=True, blank=True)
    start_date = models.DateTimeField(blank=True, null=True)
    finish_date = models.DateTimeField(blank=True, null=True)


NotificationType = models.TextChoices(
    'NotificationType', 'FAVORITE REPLY TAG FOLLOW FOLLOW_REQUEST BOOST')


class Notification(FedireadsModel):
    ''' you've been tagged, liked, followed, etc '''
    user = models.ForeignKey('User', on_delete=models.PROTECT)
    related_book = models.ForeignKey('Edition',
                                     on_delete=models.PROTECT,
                                     null=True)
    related_user = models.ForeignKey('User',
                                     on_delete=models.PROTECT,
                                     null=True,
                                     related_name='related_user')
    related_status = models.ForeignKey('Status',
                                       on_delete=models.PROTECT,
                                       null=True)
Beispiel #10
0
class Egg(models.Model):
    user = models.ForeignKey(BudgieUser, on_delete=models.CASCADE)
    couple = models.ForeignKey(BreedingCouple)
    date = models.DateField(verbose_name=_("Date found"))
    status = models.TextChoices(blank=True, null=True)