diff --git a/main/static/main/css/styles.css b/main/static/main/css/styles.css index 1df39cbcb5573c6c996829c60785c147b88f9095..2e3f994e459ceab9d5433241f5248dd028a4f6e5 100644 --- a/main/static/main/css/styles.css +++ b/main/static/main/css/styles.css @@ -2679,6 +2679,7 @@ p{ padding-top: 2rem; padding-bottom: 2rem; text-align: center; + min-height: 20rem; width: 280px; } @@ -3347,6 +3348,10 @@ p{ margin-bottom: 2.25rem; } +.mb-1{ + margin-bottom: 0.25rem; +} + .mr-1{ margin-right: 0.25rem; } @@ -3403,18 +3408,14 @@ p{ margin-top: 5rem; } -.mb-1{ - margin-bottom: 0.25rem; +.mt-8{ + margin-top: 2rem; } .mr-0{ margin-right: 0px; } -.mt-8{ - margin-top: 2rem; -} - .mt-1{ margin-top: 0.25rem; } @@ -4355,8 +4356,8 @@ a.icon-link:hover span{ margin-bottom: 0px; } - .lg\:mb-24{ - margin-bottom: 6rem; + .lg\:mt-24{ + margin-top: 6rem; } .lg\:flex{ diff --git a/main/styleguide/source/_patterns/organisms/twitter-section.mustache b/main/styleguide/source/_patterns/organisms/twitter-section.mustache index a4cef8c7b83dd5a86fdf53e30ae3b3a242189f5e..dc645e909ab855182be58426ecab37b543a35edc 100644 --- a/main/styleguide/source/_patterns/organisms/twitter-section.mustache +++ b/main/styleguide/source/_patterns/organisms/twitter-section.mustache @@ -4,7 +4,7 @@ Co právě děláme </h2> </div> - <div class="flex flex-wrap justify-center mb-8 lg:mb-24"> + <div class="flex flex-wrap justify-center"> <div class="w-full flex max-w-sm sm:max-w-xs"> {{> molecules-twitter-box }} </div> @@ -18,7 +18,7 @@ {{> molecules-twitter-box }} </div> </div> - <div class="flex justify-center"> + <div class="flex justify-center mt-8 lg:mt-24"> {{> atoms-button-animate(btn-text: "Zobrazit další") }} </div> </div> diff --git a/main/styleguide/source/css/molecules/contact_box.pcss b/main/styleguide/source/css/molecules/contact_box.pcss index 0ace8621e134db116f404fa4ad19a57513c2c303..ce651b56ba95ffc68471956b2df998a15b544d69 100644 --- a/main/styleguide/source/css/molecules/contact_box.pcss +++ b/main/styleguide/source/css/molecules/contact_box.pcss @@ -1,4 +1,5 @@ .contact-box { - @apply border border-grey-100 flex flex-col h-auto min-h-80 items-center justify-between px-16 py-8 text-center; + @apply border border-grey-100 flex flex-col h-auto items-center justify-between px-16 py-8 text-center; + min-height: 20rem; width: 280px; } diff --git a/main/templates/main/blocks/twitter_block.html b/main/templates/main/blocks/twitter_block.html index f6fdd44832e43239481c61efc8401c9abe64f67f..acd9f668abca5d609e750d80eecf32cb99243ffe 100644 --- a/main/templates/main/blocks/twitter_block.html +++ b/main/templates/main/blocks/twitter_block.html @@ -1,49 +1,50 @@ <div class="container--wide mx-auto mb-8 lg:mb-16"> <div class="flex flex-wrap justify-center items-center"> - <h2 class="w-full head-7xl xl:text-center mb-6 xl:mb-28"> - {{ self.title }} - </h2> + <h2 class="w-full head-7xl xl:text-center mb-6 xl:mb-28"> + {{ self.title }} + </h2> </div> - <div id="tweetsList"> - {% include 'main/includes/twitter_widget.html' with tweet_list=tweet_list %} + <div id="tweetsList"> + {% include 'main/includes/twitter_widget.html' with tweet_list=tweet_list %} + </div> + {% if show_next_tweet %} + <div class="flex justify-center mt-8 lg:mt-24"> + <a + onclick="showMoreTweets(event, this)" + href="#" + data-url="{{ page_url }}?page=" + data-page="2" + class="btn btn__slide__wrap" + > + <span class="btn text-sm bg-black text-white px-1 lg:text-base"> + Zobrazit starší + </span> + <span class="btn text-sm bg-white text-black px1 lg:text-base"> + Zobrazit starší + </span> + </a> </div> - {% if show_next_tweet %} - <div class="text-center"> - <a - onclick="showMoreTweets(event, this)" - href="#" - data-url="{{ page_url }}?page=" - data-page="2" - class="btn btn__slide__wrap"> - <span class="btn text-sm bg-black text-white px-1 lg:text-base"> - Zobrazit starší - </span> - <span class="btn text-sm bg-white text-black px1 lg:text-base"> - Zobrazit starší - </span> - </a> - </div> - {% endif %} + {% endif %} </div> + <script type="text/javascript"> - function showMoreTweets(event, tweet) { - event.preventDefault() - let btn = tweet; - let tweetsList = document.getElementById('tweetsList'); + async function showMoreTweets(event, btn) { + event.preventDefault() + const tweetsList = document.getElementById('tweetsList'); + + const url = btn.getAttribute('data-url') + btn.getAttribute('data-page') + const response = await fetch(url, { + method: "GET", + headers: { + "X-Requested-With": "XMLHttpRequest", + }, + }) + const data = await response.json() + + tweetsList.innerHTML += data.html; + if (btn.getAttribute('data-page') === data.last_page) { btn.hide() } - let url = tweet.getAttribute('data-url') + tweet.getAttribute('data-page') - fetch(url, { - method: "GET", - headers: { - "X-Requested-With": "XMLHttpRequest", - }, - }).then((response) => response.json()) - .then((data) => { - tweetsList.innerHTML += data.html; - if (tweet.getAttribute('data-page') === data.last_page) - btn.hide(); - let dataPage = parseInt(tweet.getAttribute('data-page')) + 1 - tweet.setAttribute('data-page', dataPage) - }); - } + const dataPage = parseInt(btn.getAttribute('data-page')) + 1 + btn.setAttribute('data-page', dataPage) + } </script> diff --git a/main/templates/main/includes/twitter_widget.html b/main/templates/main/includes/twitter_widget.html index 78d1b6ecef7f9cc1c50b5d3b5ea3ffb76eb1ceac..99d46e5f39a8e9ae003400464304d25937d92382 100644 --- a/main/templates/main/includes/twitter_widget.html +++ b/main/templates/main/includes/twitter_widget.html @@ -1,29 +1,29 @@ -<div class="flex flex-wrap justify-center mb-8 lg:mb-24"> -{% for tweet in tweet_list %} - <div class="w-full flex max-w-sm sm:max-w-xs"> - <div class="mb-5 p-4 flex flex-col items-center text-center border border-grey-100 sm:mb-0"> - <div class="flex flex-row sm:flex-col items-center"> - <img - class="rounded-full shadow-sm w-12 mb-2" - src="{{ tweet.author_img_url }}" - alt="user image" - /> - <div class="flex flex-col sm:flex-col"> - <h5 class="font-alt text-xl mb-2 sm:text-base"> - {{ tweet.author_name }} - </h5> - <small class="mb-4 text-turquoise-400"> - {{ tweet.author_username }} - </small> - </div> +<div class="flex flex-wrap justify-center"> + {% for tweet in tweet_list %} + <div class="w-full flex max-w-sm sm:max-w-xs"> + <div class="mb-5 p-4 flex flex-col items-center text-center border border-grey-100 sm:mb-0"> + <div class="flex flex-row sm:flex-col items-center"> + <img + class="rounded-full shadow-sm w-12 mb-2" + src="{{ tweet.author_img_url }}" + alt="user image" + /> + <div class="flex flex-col sm:flex-col"> + <h5 class="font-alt text-xl mb-2 sm:text-base"> + {{ tweet.author_name }} + </h5> + <small class="mb-4 text-turquoise-400"> + {{ tweet.author_username }} + </small> </div> - <p class="text-small sm:text-base leading-6 mb-2"> - {{ tweet.text }} - </p> - <a href="twitter.com/{{ tweet.author_username }}" class="hover:no-underline"> - <i class="ico--twitter text-turquoise-400 text-3xl sm:text-xl"></i> - </a> + </div> + <p class="text-small sm:text-base leading-6 mb-2"> + {{ tweet.text }} + </p> + <a href="twitter.com/{{ tweet.author_username }}" class="hover:no-underline"> + <i class="ico--twitter text-turquoise-400 text-3xl sm:text-xl"></i> + </a> + </div> </div> - </div> -{% endfor %} + {% endfor %} </div> diff --git a/twitter_utils/services.py b/twitter_utils/services.py index adf44b29aec691fa0719417bce31e76c8479633b..95d987484c2ff01683585fe6c31a08098430f14a 100644 --- a/twitter_utils/services.py +++ b/twitter_utils/services.py @@ -6,7 +6,7 @@ from django.utils import timezone from tweepy import Client from tweepy.errors import BadRequest -from main.models import MainHomePage +from main.models import MainHomePage, MainPersonPage from .models import Tweet @@ -48,6 +48,7 @@ class TweetDownloadService: """ tweets_response = self.client.get_users_tweets( user_id, + exclude=["retweets"], expansions=["author_id", "entities.mentions.username"], max_results=100, start_time=timezone.now() - timedelta(days=self.days_back), @@ -59,15 +60,25 @@ class TweetDownloadService: def get_user_list_data(self) -> list["User"]: twitter_usernames_block = MainHomePage.objects.first().twitter_usernames + person_username_list = ( + MainPersonPage.objects.filter(twitter_username__isnull=False) + .values_list("twitter_username", flat=True) + .distinct() + ) + homepage_username_list = [ + username_data["value"] for username_data in twitter_usernames_block.raw_data + ] + username_list = [*person_username_list, *homepage_username_list] + user_data_list = [] - for username_data in twitter_usernames_block.raw_data: + for username in username_list: try: - user_data_list.append(self.get_user_response(username_data["value"])) + user_data_list.append(self.get_user_response(username)) except BadRequest: logger.error( "Cannot download tweets for the username", - extra={"username": username_data["value"]}, + extra={"username": username}, ) return user_data_list