Skip to content
Snippets Groups Projects
Commit 66a8fec6 authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

finish instagram display for people

parent dcaa9ec2
No related branches found
No related tags found
3 merge requests!787Release,!743Add Redmine datasets to charts, Instagram feed to homepage,!742Add Instagram feed to homepage
......@@ -27,9 +27,7 @@ class InstagramDownloadService:
def get_user_info_list(self) -> list[str]:
access_block = MainHomePage.objects.first().instagram_access
# TODO - Individual users' instagram info
return [
homepage_access_list = [
(
block["value"]["name"],
block["value"]["access_token"]
......@@ -37,6 +35,20 @@ class InstagramDownloadService:
for block in access_block.raw_data
]
people_access_list = []
for people_page in MainPersonPage.objects.all():
people_access_list += [
(
block["value"]["name"],
block["value"]["access_token"]
)
for block in people_page.instagram_access.raw_data
]
# Remove duplicates
return list({*people_access_list, *homepage_access_list})
def download_remote_image(self, image_url) -> (str, File):
try:
response = self.session.get(image_url)
......
# Generated by Django 4.1.6 on 2023-04-06 12:36
from django.db import migrations
import wagtail.blocks
import wagtail.fields
class Migration(migrations.Migration):
dependencies = [
('main', '0051_remove_mainhomepage_twitter_usernames_and_more'),
]
operations = [
migrations.RemoveField(
model_name='mainpersonpage',
name='instagram_username',
),
migrations.RemoveField(
model_name='mainpersonpage',
name='twitter_username',
),
migrations.AddField(
model_name='mainpersonpage',
name='instagram_access',
field=wagtail.fields.StreamField([('instagram_access', wagtail.blocks.StructBlock([('name', wagtail.blocks.CharBlock(label='Zobrazované jméno')), ('username', wagtail.blocks.CharBlock(help_text='Např. pirati.cz, bez @ na začátku!', label='Username')), ('access_token', wagtail.blocks.CharBlock(label='Přístupový token'))]))], blank=True, use_json_field=True, verbose_name='Synchronizace s Instagramem'),
),
]
......@@ -698,19 +698,13 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
perex = models.TextField()
text = RichTextField()
twitter_username = models.CharField(
"Uživatelské jméno na Twitteru pro získání příspěvků",
blank=True,
null=True,
max_length=32,
help_text="Uživatelské jméno zadejte bez @ na začátku",
)
instagram_username = models.CharField(
"Uživatelské jméno na Instagramu pro získání příspěvků",
instagram_access = StreamField(
[
("instagram_access", blocks.InstagramAccessBlock()),
],
verbose_name="Synchronizace s Instagramem",
blank=True,
null=True,
max_length=32,
help_text="Uživatelské jméno zadejte bez @ na začátku",
use_json_field=True,
)
social_links = StreamField(
......@@ -747,7 +741,7 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
FieldPanel("after_name"),
FieldPanel("position"),
FieldPanel("perex"),
FieldPanel("twitter_username"),
FieldPanel("instagram_access"),
FieldPanel("text"),
FieldPanel("email"),
FieldPanel("phone"),
......@@ -757,12 +751,21 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
def get_context(self, request):
context = super().get_context(request)
context["article_page_list"] = MainArticlePage.objects.filter(
author_page=self.id
)
context["tweet_list"] = Tweet.objects.username(self.twitter_username).order_by(
"-twitter_id"
if len(self.instagram_access.raw_data) != 0:
context["instagram_post_list"] = (
InstagramPost.
objects.
filter(
author_username=self.instagram_access.raw_data[0]["value"]["username"]
).
order_by("-timestamp")
)[:20]
return context
### OTHERS
......
This diff is collapsed.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -55,55 +55,51 @@
</div>
</section>
</div>
{% if tweet_list %}
<section class="grid-container no-max mr-0 person-twitter-section mb-4 xl:mb-20">
{% if instagram_post_list %}
<section class="grid-container no-max mr-0 person-instagram-section mb-4 xl:mb-20">
<div class="grid-content-with-right-side">
<h2 class="head-4xl text-left">
Aktuálně na Twitteru
Aktuálně na Instagramu
</h2>
<div class="__js-root twitter-carousel-root xl:max-w-[1145px]">
<ui-twitter-carousel>
{% for tweet in tweet_list %}
<div class="flex max-w-sm max-w-xs w-full h-full">
<div class="__js-root instagram-carousel-root xl:max-w-[1145px]">
<ui-instagram-carousel>
{% for post in instagram_post_list %}
<div class="flex max-w-sm max-w-xs w-full h-[20rem]">
<a
href="https://twitter.com/{{ tweet.author_username }}"
class="group mb-5 h-full w-full flex flex-col align-center overflow-hidden text-center border border-grey-100 relative sm:mb-0 hover:no-underline"
href="{{ post.url }}"
class="group h-full w-full flex flex-col align-center overflow-hidden text-center border border-grey-100 relative hover:no-underline"
>
<div class="md:min-h-[21rem] p-4{% if tweet.image %} opacity-0 group-focus:opacity-100 group-hover:opacity-100 duration-150 z-10{% endif %}">
<div class="md:min-h-[20rem] p-4 opacity-0 group-focus:opacity-100 group-hover:opacity-100 duration-150 z-10">
<div class="flex flex-col items-center">
<div class="mb-4 flex items-center justify-between xl:flex-col gap-3">
<img
class="rounded-full shadow-sm w-12"
src="{{ tweet.author_img.url }}"
alt="Profilový obrázek"
>
<div class="flex flex-col">
<h5 class="font-alt text-xl mb-1 text-left sm:text-center">
{{ tweet.author_name }}
<h5 class="font-alt text-xl mt-3 mb-1 text-left sm:text-center">
{{ post.author_name }}
</h5>
<small class="text-turquoise-400 text-left sm:text-center">
{{ tweet.author_username }}
<small class="text-brands-instagram text-left sm:text-center">
@{{ post.author_username }}
</small>
</div>
</div>
<p class="text-small sm:text-base leading-6 mb-2">
{{ tweet.text|truncatechars:240 }}
{{ post.caption }}
</p>
</div>
</div>
<div class="flex-shrink-0 h-10 mt-auto">
<i class="ico--twitter text-turquoise-400 text-3xl sm:text-xl"></i>
<div class="absolute inset-0 flex-shrink-0 z-0 duration-150 group-focus:blur-lg group-focus:opacity-25 group-hover:blur-lg group-hover:opacity-25">
<div class="relative">
<div class="absolute left-4 top-4 bg-white rounded-lg p-1.5 drop-shadow-md">
<i class="ico--instagram text-brands-instagram text-2xl"></i>
</div>
{% if tweet.image %}
<div class="absolute inset-0 flex-shrink-0 z-0 duration-150 group-focus:blur-lg group-focus:opacity-25 group-hover:blur-lg group-hover:opacity-25">
<img src="{{ tweet.image.url }}"
class="tweet-image"
alt="Obrázek Tweetu"
<img
class="h-[20rem] object-cover"
src="{{ post.image.url }}"
alt="Obrázek v Instagramovém postu, popis „{{ post.caption }}“"
>
</div>
{% endif %}
</div>
</a>
</div>
{% endfor %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment