From b0707c86f210e72f21095cfa6c5efc1f1f18f47d Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Wed, 2 Feb 2011 09:15:39 +0000 Subject: [PATCH] Fix the exception path, also move app specific templates into the app folder --- .../templates}/eve_api/add.html | 0 .../templates}/eve_api/character.html | 0 .../templates}/eve_api/character_list.html | 0 .../templates}/eve_api/corporation.html | 0 .../templates}/eve_api/log.html | 0 eve_api/templatetags/__init__.py | 0 eve_api/templatetags/naturaltimediff.py | 33 +++++++++++++++++++ eve_api/views.py | 2 +- 8 files changed, 34 insertions(+), 1 deletion(-) rename {templates => eve_api/templates}/eve_api/add.html (100%) rename {templates => eve_api/templates}/eve_api/character.html (100%) rename {templates => eve_api/templates}/eve_api/character_list.html (100%) rename {templates => eve_api/templates}/eve_api/corporation.html (100%) rename {templates => eve_api/templates}/eve_api/log.html (100%) create mode 100644 eve_api/templatetags/__init__.py create mode 100644 eve_api/templatetags/naturaltimediff.py diff --git a/templates/eve_api/add.html b/eve_api/templates/eve_api/add.html similarity index 100% rename from templates/eve_api/add.html rename to eve_api/templates/eve_api/add.html diff --git a/templates/eve_api/character.html b/eve_api/templates/eve_api/character.html similarity index 100% rename from templates/eve_api/character.html rename to eve_api/templates/eve_api/character.html diff --git a/templates/eve_api/character_list.html b/eve_api/templates/eve_api/character_list.html similarity index 100% rename from templates/eve_api/character_list.html rename to eve_api/templates/eve_api/character_list.html diff --git a/templates/eve_api/corporation.html b/eve_api/templates/eve_api/corporation.html similarity index 100% rename from templates/eve_api/corporation.html rename to eve_api/templates/eve_api/corporation.html diff --git a/templates/eve_api/log.html b/eve_api/templates/eve_api/log.html similarity index 100% rename from templates/eve_api/log.html rename to eve_api/templates/eve_api/log.html diff --git a/eve_api/templatetags/__init__.py b/eve_api/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/eve_api/templatetags/naturaltimediff.py b/eve_api/templatetags/naturaltimediff.py new file mode 100644 index 0000000..657155a --- /dev/null +++ b/eve_api/templatetags/naturaltimediff.py @@ -0,0 +1,33 @@ +from django import template + +register = template.Library() + +MOMENT = 120 # duration in seconds within which the time difference + # will be rendered as 'a moment ago' + +@register.filter +def naturaltimediff(value): + """ + Finds the difference between the datetime value given and now() + and returns appropriate humanize form + """ + + from datetime import datetime + + if isinstance(value, datetime): + delta = datetime.now() - value + if delta.days > 6: + return value.strftime("%b %d") # May 15 + if delta.days > 1: + return value.strftime("%A") # Wednesday + elif delta.days == 1: + return 'yesterday' # yesterday + elif delta.seconds > 3600: + return str(delta.seconds / 3600 ) + ' hours ago' # 3 hours ago + elif delta.seconds > MOMENT: + return str(delta.seconds/60) + ' minutes ago' # 29 minutes ago + else: + return 'a moment ago' # a moment ago + return defaultfilters.date(value) + else: + return str(value) diff --git a/eve_api/views.py b/eve_api/views.py index 721e9c7..02a2017 100644 --- a/eve_api/views.py +++ b/eve_api/views.py @@ -10,7 +10,7 @@ from django.http import Http404 from django.core import serializers from eve_proxy.models import ApiAccessLog -from eve_api.api_exceptions import DocumentRetrievalError +from eve_proxy.exceptions import DocumentRetrievalError from eve_api.forms import EveAPIForm from eve_api.models import EVEAccount, EVEPlayerCharacter, EVEPlayerCorporation from eve_api.tasks import import_apikey_result