From 78b805409a2214d1e168148a00530cfb9d85c25b Mon Sep 17 00:00:00 2001 From: "jindra12.underdark" <jindra12.underdark@gmail.com> Date: Sat, 22 Apr 2023 18:09:31 +0200 Subject: [PATCH] Fix FE errors related to mastodon feeds #184 #190 --- district/models.py | 50 +++++++++++++------ district/templates/district/base.html | 24 +++++---- senate/models.py | 4 +- shared/models.py | 18 +------ .../shared/blocks/mastodon_feed_block.html | 2 +- .../shared/mastodon_feed_link_snippet.html | 2 - .../shared/mastodon_feed_snippet.html | 8 --- uniweb/models.py | 32 ++++++++---- 8 files changed, 76 insertions(+), 64 deletions(-) diff --git a/district/models.py b/district/models.py index e57ea2ae..cf218bfb 100644 --- a/district/models.py +++ b/district/models.py @@ -49,7 +49,7 @@ from shared.models import ( ArticleMixin, ExtendedMetadataHomePageMixin, ExtendedMetadataPageMixin, - HomepageMixin, + MastodonFeedMixin, MenuMixin, SubpageMixin, ) @@ -69,7 +69,7 @@ class DistrictHomePage( ExtendedMetadataHomePageMixin, MetadataPageMixin, CalendarMixin, - HomepageMixin, + MastodonFeedMixin, Page, ): ### FIELDS @@ -358,7 +358,12 @@ class DistrictArticleTag(TaggedItemBase): class DistrictArticlePage( - ArticleMixin, ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ArticleMixin, + ExtendedMetadataPageMixin, + SubpageMixin, + MastodonFeedMixin, + MetadataPageMixin, + Page, ): ### FIELDS @@ -421,7 +426,12 @@ class DistrictArticlePage( class DistrictArticlesPage( - RoutablePageMixin, ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + RoutablePageMixin, + ExtendedMetadataPageMixin, + SubpageMixin, + MastodonFeedMixin, + MetadataPageMixin, + Page, ): ### FIELDS @@ -557,7 +567,7 @@ class DistrictArticlesPage( class DistrictContactPage( - ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin, Page ): ### FIELDS @@ -601,7 +611,7 @@ class DistrictPersonTag(TaggedItemBase): class DistrictPersonPage( - ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin, Page ): ### FIELDS job = models.CharField( @@ -762,7 +772,7 @@ class DistrictPersonPage( class DistrictPeoplePage( - ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin, Page ): ### FIELDS @@ -804,7 +814,7 @@ class DistrictPeoplePage( class DistrictElectionBasePage( - ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin, Page ): ### FIELDS @@ -1125,7 +1135,7 @@ class DistrictElectionRootPage(RoutablePageMixin, Page): class DistrictInteractiveProgramPage( - ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin, Page ): ### FIELDS @@ -1172,7 +1182,7 @@ class DistrictInteractiveProgramPage( class DistrictProgramPage( - ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin, Page ): ### FIELDS @@ -1222,7 +1232,12 @@ class DistrictProgramPage( class DistrictCenterPage( - CalendarMixin, ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + CalendarMixin, + ExtendedMetadataPageMixin, + SubpageMixin, + MastodonFeedMixin, + MetadataPageMixin, + Page, ): ### FIELDS @@ -1321,7 +1336,7 @@ class DistrictCenterPage( class DistrictCrossroadPage( - ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin, Page ): ### FIELDS @@ -1379,7 +1394,7 @@ class DistrictCrossroadPage( class DistrictCustomPage( - ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin, Page ): ### FIELDS @@ -1417,7 +1432,7 @@ class DistrictCustomPage( class DistrictGeoFeatureCollectionPage( - ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin, Page ): ### FIELDS perex = models.TextField("Perex", null=True) @@ -1635,7 +1650,12 @@ def make_feature_index_cache_key(feature: "DistrictGeoFeatureDetailPage"): class DistrictGeoFeatureDetailPage( - ExtendedMetadataPageMixin, MetadataPageMixin, SubpageMixin, Page, Orderable + ExtendedMetadataPageMixin, + MetadataPageMixin, + SubpageMixin, + MastodonFeedMixin, + Page, + Orderable, ): perex = models.TextField("Perex", null=False) geojson = models.TextField( diff --git a/district/templates/district/base.html b/district/templates/district/base.html index 2128f77c..43e06b00 100644 --- a/district/templates/district/base.html +++ b/district/templates/district/base.html @@ -201,17 +201,19 @@ {% endwith %} {% endif %} - <button - class="btn btn--condensed btn--grey-500 btn--hoveractive btn--to-white text-sm ml-2 px-0" - :class="{'btn--activated': isCurrentView('mastodon')}" - @click="toggleView('mastodon')" - aria-label="Mastodon feed" - > - <div class="btn__body py-2"> - {% include "shared/mastodon_icon_snippet.html" with size="20" class_name="mr-2" %} - <span class="hidden md:block" aria-hidden="true">Mastodon feed</span> - </div> - </button> + {% if page.mastodon_feed or page.root_page.mastodon_feed %} + <button + class="btn btn--condensed btn--grey-500 btn--hoveractive btn--to-white text-sm ml-2 px-0" + :class="{'btn--activated': isCurrentView('mastodon')}" + @click="toggleView('mastodon')" + aria-label="Mastodon feed" + > + <div class="btn__body py-2"> + {% include "shared/mastodon_icon_snippet.html" with size="20" class_name="mr-2" %} + <span class="hidden md:block" aria-hidden="true">Mastodon feed</span> + </div> + </button> + {% endif %} {% if page.root_page.facebook %} <a href="{{ page.root_page.facebook }}" target="_blank" rel="noopener noreferrer" class="btn btn--inline-icon btn--condensed btn--hoveractive btn--grey-500 btn--to-brands-facebook text-sm ml-2 px-0"> diff --git a/senate/models.py b/senate/models.py index b6b95aa9..7c26a7bb 100644 --- a/senate/models.py +++ b/senate/models.py @@ -8,7 +8,7 @@ from wagtail.images.edit_handlers import FieldPanel from wagtail.models import Page from wagtailmetadata.models import MetadataPageMixin -from shared.models import HomepageMixin +from shared.models import MastodonFeedMixin from tuning import admin_help @@ -26,7 +26,7 @@ class PersonBlock(blocks.StructBlock): label = "osoba" -class SenateHomePage(MetadataPageMixin, HomepageMixin, Page): +class SenateHomePage(MetadataPageMixin, MastodonFeedMixin, Page): ### FIELDS senators = StreamField( diff --git a/shared/models.py b/shared/models.py index 7608e06b..1f6aeeb8 100644 --- a/shared/models.py +++ b/shared/models.py @@ -16,11 +16,7 @@ from shared.blocks import ( logger = logging.getLogger(__name__) -class HomepageMixin(models.Model): - """ - Use this for homepage types - """ - +class MastodonFeedMixin(models.Model): mastodon_feed = StreamField( [ ("mastodon_feed", MastodonFeedBlock()), @@ -35,19 +31,9 @@ class HomepageMixin(models.Model): abstract = True -class SubpageMixin(models.Model): +class SubpageMixin: """Must be used in class definition before MetadataPageMixin!""" - mastodon_feed = StreamField( - [ - ("mastodon_feed", MastodonFeedBlock()), - ], - verbose_name="Mastodon feed", - blank=True, - use_json_field=True, - max_length=1, - ) - @property def root_page(self): if not hasattr(self, "_root_page"): diff --git a/shared/templates/shared/blocks/mastodon_feed_block.html b/shared/templates/shared/blocks/mastodon_feed_block.html index 49677866..583fe625 100644 --- a/shared/templates/shared/blocks/mastodon_feed_block.html +++ b/shared/templates/shared/blocks/mastodon_feed_block.html @@ -4,6 +4,6 @@ allowfullscreen sandbox="allow-top-navigation allow-scripts allow-popups allow-popups-to-escape-sandbox" width="400" - height="800" + height="400" src="https://mastofeed.com/apiv2/feed?userurl={{ self.url | mastodon_url:self.user_name | urlencode:'' }}&theme=dark&size=100&header=true&replies=false&boosts=false"> </iframe> diff --git a/shared/templates/shared/mastodon_feed_link_snippet.html b/shared/templates/shared/mastodon_feed_link_snippet.html index 5368bb63..ba639792 100644 --- a/shared/templates/shared/mastodon_feed_link_snippet.html +++ b/shared/templates/shared/mastodon_feed_link_snippet.html @@ -4,6 +4,4 @@ <a href="{{ page.mastodon_feed.url | mastodon_url: page.mastodon_feed.user_name }}" class="social-icon ">{% include "shared/mastodon_icon_snippet.html" with size="20" %}</a> {% elif page.root_page.mastodon_feed %} <a href="{{ page.root_page.mastodon_feed.url | mastodon_url: page.root_page.mastodon_feed.user_name }}" class="social-icon ">{% include "shared/mastodon_icon_snippet.html" with size="20" %}</a> -{% else %} - <a href="https://mastodon.pirati.cz" class="social-icon ">{% include "shared/mastodon_icon_snippet.html" with size="20" %}</a> {% endif %} diff --git a/shared/templates/shared/mastodon_feed_snippet.html b/shared/templates/shared/mastodon_feed_snippet.html index 5c09a785..042b0085 100644 --- a/shared/templates/shared/mastodon_feed_snippet.html +++ b/shared/templates/shared/mastodon_feed_snippet.html @@ -4,12 +4,4 @@ {% include_block page.mastodon_feed %} {% elif page.root_page.mastodon_feed %} {% include_block page.root_page.mastodon_feed %} -{% else %} - <iframe - allowfullscreen - sandbox="allow-top-navigation allow-scripts allow-popups allow-popups-to-escape-sandbox" - width="400" - height="800" - src="https://mastofeed.com/api/feed?url={{ 'https://mastodon.pirati.cz' | urlencode:'' }}&theme=dark&size=100&header=true&replies=false&boosts=false"> - </iframe> {% endif %} diff --git a/uniweb/models.py b/uniweb/models.py index 9eeb6344..32aba6fb 100644 --- a/uniweb/models.py +++ b/uniweb/models.py @@ -31,13 +31,13 @@ from shared.models import ( ArticleMixin, ExtendedMetadataHomePageMixin, ExtendedMetadataPageMixin, - HomepageMixin, + MastodonFeedMixin, SubpageMixin, ) from shared.utils import make_promote_panels, strip_all_html_tags, trim_to_length from tuning import admin_help -from .blocks import PeopleGroupListBlock, PersonCustomPositionBlock, PersonUrlBlock +from .blocks import PeopleGroupListBlock, PersonUrlBlock from .constants import ( ALIGN_CHOICES, ALIGN_CSS, @@ -301,7 +301,11 @@ class UniwebArticleTag(TaggedItemBase): class UniwebHomePage( - Page, ExtendedMetadataHomePageMixin, MetadataPageMixin, CalendarMixin, HomepageMixin + Page, + ExtendedMetadataHomePageMixin, + MetadataPageMixin, + CalendarMixin, + MastodonFeedMixin, ): ### FIELDS @@ -407,7 +411,7 @@ class UniwebHomePage( class UniwebFlexiblePage( - Page, ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin + Page, ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin ): ### FIELDS @@ -424,6 +428,7 @@ class UniwebFlexiblePage( content_panels = Page.content_panels + [ FieldPanel("content"), + FieldPanel("mastodon_feed"), ] settings_panels = [] @@ -444,7 +449,7 @@ class UniwebFlexiblePage( class UniwebArticlesIndexPage( - Page, ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin + Page, ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin ): ### FIELDS @@ -484,7 +489,12 @@ class UniwebArticlesIndexPage( class UniwebArticlePage( - ArticleMixin, ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ArticleMixin, + ExtendedMetadataPageMixin, + SubpageMixin, + MastodonFeedMixin, + MetadataPageMixin, + Page, ): ### FIELDS @@ -527,7 +537,11 @@ class UniwebFormField(AbstractFormField): class UniwebFormPage( - AbstractForm, ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin + AbstractForm, + ExtendedMetadataPageMixin, + SubpageMixin, + MastodonFeedMixin, + MetadataPageMixin, ): ### FIELDS @@ -594,7 +608,7 @@ class UniwebFormPage( # Don't waste time making a new mixin for this, # we'll be doing Octopus imports within a short while. class UniwebPersonPage( - ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin, Page ): ### FIELDS job = models.CharField( @@ -754,7 +768,7 @@ class UniwebPersonPage( class UniwebPeoplePage( - ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, Page + ExtendedMetadataPageMixin, SubpageMixin, MastodonFeedMixin, MetadataPageMixin, Page ): ### FIELDS -- GitLab