[geany/www.geany.org] 1f8050: Show snippet TTL as forever if it is (almost) forever

Enrico Tröger git-noreply at xxxxx
Sun Jan 5 18:48:47 UTC 2014


Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Wed, 30 Oct 2013 21:55:11 UTC
Commit:      1f80507adc4023a1d4520c72c7ed37859b6b2702
             https://github.com/geany/www.geany.org/commit/1f80507adc4023a1d4520c72c7ed37859b6b2702

Log Message:
-----------
Show snippet TTL as forever if it is (almost) forever


Modified Paths:
--------------
    pastebin/templates/pastebin/snippet_details.html
    pastebin/templatetags/pastebin_tags.py

Modified: pastebin/templates/pastebin/snippet_details.html
2 files changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -14,7 +14,7 @@
 </h2>
 
 <div class="snippet-options">
-    <abbr title="Time to life">TTL:</abbr> {{ snippet.expires|timeuntil  }}
+    <abbr title="Time to life">TTL:</abbr> {{ snippet.expires|timeuntil_or_forever }}
     —
     {% if snippet.pk|in_list:request.session.snippet_list %}
     <a onclick="return confirm('Really delete this snippet?')" href="{% url 'snippet_delete' snippet.secret_id %}">Delete</a>


Modified: pastebin/templatetags/pastebin_tags.py
20 files changed, 18 insertions(+), 2 deletions(-)
===================================================================
@@ -3,18 +3,22 @@
 # it under the terms of the GNU Affero General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU Affero General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from django.template import Library
+from django.template.defaultfilters import timeuntil
+from django.utils.timezone import now
 from pastebin.highlight import pygmentize
 
+NINETY_YEARS_IN_DAYS = 32850  # 90 * 365
+
 
 register = Library()
 
@@ -27,6 +31,18 @@ def in_list(value, arg):
 
 #----------------------------------------------------------------------
 @register.filter
+def timeuntil_or_forever(snippet_expire):
+    ttl = snippet_expire - now()
+    if ttl.days > NINETY_YEARS_IN_DAYS:
+        # snippet TTL 'forever' is defined as 100 years, so if remaining TTL is more than
+        # (90 * 365) days, we most probably got a snippet with TTL 'forever'
+        return u'forever'
+    else:
+        return timeuntil(snippet_expire)
+
+
+#----------------------------------------------------------------------
+ at register.filter
 def highlight(snippet, line_count=None):
     h = pygmentize(snippet.content, snippet.lexer)
     if h:



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list