Ejemplo n.º 1
0
 def test_status_type(self, *_):
     """class name"""
     self.assertEqual(models.Status().status_type, "Note")
     self.assertEqual(models.Review().status_type, "Review")
     self.assertEqual(models.Quotation().status_type, "Quotation")
     self.assertEqual(models.Comment().status_type, "Comment")
     self.assertEqual(models.Boost().status_type, "Announce")
Ejemplo n.º 2
0
    def test_replies(self, *_):
        """get a list of replies"""
        parent = models.Status(content="hi", user=self.local_user)
        parent.save(broadcast=False)
        child = models.Status(content="hello",
                              reply_parent=parent,
                              user=self.local_user)
        child.save(broadcast=False)
        sibling = models.Review(content="hey",
                                reply_parent=parent,
                                user=self.local_user,
                                book=self.book)
        sibling.save(broadcast=False)
        grandchild = models.Status(content="hi hello",
                                   reply_parent=child,
                                   user=self.local_user)
        grandchild.save(broadcast=False)

        replies = models.Status.replies(parent)
        self.assertEqual(replies.count(), 2)
        self.assertEqual(replies.first(), child)
        # should select subclasses
        self.assertIsInstance(replies.last(), models.Review)

        self.assertEqual(parent.thread_id, parent.id)
        self.assertEqual(child.thread_id, parent.id)
        self.assertEqual(sibling.thread_id, parent.id)
        self.assertEqual(grandchild.thread_id, parent.id)
Ejemplo n.º 3
0
 def test_status_type(self, _):
     ''' class name '''
     self.assertEqual(models.Status().status_type, 'Note')
     self.assertEqual(models.Review().status_type, 'Review')
     self.assertEqual(models.Quotation().status_type, 'Quotation')
     self.assertEqual(models.Comment().status_type, 'Comment')
     self.assertEqual(models.Boost().status_type, 'Boost')
Ejemplo n.º 4
0
def handle_imported_book(item):
    """process a csv and then post about it"""
    job = item.job
    user = job.user
    if isinstance(item.book, models.Work):
        item.book = item.book.default_edition
    if not item.book:
        item.fail_reason = _("Error loading book")
        item.save()
        return
    if not isinstance(item.book, models.Edition):
        item.book = item.book.edition

    existing_shelf = models.ShelfBook.objects.filter(book=item.book,
                                                     user=user).exists()

    # shelve the book if it hasn't been shelved already
    if item.shelf and not existing_shelf:
        desired_shelf = models.Shelf.objects.get(identifier=item.shelf,
                                                 user=user)
        shelved_date = item.date_added or timezone.now()
        models.ShelfBook(book=item.book,
                         shelf=desired_shelf,
                         user=user,
                         shelved_date=shelved_date).save(priority=LOW)

    for read in item.reads:
        # check for an existing readthrough with the same dates
        if models.ReadThrough.objects.filter(
                user=user,
                book=item.book,
                start_date=read.start_date,
                finish_date=read.finish_date,
        ).exists():
            continue
        read.book = item.book
        read.user = user
        read.save()

    if job.include_reviews and (item.rating
                                or item.review) and not item.linked_review:
        # we don't know the publication date of the review,
        # but "now" is a bad guess
        published_date_guess = item.date_read or item.date_added
        if item.review:
            # pylint: disable=consider-using-f-string
            review_title = "Review of {!r} on {!r}".format(
                item.book.title,
                job.source,
            )
            review = models.Review.objects.filter(
                user=user,
                book=item.book,
                name=review_title,
                rating=item.rating,
                published_date=published_date_guess,
            ).first()
            if not review:
                review = models.Review(
                    user=user,
                    book=item.book,
                    name=review_title,
                    content=item.review,
                    rating=item.rating,
                    published_date=published_date_guess,
                    privacy=job.privacy,
                )
                review.save(software="bookwyrm", priority=LOW)
        else:
            # just a rating
            review = models.ReviewRating.objects.filter(
                user=user,
                book=item.book,
                published_date=published_date_guess,
                rating=item.rating,
            ).first()
            if not review:
                review = models.ReviewRating(
                    user=user,
                    book=item.book,
                    rating=item.rating,
                    published_date=published_date_guess,
                    privacy=job.privacy,
                )
                review.save(software="bookwyrm", priority=LOW)

        # only broadcast this review to other bookwyrm instances
        item.linked_review = review
    item.save()