diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index a34eb3019..3172ea797 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -5,6 +5,7 @@ from dateutil import parser import pytz import requests from requests import HTTPError +from urllib3.exceptions import RequestError from django.db import transaction @@ -298,7 +299,7 @@ def get_data(url): 'Accept': 'application/json; charset=utf-8', }, ) - except ConnectionError: + except RequestError: raise ConnectorException() if not resp.ok: resp.raise_for_status() diff --git a/bookwyrm/incoming.py b/bookwyrm/incoming.py index e137aafa7..7507ee5b5 100644 --- a/bookwyrm/incoming.py +++ b/bookwyrm/incoming.py @@ -204,7 +204,7 @@ def handle_follow_reject(activity): def handle_create(activity): ''' someone did something, good on them ''' if activity['object'].get('type') not in \ - ['Note', 'Comment', 'Quotation', 'Review']: + ['Note', 'Comment', 'Quotation', 'Review', 'GeneratedNote']: # if it's an article or unknown type, ignore it return diff --git a/bookwyrm/migrations/0061_auto_20201030_2157.py b/bookwyrm/migrations/0061_auto_20201030_2157.py new file mode 100644 index 000000000..750b37639 --- /dev/null +++ b/bookwyrm/migrations/0061_auto_20201030_2157.py @@ -0,0 +1,17 @@ +# Generated by Django 3.0.7 on 2020-10-30 21:57 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0060_auto_20201030_2010'), + ] + + operations = [ + migrations.RenameModel( + old_name='GeneratedStatus', + new_name='GeneratedNote', + ), + ] diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py index 47ae177bb..18ddb8041 100644 --- a/bookwyrm/models/__init__.py +++ b/bookwyrm/models/__init__.py @@ -6,7 +6,7 @@ from .book import Book, Work, Edition, Author from .connector import Connector from .relationship import UserFollows, UserFollowRequest, UserBlocks from .shelf import Shelf, ShelfBook -from .status import Status, GeneratedStatus, Review, Comment, Quotation +from .status import Status, GeneratedNote, Review, Comment, Quotation from .status import Favorite, Boost, Notification, ReadThrough from .tag import Tag from .user import User @@ -16,5 +16,5 @@ from .import_job import ImportJob, ImportItem from .site import SiteSettings, SiteInvite, PasswordReset cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass) -activity_models = {c[0]: c[1].activity_serializer for c in cls_members \ +activity_models = {c[0]: c[1] for c in cls_members \ if hasattr(c[1], 'activity_serializer')} diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index d5f4a8993..7d3cb344b 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -1,4 +1,5 @@ ''' base model with default fields ''' +from datetime import datetime from base64 import b64encode from dataclasses import dataclass from typing import Callable @@ -69,6 +70,8 @@ class ActivitypubMixin: value = getattr(self, mapping.model_key) if hasattr(value, 'remote_id'): value = value.remote_id + if isinstance(value, datetime): + value = value.isoformat() fields[mapping.activity_key] = mapping.activity_formatter(value) if pure: diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index d6b48b57e..03b2c1f8b 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -3,7 +3,6 @@ import re from django.db import models from django.utils import timezone -from django.utils.http import http_date from model_utils.managers import InheritanceManager from bookwyrm import activitypub @@ -63,16 +62,8 @@ class Book(ActivitypubMixin, BookWyrmModel): ActivityMapping('id', 'remote_id'), ActivityMapping('authors', 'ap_authors'), - ActivityMapping( - 'first_published_date', - 'first_published_date', - activity_formatter=lambda d: http_date(d.timestamp()) if d else None - ), - ActivityMapping( - 'published_date', - 'published_date', - activity_formatter=lambda d: http_date(d.timestamp()) if d else None - ), + ActivityMapping('first_published_date', 'first_published_date'), + ActivityMapping('published_date', 'published_date'), ActivityMapping('title', 'title'), ActivityMapping('sort_title', 'sort_title'), diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 533868e80..8798589f3 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -1,6 +1,5 @@ ''' models for storing different kinds of Activities ''' from django.utils import timezone -from django.utils.http import http_date from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models from model_utils.managers import InheritanceManager @@ -62,11 +61,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): ActivityMapping('id', 'remote_id'), ActivityMapping('url', 'remote_id'), ActivityMapping('inReplyTo', 'reply_parent'), - ActivityMapping( - 'published', - 'published_date', - activity_formatter=lambda d: http_date(d.timestamp()) - ), + ActivityMapping('published', 'published_date'), ActivityMapping('attributedTo', 'user'), ActivityMapping('to', 'ap_to'), ActivityMapping('cc', 'ap_cc'), @@ -116,13 +111,13 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): return activitypub.Tombstone( id=self.remote_id, url=self.remote_id, - deleted=http_date(self.deleted_date.timestamp()), - published=http_date(self.deleted_date.timestamp()), + deleted=self.deleted_date.isoformat(), + published=self.deleted_date.isoformat() ).serialize() return ActivitypubMixin.to_activity(self, **kwargs) -class GeneratedStatus(Status): +class GeneratedNote(Status): ''' these are app-generated messages about user activity ''' @property def ap_pure_content(self): diff --git a/bookwyrm/status.py b/bookwyrm/status.py index 258734b39..b373bec54 100644 --- a/bookwyrm/status.py +++ b/bookwyrm/status.py @@ -21,7 +21,7 @@ def create_generated_note(user, content, mention_books=None): parser.feed(content) content = parser.get_output() - status = models.GeneratedStatus.objects.create( + status = models.GeneratedNote.objects.create( user=user, content=content, ) diff --git a/bookwyrm/templates/shelf.html b/bookwyrm/templates/shelf.html index 2c49f0024..962795437 100644 --- a/bookwyrm/templates/shelf.html +++ b/bookwyrm/templates/shelf.html @@ -1,19 +1,22 @@ {% extends 'layout.html' %} +{% load fr_display %} {% block content %} +{% include 'user_header.html' with user=user %}