From 8782ae2ce9ad032227a0ddb931c6bbd7fd6946cc Mon Sep 17 00:00:00 2001
From: Julen Landa Alustiza <jlanda@fedoraproject.org>
Date: Aug 20 2020 13:02:26 +0000
Subject: [PATCH 1/2] ui/filters: new filter for humanized dates with tooltip


---

diff --git a/pagure/ui/filters.py b/pagure/ui/filters.py
index 98b2741..a0eba49 100644
--- a/pagure/ui/filters.py
+++ b/pagure/ui/filters.py
@@ -80,6 +80,21 @@ def format_ts(string):
     return arr.strftime("%Y-%m-%d %H:%M:%S %Z")
 
 
+@UI_NS.app_template_filter("humanize_tooltip")
+def humanize_with_tooltip(date):
+    """ Template filter returning a human readable time string with an
+    UTC timestamp tooltip
+    """
+    if date:
+        humanized = humanize_date(date)
+        utc = format_ts(date)
+        output = '<span title="{utc}s">{humanized}</span>'.format(
+            utc=utc, humanized=humanized
+        )
+        return output
+    return ""
+
+
 @UI_NS.app_template_filter("linkify")
 def linkify_text(text):
     """ escape all html tags with bleach, then use bleach to linkify

From 4850a7ba7de8d05d11d62db1c6defb0968f516a2 Mon Sep 17 00:00:00 2001
From: Julen Landa Alustiza <jlanda@fedoraproject.org>
Date: Aug 20 2020 13:02:26 +0000
Subject: [PATCH 2/2] pagure/templates: replace humanize with humanize_tooltip where has sense


---

diff --git a/pagure/templates/_formhelper.html b/pagure/templates/_formhelper.html
index 047cf34..714211d 100644
--- a/pagure/templates/_formhelper.html
+++ b/pagure/templates/_formhelper.html
@@ -207,7 +207,7 @@
   <div class="card-footer bg-transparent d-flex align-items-center border-0 p-0">
     {% if comment.edited_on %}
     <div class="issue_actions ml-3">
-      <small>Edited {{ comment.edited_on | humanize }} by {{ comment.editor.username }} </small>
+      <small>Edited {{ comment.edited_on | humanize_tooltip | safe }} by {{ comment.editor.username }} </small>
       </div>
     {% endif %}
 
@@ -340,7 +340,7 @@
           <a href="{{ attachment[0] }}?raw=1" title="{{attachment[2]}}" data-toggle="tooltip">{{ attachment[2] }}</a>
         </div>
         <div><small>
-          Attached {{ attachment[3] | humanize}}
+          Attached {{ attachment[3] | humanize_tooltip | safe}}
           {% if attachment[4] is not none %}
           <a href="#comment-{{ attachment[4] }}" class="pull-right">View Comment</a>
           {% else %}
diff --git a/pagure/templates/_render_issues.html b/pagure/templates/_render_issues.html
index dea0d16..2cbacbc 100644
--- a/pagure/templates/_render_issues.html
+++ b/pagure/templates/_render_issues.html
@@ -68,9 +68,7 @@
                         issue.date_created | format_datetime
                       }}">{{ issue.date_created | humanize}}</a> by <span title="{{
                       issue.user.html_title }}">{{ issue.user.user }}</span>.
-                      Modified <span data-toggle="tooltip" title="{{
-                        issue.last_updated | format_datetime
-                      }}">{{ issue.last_updated | humanize}}</span>
+                      Modified {{ issue.last_updated | humanize_tooltip | safe }}
                       </small>
                       {% if showproject %}
                       <small class="ml-auto mt-1">
diff --git a/pagure/templates/_render_pullrequests.html b/pagure/templates/_render_pullrequests.html
index 4f3d325..a8b56e7 100644
--- a/pagure/templates/_render_pullrequests.html
+++ b/pagure/templates/_render_pullrequests.html
@@ -64,38 +64,26 @@
                     {% if request.status|lower == 'merged'%}
                         <small>
                             <span class="text-info font-weight-bold">Merged</span>
-                            <span data-toggle="tooltip" title="{{
-                            request.closed_at | format_datetime
-                          }}">{{ request.closed_at | humanize}}</span>.
+                            {{ request.closed_at | humanize_tooltip | safe }}.
 
-                          Opened <span data-toggle="tooltip" title="{{
-                            request.date_created | format_datetime
-                          }}">{{ request.date_created | humanize}}</span> by <span title="{{
+                          Opened {{ request.date_created | humanize_tooltip | safe }} by <span title="{{
                           request.user.html_title }}">{{ request.user.user }}</span>.
 
                         </small>
                     {% elif request.status|lower == 'closed' %}
                         <small>
                             <span class="text-danger font-weight-bold">Cancelled</span>
-                            <span data-toggle="tooltip" title="{{
-                            request.closed_at | format_datetime
-                          }}">{{ request.closed_at | humanize}}</span>.
-                          Opened <span data-toggle="tooltip" title="{{
-                            request.date_created | format_datetime
-                          }}">{{ request.date_created | humanize}}</span> by <span title="{{
+                            {{ request.closed_at | humanize_tooltip | safe }}.
+                          Opened {{ request.date_created | humanize_tooltip | safe }} by <span title="{{
                           request.user.html_title }}">{{ request.user.user }}</span>.
                         </small>
                     {% else %}
                     <small>
                         <span class="text-success font-weight-bold">Opened</span>
-                        <span data-toggle="tooltip" title="{{
-                        request.date_created | format_datetime
-                      }}">{{ request.date_created | humanize}}</span> by <span title="{{
+                        {{ request.date_created | humanize_tooltip | safe }} by <span title="{{
                       request.user.html_title }}">{{ request.user.user }}</span>.
-                      Modified <span data-toggle="tooltip" title="{{
-                        request.updated_on | format_datetime
-                      }}">{{ request.updated_on | humanize}}</span>
-                      </small>
+                      Modified {{ request.updated_on | humanize_tooltip | safe }}
+                    </small>
                     {% endif %}
                     {% if showproject %}
                       <small class="ml-auto mt-1">
diff --git a/pagure/templates/_render_repo.html b/pagure/templates/_render_repo.html
index cfd0bb8..3ed23eb 100644
--- a/pagure/templates/_render_repo.html
+++ b/pagure/templates/_render_repo.html
@@ -56,7 +56,7 @@
       </div>
       <div class="bg-light border-top">
         <span class="pl-2">
-          <small>created {{repo.date_created|humanize}}</small>
+          <small>created {{repo.date_created|humanize_tooltip | safe}}</small>
         </span>
         <div class="pr-2 text-muted float-right text-align-right">
           <span title="Forks" data-toggle="tooltip">
diff --git a/pagure/templates/commit.html b/pagure/templates/commit.html
index 484bf49..73408ec 100644
--- a/pagure/templates/commit.html
+++ b/pagure/templates/commit.html
@@ -37,9 +37,7 @@
               {% else %}
                 Merged and Committed by {{ commit.author | author2user |safe }}
               {% endif %}
-              <span data-toggle="tooltip" title="{{ commit.commit_time | format_ts }}">
-                {{ commit.commit_time | humanize }}
-              </span>
+              {{ commit.commit_time | humanize_tooltip | safe }}
             {% else %}
               <a href="#" id="diff_list_link">{{ diff|count}} file{{'s' if diff|count > 1 }}</a>
               {% if commit.parents | length == 1 %}
@@ -47,13 +45,9 @@
               {% else %}
                 Merged by {{ commit.author | author2user |safe }}
               {% endif %}
-              <span data-toggle="tooltip" title="{{ commit.commit_time | format_ts }}">
-                {{ commit.commit_time | humanize }}
-              </span>,
+              {{ commit.commit_time | humanize_tooltip | safe }},
               Committed by {{ commit.committer | author2user |safe }}
-              <span data-toggle="tooltip" title="{{ commit.commit_time | format_ts }}">
-                {{ commit.commit_time | humanize }}
-              </span>,
+              {{ commit.commit_time | humanize_tooltip | safe }},
             {% endif%}
           </h5>
       </div>
@@ -245,7 +239,7 @@
                         flag.date_created == flag.date_updated -%}
                           Created at {% else -%} Updated at {% endif -%}
                       {{ flag.date_updated }}" class="pull-xs-right">
-                      {{ flag.date_updated | humanize }}</div>
+                      {{ flag.date_updated | humanize_tooltip | safe }}</div>
                 </div>
                 </small>
               </li>
diff --git a/pagure/templates/group_info.html b/pagure/templates/group_info.html
index 36a2f71..1e6088f 100644
--- a/pagure/templates/group_info.html
+++ b/pagure/templates/group_info.html
@@ -21,7 +21,7 @@
           <h3 class="mb-0 font-weight-bold">{{group.display_name }}</h3>
           {% if group.description %}<div>{{ group.description }}</div>{% endif %}
           <div><small>
-              formed {{ group.created |humanize }},
+              formed {{ group.created |humanize_tooltip | safe }},
               administered by <a href="{{ url_for('ui_ns.view_user', username=group.creator.user)}}">{{ group.creator.user }}</a></small>
           </div>
         </div>
diff --git a/pagure/templates/group_list.html b/pagure/templates/group_list.html
index 0bed5bc..4bcb643 100644
--- a/pagure/templates/group_list.html
+++ b/pagure/templates/group_list.html
@@ -45,7 +45,7 @@
               </div>
             </div>
             <div class="bg-light border-top py-1 px-2 mt-0">
-                <small>Formed {{ group.created |humanize }}</small>
+                <small>Formed {{ group.created |humanize_tooltip | safe }}</small>
               <div class="float-right text-muted">
                 <span title="{{projectstring(plural=True)}}" data-toggle="tooltip" class="mr-1">
                   <span class="fa {{projecticon()}} pr-1"></span>
diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html
index 2a2a5fa..2e5c51d 100644
--- a/pagure/templates/issue.html
+++ b/pagure/templates/issue.html
@@ -168,8 +168,7 @@ namespace=repo.namespace, repo=repo.name, issueid=issueid)
             </div>
             <span class="font-size-09 autogenerated-comment pl-4">{{ comment.comment | markdown | noJS | safe }}</span>
             <div class="text-muted ml-auto">
-                <span title="{{ comment.date_created | format_datetime }}">{{
-                    comment.date_created | humanize }}</span>
+              {{ comment.date_created | humanize_tooltip | safe }}
             </div>
           </div>
         {% else %}
@@ -638,7 +637,7 @@ namespace=repo.namespace, repo=repo.name, issueid=issueid)
                   namespace=pr.project.namespace,
                   requestid=pr.id) }}">#{{pr.id}}</a>
               {{ pr.status if pr.status != 'Open' else 'Last updated'
-                }} {{ pr.updated_on | humanize }}
+                }} {{ pr.updated_on | humanize_tooltip | safe }}
             </li>
             {% endfor %}
           </ul>
diff --git a/pagure/templates/releases.html b/pagure/templates/releases.html
index 3fc1a12..1ca3182 100644
--- a/pagure/templates/releases.html
+++ b/pagure/templates/releases.html
@@ -66,10 +66,10 @@
                     <i class="fa fa-fw fa-tags text-muted"></i> {{tag['tagname']}}
                     </a>
               </div>
-              <div>{{ tag['head_msg'] }} &bull; {{tag['date'] | humanize}}</div>
+              <div>{{ tag['head_msg'] }} &bull; {{tag['date'] | humanize_tooltip | safe}}</div>
             {% else %}
               <div><strong><i class="fa fa-fw fa-tags text-muted"></i> {{tag['tagname']}}</strong></div>
-              <div>{{tag['date'] | humanize}}</div>
+              <div>{{tag['date'] | humanize_tooltip | safe}}</div>
             {% endif %}
           </div>
           <div class="col-xs-auto pr-2">
diff --git a/pagure/templates/repo_info.html b/pagure/templates/repo_info.html
index 15609c6..a5f74d3 100644
--- a/pagure/templates/repo_info.html
+++ b/pagure/templates/repo_info.html
@@ -64,15 +64,15 @@
                 namespace=repo.parent.namespace)}}">
                 {{ repo.parent.fullname }}
               </a>
-              {{repo.date_created|humanize}}
+              {{repo.date_created|humanize_tooltip | safe}}
             </span>
             {% elif repo.is_fork and not repo.parent %}
             <span class="text-muted">
-                Forked from a deleted repository {{repo.date_created|humanize}}
+                Forked from a deleted repository {{repo.date_created|humanize_tooltip | safe}}
             </span>
             {% endif %}
             {% if not repo.is_fork %}
-            <div class="text-muted">Created {{repo.date_created|humanize}}</div>
+            <div class="text-muted">Created {{repo.date_created|humanize_tooltip | safe}}</div>
             <div class="text-muted">
             Maintained by
             <a href="{{ url_for('ui_ns.view_user', username=repo.user.user)}}">
@@ -284,7 +284,7 @@
                         </a>
                       </div>
                       <div class="ml-auto">
-                          <span><span class="font-weight-bold">{{ commit.author | author2avatar(20) | safe }} {{commit.author.name}}</span> committed {{ commit.commit_time|humanize }}</span>
+                          <span><span class="font-weight-bold">{{ commit.author | author2avatar(20) | safe }} {{commit.author.name}}</span> committed {{ commit.commit_time|humanize_tooltip | safe }}</span>
                       </div>
                     </div>
                     {% endif %}
diff --git a/pagure/templates/repo_master.html b/pagure/templates/repo_master.html
index 75ed514..9d96f92 100644
--- a/pagure/templates/repo_master.html
+++ b/pagure/templates/repo_master.html
@@ -74,11 +74,11 @@
                 namespace=repo.parent.namespace)}}">
                 {{ repo.parent.fullname }}
               </a>
-              {{repo.date_created|humanize}}
+              {{repo.date_created|humanize_tooltip | safe}}
             </span>
             {% elif repo.is_fork and not repo.parent %}
             <span class="text-muted">
-                Forked from a deleted repository {{repo.date_created|humanize}}
+                Forked from a deleted repository {{repo.date_created|humanize_tooltip | safe}}
             </span>
             {% endif %}
         </div>
diff --git a/pagure/templates/repo_pull_request.html b/pagure/templates/repo_pull_request.html
index 2581c5c..5eec6b8 100644
--- a/pagure/templates/repo_pull_request.html
+++ b/pagure/templates/repo_pull_request.html
@@ -396,8 +396,7 @@
             </div>
             <span class="font-size-09 autogenerated-comment pl-4">{{ comment.comment | markdown | noJS | safe }}</span>
             <div class="text-muted ml-auto">
-                <span title="{{ comment.date_created | format_datetime }}">{{
-                    comment.date_created | humanize }}</span>
+              {{ comment.date_created | humanize_tooltip | safe }}
             </div>
           </div>
         {% else %}
diff --git a/pagure/templates/user_list.html b/pagure/templates/user_list.html
index 1c1b02e..277243a 100644
--- a/pagure/templates/user_list.html
+++ b/pagure/templates/user_list.html
@@ -42,9 +42,7 @@
           </div>
 
           <div class="bg-light border-top py-1 px-2 mt-0">
-              <small>joined <span title="{{
-                user.created | format_datetime }}">{{
-                user.created | humanize }}</span></small>
+              <small>joined {{ user.created | humanize_tooltip | safe }}</small>
             <div class="float-right text-muted">
               <span title="{{projectstring(plural=True)}}" data-toggle="tooltip">
                 <span class="fa {{projecticon()}} pr-1"></span>
diff --git a/pagure/templates/userdash_activity.html b/pagure/templates/userdash_activity.html
index 043accf..bed781f 100644
--- a/pagure/templates/userdash_activity.html
+++ b/pagure/templates/userdash_activity.html
@@ -77,7 +77,7 @@
                                 {{render_reponame(log.project)}}
                                 </div>
                                 <div class="ml-auto">
-                                    {{log.date_created|humanize}}
+                                    {{log.date_created|humanize_tooltip | safe}}
                                 </div>
                             </div>
                             <div class="list-group mt-2">
@@ -99,7 +99,7 @@
                                     {{render_reponame(log.project)}}
                                 </div>
                                 <div class="ml-auto">
-                                    {{log.date_created|humanize}}
+                                    {{log.date_created|humanize_tooltip | safe}}
                                 </div>
                             </div>
                             <div class="list-group mt-2">
@@ -113,7 +113,7 @@
                                     {{render_reponame(log.project)}}
                                 </div>
                                 <div class="ml-auto">
-                                    {{log.date_created|humanize}}
+                                    {{log.date_created|humanize_tooltip | safe}}
                                 </div>
                             </div>
                         {% elif self.log_type == 'committed' %}
diff --git a/pagure/ui/filters.py b/pagure/ui/filters.py
index a0eba49..55a2ca0 100644
--- a/pagure/ui/filters.py
+++ b/pagure/ui/filters.py
@@ -88,9 +88,8 @@ def humanize_with_tooltip(date):
     if date:
         humanized = humanize_date(date)
         utc = format_ts(date)
-        output = '<span title="{utc}s">{humanized}</span>'.format(
-            utc=utc, humanized=humanized
-        )
+        output = '<span title="{utc}" data-toggle="tooltip">{humanized}</span>'
+        output = output.format(utc=utc, humanized=humanized)
         return output
     return ""
 
diff --git a/tests/test_pagure_flask_ui_fork.py b/tests/test_pagure_flask_ui_fork.py
index 8e8dce1..8efa8eb 100644
--- a/tests/test_pagure_flask_ui_fork.py
+++ b/tests/test_pagure_flask_ui_fork.py
@@ -4360,7 +4360,8 @@ More information</textarea>
             # Checking if Edited by User is there or not
             pattern = (
                 re.escape("<small>Edited ")
-                + "(just now|seconds ago)"
+                + '<span title="[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:'
+                + '[0-9]{2} UTC" data-toggle="tooltip">(just now|seconds ago)</span>'
                 + re.escape(" by pingou </small>")
             )
             self.assertIsNotNone(re.search(pattern, output_text))

