diff --git a/district/migrations/0113_merge_20230502_1854.py b/district/migrations/0112_merge_20230505_0128.py similarity index 54% rename from district/migrations/0113_merge_20230502_1854.py rename to district/migrations/0112_merge_20230505_0128.py index 991a956f3e80be8f396208a292cd85920f358a7a..1b0c257e96662a64caf082abb2df5ef2bf3a5190 100644 --- a/district/migrations/0113_merge_20230502_1854.py +++ b/district/migrations/0112_merge_20230505_0128.py @@ -1,12 +1,13 @@ -# Generated by Django 4.1.8 on 2023-05-02 16:54 +# Generated by Django 4.1.8 on 2023-05-04 23:28 from django.db import migrations class Migration(migrations.Migration): dependencies = [ + ("district", "0109_districtcustompage_mastodon_feed_and_more"), ("district", "0109_districthomepage_footer_links"), - ("district", "0112_alter_districtcenterpage_content_and_more"), + ("district", "0111_merge_20230502_1633"), ] operations = [] diff --git a/district/migrations/0112_alter_districtcenterpage_content_and_more.py b/district/migrations/0113_districtcustompage_mastodon_and_more.py similarity index 99% rename from district/migrations/0112_alter_districtcenterpage_content_and_more.py rename to district/migrations/0113_districtcustompage_mastodon_and_more.py index ffe658997b4f2f211d6f51b07abd017d3813b999..f54a941bb41ca59388aeac9180a254ff8c7c13ab 100644 --- a/district/migrations/0112_alter_districtcenterpage_content_and_more.py +++ b/district/migrations/0113_districtcustompage_mastodon_and_more.py @@ -1,20 +1,62 @@ -# Generated by Django 4.1.8 on 2023-05-02 15:09 +# Generated by Django 4.1.8 on 2023-05-04 23:46 +import django.db.models.deletion import wagtail.blocks import wagtail.contrib.table_block.blocks import wagtail.fields import wagtail.images.blocks -from django.db import migrations +from django.db import migrations, models import shared.blocks class Migration(migrations.Migration): dependencies = [ - ("district", "0111_merge_20230502_1633"), + ("shared", "0003_initial"), + ("district", "0112_merge_20230505_0128"), ] operations = [ + migrations.AddField( + model_name="districtcustompage", + name="mastodon", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="shared.mastodon", + ), + ), + migrations.AddField( + model_name="districthomepage", + name="mastodon", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="shared.mastodon", + ), + ), + migrations.AddField( + model_name="districtpeoplepage", + name="mastodon", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="shared.mastodon", + ), + ), + migrations.AddField( + model_name="districtpersonpage", + name="mastodon", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="shared.mastodon", + ), + ), migrations.AlterField( model_name="districtcenterpage", name="content", diff --git a/district/templates/district/base.html b/district/templates/district/base.html index ef15ca181c0144136e5ede21d55f839b8c7c87d9..114cf7595665c00da64f5c400c8b3ec1ada030c0 100644 --- a/district/templates/district/base.html +++ b/district/templates/district/base.html @@ -22,7 +22,7 @@ <link rel="stylesheet" href="https://styleguide.pirati.cz/2.10.x/css/styles.css"> <link href="{% static "shared/vendor/fancybox/jquery.fancybox.min.css" %}" rel="stylesheet"> <link rel="stylesheet" href="{% static "shared/css/helpers.css" %}"> - <link rel="stylesheet" href="{% static "shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.min.css" %}"> + <link rel="stylesheet" href="{% static "shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.css" %}"> {% block styles %}{% endblock %} diff --git a/senat_campaign/migrations/0012_merge_20230502_1854.py b/senat_campaign/migrations/0012_merge_20230505_0128.py similarity index 85% rename from senat_campaign/migrations/0012_merge_20230502_1854.py rename to senat_campaign/migrations/0012_merge_20230505_0128.py index a25021934bc0e7906029989c4dd2b6ed000c3c82..653e08cf2c3936ce776a175bfaf2fd588c49ce73 100644 --- a/senat_campaign/migrations/0012_merge_20230502_1854.py +++ b/senat_campaign/migrations/0012_merge_20230505_0128.py @@ -1,4 +1,4 @@ -# Generated by Django 4.1.8 on 2023-05-02 16:54 +# Generated by Django 4.1.8 on 2023-05-04 23:28 from django.db import migrations diff --git a/senat_campaign/migrations/0011_senatcampaignhomepage_mastodon_feed.py b/senat_campaign/migrations/0013_senatcampaignhomepage_mastodon_and_more.py similarity index 50% rename from senat_campaign/migrations/0011_senatcampaignhomepage_mastodon_feed.py rename to senat_campaign/migrations/0013_senatcampaignhomepage_mastodon_and_more.py index 458129520e1097913db2cf7fb6e7e5f1402b9ee8..c07e466d5f508c5d64e0ee32821f403151dd847a 100644 --- a/senat_campaign/migrations/0011_senatcampaignhomepage_mastodon_feed.py +++ b/senat_campaign/migrations/0013_senatcampaignhomepage_mastodon_and_more.py @@ -1,14 +1,26 @@ -# Generated by Django 4.1.8 on 2023-04-24 20:41 +# Generated by Django 4.1.8 on 2023-05-04 23:46 +import django.db.models.deletion from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ("senat_campaign", "0010_alter_senatcampaignhomepage_about_gallery_and_more"), + ("shared", "0003_initial"), + ("senat_campaign", "0012_merge_20230505_0128"), ] operations = [ + migrations.AddField( + model_name="senatcampaignhomepage", + name="mastodon", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="shared.mastodon", + ), + ), migrations.AddField( model_name="senatcampaignhomepage", name="mastodon_feed", diff --git a/senat_campaign/templates/senat_campaign/base.html b/senat_campaign/templates/senat_campaign/base.html index 0b2ede2d3176a0c734ed76ca752ff30d12e37409..e8ae9f5b9f6ba6faa038be2535b62d163992561b 100644 --- a/senat_campaign/templates/senat_campaign/base.html +++ b/senat_campaign/templates/senat_campaign/base.html @@ -32,7 +32,7 @@ <!-- Bootstrap CSS --> <link rel="stylesheet" href="{% static "shared/vendor/bootstrap-4.4.1/css/bootstrap.min.css" %}"> <link rel="stylesheet" href="{% static "shared/vendor/fancybox/jquery.fancybox.min.css" %}"> - <link rel="stylesheet" href="{% static "shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.min.css" %}"> + <link rel="stylesheet" href="{% static "shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.css" %}"> <!-- Styles --> <link href="{% static "senat_campaign/assets/css/style.css" %}" rel="stylesheet"> diff --git a/shared/migrations/0003_initial.py b/shared/migrations/0003_initial.py new file mode 100644 index 0000000000000000000000000000000000000000..f3b9ebba64aa2dd679a948e5946989c8deb3ad09 --- /dev/null +++ b/shared/migrations/0003_initial.py @@ -0,0 +1,83 @@ +# Generated by Django 4.1.8 on 2023-05-04 23:46 + +import django.core.serializers.json +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + initial = True + + dependencies = [ + ("shared", "0002_delete_person"), + ] + + operations = [ + migrations.CreateModel( + name="Mastodon", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "image", + models.ImageField(blank=True, null=True, upload_to="mastodon/"), + ), + ("url", models.URLField()), + ( + "user", + models.JSONField( + encoder=django.core.serializers.json.DjangoJSONEncoder, + null=True, + ), + ), + ( + "toots", + models.JSONField( + encoder=django.core.serializers.json.DjangoJSONEncoder, + null=True, + ), + ), + ("summary", models.TextField(blank=True, null=True)), + ], + options={ + "abstract": False, + }, + ), + migrations.CreateModel( + name="MastodonAttachment", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "image", + models.ImageField(blank=True, null=True, upload_to="mastodon/"), + ), + ( + "mastodon", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="shared.mastodon", + ), + ), + ], + options={ + "abstract": False, + }, + ), + ] diff --git a/shared/migrations/0004_remove_mastodon_summary.py b/shared/migrations/0004_remove_mastodon_summary.py new file mode 100644 index 0000000000000000000000000000000000000000..4185eb78d58a0950d01052e60c2d5d822933e0d2 --- /dev/null +++ b/shared/migrations/0004_remove_mastodon_summary.py @@ -0,0 +1,16 @@ +# Generated by Django 4.1.8 on 2023-05-05 00:23 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("shared", "0003_initial"), + ] + + operations = [ + migrations.RemoveField( + model_name="mastodon", + name="summary", + ), + ] diff --git a/shared/models.py b/shared/models.py index 8d395e9f7aa7ade7a60f9a593a3693d5269fe602..77ff8dca920deccae974e3a9079e7a00e4745d4c 100644 --- a/shared/models.py +++ b/shared/models.py @@ -32,6 +32,16 @@ class MastodonImage: url: str +@dataclass +class MastodonTootObject: + """ + Inner contents of mastodon tood + """ + + content: str + published: str + + @dataclass class MastodonToot: """ @@ -39,8 +49,7 @@ class MastodonToot: """ id: str - content: str - published: str + object: MastodonTootObject attachment: list[MastodonImage] @@ -80,11 +89,10 @@ class MastodonImageMixin(models.Model): abstract = True -class Mastodon(MastodonImageMixin, models.Model): +class Mastodon(MastodonImageMixin): url = models.URLField() user = models.JSONField(encoder=DjangoJSONEncoder, null=True) toots = models.JSONField(encoder=DjangoJSONEncoder, null=True) - summary = models.TextField(null=True, blank=True) def download_toots(self): """ @@ -106,26 +114,26 @@ class Mastodon(MastodonImageMixin, models.Model): toots: MastodonToots = self.download_toots() user: MastodonUser = self.download_user() - self.download_image(f"{user.preferredUsername}.jpg", user["icon"]["url"]) - - for toot in toots["orderedItems"]: - toot["published"] = parse_datetime(toot["published"]).strftime( - "%d. %m. %Y G:i" - ) - if toot["attachment"] != None: - for attachment in toot["attachment"]: - mastodon_attachment: MastodonAttachment = ( - MastodonAttachment.objects.create(mastodon=self) - ) - mastodon_attachment.download_image( - attachment["url"], - hashlib.md5(attachment["url"].encode("ascii")).hexdigest(), - ) - attachment["url"] = mastodon_attachment.image.url - - self.toots = toots.orderedItems + self.download_image(user["icon"]["url"], f'{user["preferredUsername"]}.jpg') + + if "orderedItems" in toots and toots["orderedItems"] != None: + for toot in toots["orderedItems"]: + toot["published"] = parse_datetime(toot["published"]).strftime( + "%-H:%M %-d.%-m.%Y" + ) + if "attachment" in toot["object"] and toot["object"]["attachment"] != None: + for attachment in toot["object"]["attachment"]: + mastodon_attachment: MastodonAttachment = ( + MastodonAttachment.objects.create(mastodon=self) + ) + mastodon_attachment.download_image( + attachment["url"], + hashlib.md5(attachment["url"].encode("ascii")).hexdigest(), + ) + attachment["url"] = mastodon_attachment.image.url + + self.toots = toots["orderedItems"] self.user = user - self.summary = user.summary def refresh_toots(self): try: @@ -135,7 +143,7 @@ class Mastodon(MastodonImageMixin, models.Model): logger.error("Mastodon refresh failed for %s", self.url, exc_info=True) -class MastodonAttachment(MastodonImageMixin, models.Model): +class MastodonAttachment(MastodonImageMixin): mastodon = models.ForeignKey( Mastodon, null=True, blank=True, on_delete=models.PROTECT ) @@ -151,18 +159,6 @@ class MastodonFeedMixin(models.Model): Mastodon, null=True, blank=True, on_delete=models.PROTECT ) - def clean(self): - super().clean() - try: - mastodon = ( - self.mastodon - if self.mastodon is not None - else Mastodon.objects.create(url=self.calendar_url) - ) - mastodon.parse_url() - except: - raise ValidationError("Update mastodonu se nepovedl") - def save(self, *args, **kwargs): if self.mastodon_feed: if self.mastodon: diff --git a/shared/static/shared/css/helpers.css b/shared/static/shared/css/helpers.css index ed5cbd098799e8fd382338932fd3695c12a05a6e..c30a4e3b2ae399d832cbc9dde6befeeceb863b1f 100644 --- a/shared/static/shared/css/helpers.css +++ b/shared/static/shared/css/helpers.css @@ -39,3 +39,15 @@ table caption { .content-block { clear: both; } + +.mt-container { + height: 40rem; +} + +.mt-container .toot-date { + color: #fff; +} + +.mt-container .mt-body { + white-space: normal; +} diff --git a/shared/static/shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.css b/shared/static/shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.css new file mode 100644 index 0000000000000000000000000000000000000000..08e4ed62da75c735e773948c67a138f20a76616c --- /dev/null +++ b/shared/static/shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.css @@ -0,0 +1,260 @@ +/* Mastodon embed feed timeline v3.4.2 */ +/* More info at: */ +/* https://gitlab.com/idotj/mastodon-embed-feed-timeline */ +/* Changes were made to ensure this script is safe, removed :root rules */ +/* Variables */ + +/* Main container */ +.mt-timeline { + --bg-color: #282c37; + --bg-hover-color: #313543; + --line-gray-color: #393f4f; + --content-text: #fff; + --link-color: #8c8dff; + --error-text-color: #fe6c6c; + + height: 100%; + overflow-y: auto; + position: relative; + background: var(--bg-color); + scrollbar-color: var(--bg-hover-color) rgba(0, 0, 0, 0.1); +} +.mt-timeline a:link, +.mt-timeline a:active, +.mt-timeline a { + text-decoration: none; + color: var(--link-color); +} +.mt-timeline a:hover { + text-decoration: underline; +} +.mt-timeline::-webkit-scrollbar { + width: 0.75rem; + height: 0.75rem; +} +.mt-timeline::-webkit-scrollbar-corner { + background: transparent; +} +.mt-timeline::-webkit-scrollbar-thumb { + border: 0 var(--content-text); + border-radius: 2rem; + background: var(--bg-hover-color); +} +.mt-timeline::-webkit-scrollbar-track { + border: 0 var(--content-text); + border-radius: 0; + background: rgba(0, 0, 0, 0.1); +} + +.mt-body { + padding: 1rem 1.5rem; + white-space: pre-wrap; + word-wrap: break-word; +} +.mt-body .invisible { + font-size: 0; + line-height: 0; + display: inline-block; + width: 0; + height: 0; + position: absolute; +} + +/* Toot container */ +.mt-toot { + margin: 0.25rem; + padding: 1rem 0.5rem 2rem 4rem; + position: relative; + min-height: 3.75rem; + background-color: transparent; + border-bottom: 1px solid var(--line-gray-color); +} +.mt-toot:hover, +.mt-toot:focus { + cursor: pointer; + background-color: var(--bg-hover-color); +} +.mt-toot p:last-child { + margin-bottom: 0; +} + +/* User icon */ +.mt-avatar { + position: absolute; + top: 1rem; + left: 5px; + width: 3rem; + height: 3rem; + background-color: transparent; + background-repeat: no-repeat; + background-position: 50% 50%; + background-size: contain; + background-color: var(--bg-color); + border-radius: 5px; +} +.mt-avatar-boosted { + width: 2.5rem; + height: 2.5rem; +} +.mt-avatar-booster { + width: 1.5rem; + height: 1.5rem; + top: 1.5rem; + left: 1.5rem; +} +.mt-user { + display: table; + font-weight: 600; +} +.mt-user > a { + color: var(--content-text) !important; +} + +/* Text */ +.toot-text { + margin-bottom: 0.25rem; + color: var(--content-text); +} +.toot-text .spoiler-link { + display: inline-block; + border-radius: 2px; + background-color: var(--bg-hover-color); + border: 0; + color: var(--content-text); + font-weight: 700; + font-size: 0.7rem; + padding: 0 0.35rem; + text-transform: uppercase; + line-height: 1.25rem; + cursor: pointer; + vertical-align: top; +} +.toot-text .spoiler-text { + display: none; +} +.toot-text.truncate { + display: -webkit-box; + overflow: hidden; + -webkit-line-clamp: var(--text-max-lines); + -webkit-box-orient: vertical; +} +.toot-text:not(.truncate) .ellipsis::after { + content: "..."; +} + +.mt-error { + position: absolute; + display: flex; + flex-direction: column; + height: calc(100% - 3.5rem); + width: calc(100% - 4.5rem); + justify-content: center; + align-items: center; + color: var(--error-text-color); + padding: 0.75rem; + text-align: center; +} + +/* Poll */ +.toot-poll { + margin-bottom: 0.25rem; + color: var(--content-text); +} +.toot-poll ul { + list-style: none; + padding: 0; + margin: 0; +} +.toot-poll ul li { + font-size: 0.9rem; + margin-bottom: 0.5rem; +} +.toot-poll ul li:not(:last-child) { + margin-bottom: 0.25rem; +} +.toot-poll ul li:before { + content: "◯"; + padding-right: 0.5rem; +} + +/* Medias */ +.toot-media { + overflow: hidden; + margin-bottom: 0.25rem; +} +.toot-media-preview { + position: relative; + margin-top: 0.25rem; + height: auto; + text-align: center; + width: 100%; +} +.toot-media-spoiler > img { + filter: blur(2rem); +} +.toot-media-preview a { + display: block; + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; +} + +.img-ratio14_7 { + position: relative; + padding-top: 48.95%; /* 14:7 */ + width: 100%; +} +.img-ratio14_7 > img { + width: 100%; + height: auto; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + text-align: center; +} + +/* Date */ +.toot-date { + font-size: 0.75rem; +} + +/* Loading-spinner */ +.mt-body > .loading-spinner { + position: absolute; + width: 3rem; + height: 3rem; + margin: auto; + top: calc(50% - 1.5rem); + right: calc(50% - 1.5rem); +} +.loading-spinner { + height: 100%; + background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.0' viewBox='0 0 128 128' %3E%3Cg%3E%3Cpath d='M64 128A64 64 0 0 1 18.34 19.16L21.16 22a60 60 0 1 0 52.8-17.17l.62-3.95A64 64 0 0 1 64 128z' fill='%23404040'/%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 64 64' to='360 64 64' dur='1000ms' repeatCount='indefinite'%3E%3C/animateTransform%3E%3C/g%3E%3C/svg%3E"); + background-repeat: no-repeat; + background-position: center center; + background-color: transparent; + background-size: min(2.5rem, calc(100% - 0.5rem)); +} + +/* Footer (See more link) */ +.mt-footer { + margin: 1rem auto 2rem auto; + padding: 0 2rem; + text-align: center; +} + +/* Hidden element */ +.visually-hidden { + position: absolute !important; + width: 1px !important; + height: 1px !important; + padding: 0 !important; + margin: -1px !important; + overflow: hidden !important; + clip: rect(0, 0, 0, 0) !important; + white-space: nowrap !important; + border: 0 !important; +} diff --git a/shared/static/shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.min.css b/shared/static/shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.min.css deleted file mode 100644 index 3f7f679facb7a2bb0c00cefe4cb6950124fc424a..0000000000000000000000000000000000000000 --- a/shared/static/shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.min.css +++ /dev/null @@ -1 +0,0 @@ -:root{--text-max-lines:none}:root,html[data-theme=light]{--bg-color:#fff;--bg-hover-color:#d9e1e8;--line-gray-color:#c0cdd9;--content-text:#000;--link-color:#3a3bff;--error-text-color:#8b0000}html[data-theme=dark]{--bg-color:#282c37;--bg-hover-color:#313543;--line-gray-color:#393f4f;--content-text:#fff;--link-color:#8c8dff;--error-text-color:#fe6c6c}.mt-timeline{height:100%;overflow-y:auto;position:relative;background:var(--bg-color);scrollbar-color:var(--bg-hover-color) rgba(0,0,0,.1)}.mt-timeline a,.mt-timeline a:active,.mt-timeline a:link{text-decoration:none;color:var(--link-color)}.mt-timeline a:hover{text-decoration:underline}.mt-timeline::-webkit-scrollbar{width:.75rem;height:.75rem}.mt-timeline::-webkit-scrollbar-corner{background:0 0}.mt-timeline::-webkit-scrollbar-thumb{border:0 var(--content-text);border-radius:2rem;background:var(--bg-hover-color)}.mt-timeline::-webkit-scrollbar-track{border:0 var(--content-text);border-radius:0;background:rgba(0,0,0,.1)}.mt-body{padding:1rem 1.5rem;white-space:pre-wrap;word-wrap:break-word}.mt-body .invisible{font-size:0;line-height:0;display:inline-block;width:0;height:0;position:absolute}.mt-toot{margin:.25rem;padding:1rem .5rem 2rem 4rem;position:relative;min-height:3.75rem;background-color:transparent;border-bottom:1px solid var(--line-gray-color)}.mt-toot:focus,.mt-toot:hover{cursor:pointer;background-color:var(--bg-hover-color)}.mt-toot p:last-child{margin-bottom:0}.mt-avatar{position:absolute;top:1rem;left:5px;width:3rem;height:3rem;background-color:transparent;background-repeat:no-repeat;background-position:50% 50%;background-size:contain;background-color:var(--bg-color);border-radius:5px}.mt-avatar-boosted{width:2.5rem;height:2.5rem}.mt-avatar-booster{width:1.5rem;height:1.5rem;top:1.5rem;left:1.5rem}.mt-user{display:table;font-weight:600}.mt-user>a{color:var(--content-text)!important}.toot-text{margin-bottom:.25rem;color:var(--content-text)}.toot-text .spoiler-link{display:inline-block;border-radius:2px;background-color:var(--bg-hover-color);border:0;color:var(--content-text);font-weight:700;font-size:.7rem;padding:0 .35rem;text-transform:uppercase;line-height:1.25rem;cursor:pointer;vertical-align:top}.toot-text .spoiler-text{display:none}.toot-text.truncate{display:-webkit-box;overflow:hidden;-webkit-line-clamp:var(--text-max-lines);-webkit-box-orient:vertical}.toot-text:not(.truncate) .ellipsis::after{content:"..."}.mt-error{position:absolute;display:flex;flex-direction:column;height:calc(100% - 3.5rem);width:calc(100% - 4.5rem);justify-content:center;align-items:center;color:var(--error-text-color);padding:.75rem;text-align:center}.toot-poll{margin-bottom:.25rem;color:var(--content-text)}.toot-poll ul{list-style:none;padding:0;margin:0}.toot-poll ul li{font-size:.9rem;margin-bottom:.5rem}.toot-poll ul li:not(:last-child){margin-bottom:.25rem}.toot-poll ul li:before{content:"◯";padding-right:.5rem}.toot-media{overflow:hidden;margin-bottom:.25rem}.toot-media-preview{position:relative;margin-top:.25rem;height:auto;text-align:center;width:100%}.toot-media-spoiler>img{filter:blur(2rem)}.toot-media-preview a{display:block;position:absolute;top:0;right:0;bottom:0;left:0}.img-ratio14_7{position:relative;padding-top:48.95%;width:100%}.img-ratio14_7>img{width:100%;height:auto;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);text-align:center}.toot-date{font-size:.75rem}.mt-body>.loading-spinner{position:absolute;width:3rem;height:3rem;margin:auto;top:calc(50% - 1.5rem);right:calc(50% - 1.5rem)}.loading-spinner{height:100%;background-image:url("data:image/svg+xml;charset=utf8,%3Csvg xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.0' viewBox='0 0 128 128' %3E%3Cg%3E%3Cpath d='M64 128A64 64 0 0 1 18.34 19.16L21.16 22a60 60 0 1 0 52.8-17.17l.62-3.95A64 64 0 0 1 64 128z' fill='%23404040'/%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 64 64' to='360 64 64' dur='1000ms' repeatCount='indefinite'%3E%3C/animateTransform%3E%3C/g%3E%3C/svg%3E");background-repeat:no-repeat;background-position:center center;background-color:transparent;background-size:min(2.5rem,calc(100% - .5rem))}.mt-footer{margin:1rem auto 2rem auto;padding:0 2rem;text-align:center}.visually-hidden{position:absolute!important;width:1px!important;height:1px!important;padding:0!important;margin:-1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;white-space:nowrap!important;border:0!important} diff --git a/shared/templates/shared/mastodon_feed_snippet.html b/shared/templates/shared/mastodon_feed_snippet.html index c135a0c80e3c1f853c9ea3af952cc6ab7f3390e3..443a1142d04818202dc38ed876c336e353e60cc6 100644 --- a/shared/templates/shared/mastodon_feed_snippet.html +++ b/shared/templates/shared/mastodon_feed_snippet.html @@ -1,13 +1,13 @@ {% if page.mastodon_feed %} {% if is_link %} <a href="{{ page.mastodon_feed }}" class="social-icon ">{% include "shared/mastodon_icon_snippet.html" with size=link_size invert=True %}</a> - {% else %} - {% include "shared/mastodon_feed_toots_snippet.html" with mastodon_feed=page.mastodon_feed %} + {% elif page.mastodon %} + {% include "shared/mastodon_feed_toots_snippet.html" with mastodon=page.mastodon %} {% endif %} {% elif page.root_page.mastodon_feed %} {% if is_link %} <a href="{{ page.root_page.mastodon_feed }}" class="social-icon ">{% include "shared/mastodon_icon_snippet.html" with size=link_size invert=True %}</a> - {% else %} - {% include "shared/mastodon_feed_toots_snippet.html" with mastodon_feed=page.root_page.mastodon_feed %} + {% elif page.root_page.mastodon %} + {% include "shared/mastodon_feed_toots_snippet.html" with mastodon=page.root_page.mastodon %} {% endif %} {% endif %} diff --git a/shared/templates/shared/mastodon_feed_toots_snippet.html b/shared/templates/shared/mastodon_feed_toots_snippet.html index bacfab3905b50f464f355c9f008fd85c141249ee..5e511fb5e507bcf81d7eeacead27beaf462fdf32 100644 --- a/shared/templates/shared/mastodon_feed_toots_snippet.html +++ b/shared/templates/shared/mastodon_feed_toots_snippet.html @@ -1,28 +1,30 @@ -<div class="mt-timeline"> - <div class="mt-body"> - {% for toot in mastodon_feed.mastodon.toots %} - <article class="mt-toot" aria-posinset="{{ forloop.counter }}" aria-setsize="{{ mastodon_feed.mastodon.toots|length }}"> - <a href="{{ mastodon_feed.mastodon_feed }}" class="mt-avatar" style="background-image:url({{ mastodon_feed.image.url }});"> - <span class="visually-hidden">Avatar</span> - </a> - <div class="mt-user"> - <a href="https://mastodon.online/@Chestnots" rel="nofollow noopener noreferrer" target="_blank">{{ mastodon_feed.user.preferredUsername }}</a> - </div> - <div class="toot-text"> - {{ toot.content|linebreaks }} - </div> - {% for attachment in toot.attachment %} - <div class="toot-media img-ratio14_7"> - <img src="{{ attachment.image.url }}"> +<div class="mt-container max-w-md h-80"> + <div class="mt-timeline"> + <div class="mt-body"> + {% for toot in mastodon.toots %} + <article class="mt-toot" aria-posinset="{{ forloop.counter }}" aria-setsize="{{ mastodon.toots|length }}"> + <a href="{{ mastodon.url }}" class="mt-avatar" style="background-image:url({{ mastodon.image.url }});"> + <span class="visually-hidden">Avatar</span> + </a> + <div class="mt-user"> + <a href="{{ mastodon.url }}" rel="nofollow noopener noreferrer" target="_blank">{{ mastodon.user.preferredUsername }}</a> </div> - {% endfor %} - <div class="toot-date"> - {{ toot.published }} - </div> - </article> - {% endfor %} - </div> - <div class="mt-footer"> - <a href="{{ mastodon_feed.mastodon_feed }}" class="btn">Zobrazit další tooty</a> + <div class="toot-text"> + {{ toot.object.content|striptags }} + </div> + {% for attachment in toot.object.attachment %} + <div class="toot-media img-ratio14_7"> + <img src="{{ attachment.image.url }}"> + </div> + {% endfor %} + <div class="toot-date"> + {{ toot.published }} + </div> + </article> + {% endfor %} + </div> + <div class="mt-footer"> + <a href="{{ mastodon.url }}" class="btn">Zobrazit další tooty</a> + </div> </div> </div> diff --git a/uniweb/migrations/0043_merge_20230502_1854.py b/uniweb/migrations/0043_merge_20230505_0128.py similarity index 83% rename from uniweb/migrations/0043_merge_20230502_1854.py rename to uniweb/migrations/0043_merge_20230505_0128.py index 794bb0efb5ec9e7759754e6171c8f8bcdfb26a4b..ef620715b8218b2a00bc1618e97902505677293f 100644 --- a/uniweb/migrations/0043_merge_20230502_1854.py +++ b/uniweb/migrations/0043_merge_20230505_0128.py @@ -1,4 +1,4 @@ -# Generated by Django 4.1.8 on 2023-05-02 16:54 +# Generated by Django 4.1.8 on 2023-05-04 23:28 from django.db import migrations diff --git a/uniweb/migrations/0042_uniwebhomepage_mastodon_feed_and_more.py b/uniweb/migrations/0044_uniwebhomepage_mastodon_uniwebhomepage_mastodon_feed_and_more.py similarity index 51% rename from uniweb/migrations/0042_uniwebhomepage_mastodon_feed_and_more.py rename to uniweb/migrations/0044_uniwebhomepage_mastodon_uniwebhomepage_mastodon_feed_and_more.py index 8bf97783bb57c86f032afc00d358605bb6908828..ceba567afacca6b3b473bd02203d11292ffcd60b 100644 --- a/uniweb/migrations/0042_uniwebhomepage_mastodon_feed_and_more.py +++ b/uniweb/migrations/0044_uniwebhomepage_mastodon_uniwebhomepage_mastodon_feed_and_more.py @@ -1,14 +1,26 @@ -# Generated by Django 4.1.8 on 2023-04-24 20:41 +# Generated by Django 4.1.8 on 2023-05-04 23:46 +import django.db.models.deletion from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ("uniweb", "0041_alter_uniwebflexiblepage_content_and_more"), + ("shared", "0003_initial"), + ("uniweb", "0043_merge_20230505_0128"), ] operations = [ + migrations.AddField( + model_name="uniwebhomepage", + name="mastodon", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="shared.mastodon", + ), + ), migrations.AddField( model_name="uniwebhomepage", name="mastodon_feed", @@ -18,6 +30,16 @@ class Migration(migrations.Migration): verbose_name="Mastodon feed", ), ), + migrations.AddField( + model_name="uniwebpeoplepage", + name="mastodon", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="shared.mastodon", + ), + ), migrations.AddField( model_name="uniwebpeoplepage", name="mastodon_feed", @@ -27,6 +49,16 @@ class Migration(migrations.Migration): verbose_name="Mastodon feed", ), ), + migrations.AddField( + model_name="uniwebpersonpage", + name="mastodon", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="shared.mastodon", + ), + ), migrations.AddField( model_name="uniwebpersonpage", name="mastodon_feed", diff --git a/uniweb/templates/uniweb/base.html b/uniweb/templates/uniweb/base.html index d7230186844ecbb2ba958777ba21a64934be9fb6..a050282dfb6016256b62735d6bfc014f8288df63 100644 --- a/uniweb/templates/uniweb/base.html +++ b/uniweb/templates/uniweb/base.html @@ -20,7 +20,7 @@ <link href="https://styleguide.pirati.cz/2.11.x/css/styles.css" rel="stylesheet" media="all" /> <link href="https://styleguide.pirati.cz/2.11.x/css/pattern-scaffolding.css" rel="stylesheet" media="all" /> <link href="{% static "shared/vendor/fancybox/jquery.fancybox.min.css" %}" rel="stylesheet"> - <link rel="stylesheet" href="{% static "shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.min.css" %}"> + <link rel="stylesheet" href="{% static "shared/vendor/mastodon-embed-feed-timeline/css/mastodon-timeline.css" %}"> <style type="text/css"> .head-alt-md, .head-alt-lg {