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) diff --git a/bookwyrm/activitypub/person.py b/bookwyrm/activitypub/person.py index ba86b036c..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 + endpoints: Dict = None name: str = None summary: str = None icon: Image = field(default_factory=lambda: {}) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index c6dfa9fe1..edf1d9e45 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -115,7 +115,14 @@ class StatusForm(CustomForm): class EditUserForm(CustomForm): class Meta: model = models.User - fields = ["avatar", "name", "email", "summary", "manually_approves_followers"] + fields = [ + "avatar", + "name", + "email", + "summary", + "manually_approves_followers", + "show_goal", + ] help_texts = {f: None for f in fields} diff --git a/bookwyrm/migrations/0052_user_show_goal.py b/bookwyrm/migrations/0052_user_show_goal.py new file mode 100644 index 000000000..3b72ee7ac --- /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/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 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/static/js/localstorage.js b/bookwyrm/static/js/localstorage.js new file mode 100644 index 000000000..ff4027e68 --- /dev/null +++ b/bookwyrm/static/js/localstorage.js @@ -0,0 +1,27 @@ +// set javascript listeners +window.onload = function() { + // display based on localstorage vars + document.querySelectorAll('[data-hide]') + .forEach(t => setDisplay(t)); + + // update localstorage + Array.from(document.getElementsByClassName('set-display')) + .forEach(t => t.onclick = updateDisplay); +}; + +function updateDisplay(e) { + // used in set reading goal + var key = e.target.getAttribute('data-id'); + var value = e.target.getAttribute('data-value'); + window.localStorage.setItem(key, value); + + document.querySelectorAll('[data-hide="' + key + '"]') + .forEach(t => setDisplay(t)); +} + +function setDisplay(el) { + // used in set reading goal + var key = el.getAttribute('data-hide'); + var value = window.localStorage.getItem(key); + addRemoveClass(el, 'hidden', value); +} diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index 391efcc2c..a7f30660a 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -23,14 +23,6 @@ window.onload = function() { Array.from(document.getElementsByClassName('pulldown-menu')) .forEach(t => t.onclick = toggleMenu); - // display based on localstorage vars - document.querySelectorAll('[data-hide]') - .forEach(t => setDisplay(t)); - - // update localstorage - Array.from(document.getElementsByClassName('set-display')) - .forEach(t => t.onclick = updateDisplay); - // hidden submit button in a form document.querySelectorAll('.hidden-form input') .forEach(t => t.onchange = revealForm); @@ -78,24 +70,6 @@ function revealForm(e) { } -function updateDisplay(e) { - // used in set reading goal - var key = e.target.getAttribute('data-id'); - var value = e.target.getAttribute('data-value'); - window.localStorage.setItem(key, value); - - document.querySelectorAll('[data-hide="' + key + '"]') - .forEach(t => setDisplay(t)); -} - -function setDisplay(el) { - // used in set reading goal - var key = el.getAttribute('data-hide'); - var value = window.localStorage.getItem(key); - addRemoveClass(el, 'hidden', value); -} - - function toggleAction(e) { var el = e.currentTarget; var pressed = el.getAttribute('aria-pressed') == 'false'; diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html index 4eb363e4a..b7ff6e253 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 %} -