From db426d71eed978fdb80a692a22a5feef5ec795fd Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 17 Mar 2021 09:22:45 -0700 Subject: [PATCH 1/9] Fixes failed serialization of empty avatar field --- bookwyrm/activitypub/base_activity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 170bdfb9f..791502d01 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -75,7 +75,7 @@ class ActivityObject: for field in fields(self): try: value = kwargs[field.name] - if value in (None, MISSING): + if value in (None, MISSING, {}): raise KeyError() try: is_subclass = issubclass(field.type, ActivityObject) From 0d8e1f0ae26dee88c180a1ea12634d2af7232ffa Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 17 Mar 2021 09:34:20 -0700 Subject: [PATCH 2/9] Makes endponts a default field --- bookwyrm/activitypub/person.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/activitypub/person.py b/bookwyrm/activitypub/person.py index ba86b036c..f2cacc15f 100644 --- a/bookwyrm/activitypub/person.py +++ b/bookwyrm/activitypub/person.py @@ -24,7 +24,7 @@ class Person(ActivityObject): outbox: str followers: str publicKey: PublicKey - endpoints: Dict + endpoints: Dict = field(default_factory=lambda: {}) name: str = None summary: str = None icon: Image = field(default_factory=lambda: {}) From ba09377041b8a772c86f9a71b045dac68755cff0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 17 Mar 2021 13:59:16 -0700 Subject: [PATCH 3/9] Use None instead of empty dict for endpoint default value --- bookwyrm/activitypub/person.py | 2 +- bookwyrm/models/fields.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/activitypub/person.py b/bookwyrm/activitypub/person.py index f2cacc15f..f1298b927 100644 --- a/bookwyrm/activitypub/person.py +++ b/bookwyrm/activitypub/person.py @@ -24,7 +24,7 @@ class Person(ActivityObject): outbox: str followers: str publicKey: PublicKey - endpoints: Dict = field(default_factory=lambda: {}) + endpoints: Dict = None name: str = None summary: str = None icon: Image = field(default_factory=lambda: {}) diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 1ca0b377b..1bdc6c456 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -73,7 +73,7 @@ class ActivitypubFieldMixin: raise value = getattr(data, "actor") formatted = self.field_from_activity(value) - if formatted is None or formatted is MISSING: + if formatted is None or formatted is MISSING or formatted == {}: return setattr(instance, self.name, formatted) @@ -101,7 +101,7 @@ class ActivitypubFieldMixin: def field_from_activity(self, value): """ formatter to convert activitypub into a model value """ - if hasattr(self, "activitypub_wrapper"): + if value and hasattr(self, "activitypub_wrapper"): value = value.get(self.activitypub_wrapper) return value From 9a20b5dbd5d31d216c7f7456359edba2cca601f7 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 18 Mar 2021 09:00:25 -0700 Subject: [PATCH 4/9] Hide goal using database field instead of localstorage --- bookwyrm/migrations/0052_user_show_goal.py | 18 ++++++++++++++++++ bookwyrm/models/user.py | 1 + bookwyrm/templates/feed/feed.html | 4 ++-- bookwyrm/templates/snippets/goal_card.html | 7 ++++--- bookwyrm/urls.py | 2 ++ bookwyrm/views/__init__.py | 2 +- bookwyrm/views/goal.py | 10 ++++++++++ 7 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 bookwyrm/migrations/0052_user_show_goal.py diff --git a/bookwyrm/migrations/0052_user_show_goal.py b/bookwyrm/migrations/0052_user_show_goal.py new file mode 100644 index 000000000..4455e0483 --- /dev/null +++ b/bookwyrm/migrations/0052_user_show_goal.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2021-03-18 15:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0051_auto_20210316_1950'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='show_goal', + field=models.BooleanField(default=True), + ), + ] diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 440b65d3d..46f08509f 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -102,6 +102,7 @@ class User(OrderedCollectionPageMixin, AbstractUser): updated_date = models.DateTimeField(auto_now=True) last_active_date = models.DateTimeField(auto_now=True) manually_approves_followers = fields.BooleanField(default=False) + show_goal = models.BooleanField(default=True) name_field = "username" diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html index 4eb363e4a..13533f72d 100644 --- a/bookwyrm/templates/feed/feed.html +++ b/bookwyrm/templates/feed/feed.html @@ -19,9 +19,9 @@ {# announcements and system messages #} -{% if not goal and tab == 'home' %} +{% if request.user.show_goal and not goal and tab == 'home' %} {% now 'Y' as year %} -