From 23b8639b6e62c0ebad93b54f173a3e9065144891 Mon Sep 17 00:00:00 2001
From: "jindra12.underdark" <jindra12.underdark@gmail.com>
Date: Sun, 23 Jul 2023 02:30:36 +0200
Subject: [PATCH] Add original url algo

#210
---
 district/templates/district/district_article_page.html | 2 ++
 main/templates/main/main_article_page.html             | 1 +
 shared/models.py                                       | 4 ++++
 shared/templates/shared/article_shared_link.html       | 5 +++++
 uniweb/templates/uniweb/uniweb_article_page.html       | 2 ++
 5 files changed, 14 insertions(+)
 create mode 100644 shared/templates/shared/article_shared_link.html

diff --git a/district/templates/district/district_article_page.html b/district/templates/district/district_article_page.html
index 67b066cd..db90ced9 100644
--- a/district/templates/district/district_article_page.html
+++ b/district/templates/district/district_article_page.html
@@ -12,6 +12,8 @@
       {{ page.title }}
     </h1>
 
+    {% include "shared/article_shared_link.html" %}
+
     <div class="flex flex-col md:flex-row md:items-center">
       <div class="inline-flex divide-x flex-grow">
         <span class="pr-2">{{ page.date|date:"DATE_FORMAT" }}</span>
diff --git a/main/templates/main/main_article_page.html b/main/templates/main/main_article_page.html
index 9504db51..36dce372 100644
--- a/main/templates/main/main_article_page.html
+++ b/main/templates/main/main_article_page.html
@@ -29,6 +29,7 @@
       <div class="grid-content leading-6">
         <p class="font-condensed text-xl leading-7 mb-5">
           {{ page.perex }}
+          {% include "shared/article_shared_link.html" %}
         </p>
       </div>
       {% if page.author_page.title or page.author %}
diff --git a/shared/models.py b/shared/models.py
index 926dc37b..a3f9cfa4 100644
--- a/shared/models.py
+++ b/shared/models.py
@@ -102,6 +102,10 @@ class ArticleMixin(models.Model):
     class Meta:
         abstract = True
 
+    @property
+    def get_original_url(self):
+        return f"{self.get_parent().get_ancestors().specific().live().last().full_url}{self.slug}"
+
     @property
     def get_no_index(self):
         """
diff --git a/shared/templates/shared/article_shared_link.html b/shared/templates/shared/article_shared_link.html
new file mode 100644
index 00000000..5cb8ee8e
--- /dev/null
+++ b/shared/templates/shared/article_shared_link.html
@@ -0,0 +1,5 @@
+{% if page.shared_from %}
+    <div>
+        Tento článek byl sdílen z&nbsp;externího zdroje. Originál si můžete přečíst <a href="{{ page.get_original_url }}">zde</a>.
+    </div>
+{% endif %}
diff --git a/uniweb/templates/uniweb/uniweb_article_page.html b/uniweb/templates/uniweb/uniweb_article_page.html
index 63f02a2d..030fef10 100644
--- a/uniweb/templates/uniweb/uniweb_article_page.html
+++ b/uniweb/templates/uniweb/uniweb_article_page.html
@@ -11,6 +11,8 @@
 
     <h1 itemprop="headline" class="head-alt-md md:head-alt-lg mb-4">{{ page.title }}</h1>
 
+    {% include "shared/article_shared_link.html" %}
+
     <div class="flex flex-col md:flex-row md:items-center">
       <div class="inline-flex divide-x flex-grow my-4">
         <span class="pr-2">{{ page.date|date:"SHORT_DATE_FORMAT" }}</span>
-- 
GitLab