|
|
@@ -34,7 +34,6 @@ from django.template.loader import render_to_string as django_render_to_string
|
|
|
from django.template import RequestContext
|
|
|
from django.db import models
|
|
|
from desktop.lib import django_mako
|
|
|
-from django.core import urlresolvers
|
|
|
|
|
|
import desktop.conf
|
|
|
import desktop.lib.thrift_util
|
|
|
@@ -293,9 +292,9 @@ def extract_field_data(field):
|
|
|
|
|
|
def get_app_nice_name(app_name):
|
|
|
try:
|
|
|
- return desktop.appmanager.get_desktop_module(app_name).settings.NICE_NAME
|
|
|
+ return desktop.appmanager.get_desktop_module(app_name).settings.NICE_NAME
|
|
|
except:
|
|
|
- return app_name
|
|
|
+ return app_name
|
|
|
|
|
|
class StructuredException(Exception):
|
|
|
"""
|
|
|
@@ -342,11 +341,7 @@ class PopupException(Exception):
|
|
|
self.detail = detail
|
|
|
|
|
|
def response(self, request):
|
|
|
- return render("popup_error.mako", request,
|
|
|
- dict(title=self.title, message=self.message, detail=self.detail, request=request))
|
|
|
-
|
|
|
- def html(self):
|
|
|
- return django_mako.render_to_string('popup_error.mako',
|
|
|
+ return render("popup_error.mako", request,
|
|
|
dict(title=self.title, message=self.message, detail=self.detail, request=request))
|
|
|
|
|
|
|
|
|
@@ -405,84 +400,84 @@ def reverse_with_get(view, args=None, kwargs=None, get=None):
|
|
|
return url
|
|
|
|
|
|
def humanize_duration(seconds, abbreviate=False):
|
|
|
- d = datetime.datetime.fromtimestamp(0)
|
|
|
- now = datetime.datetime.fromtimestamp(seconds)
|
|
|
- return timesince(d, now, abbreviate)
|
|
|
+ d = datetime.datetime.fromtimestamp(0)
|
|
|
+ now = datetime.datetime.fromtimestamp(seconds)
|
|
|
+ return timesince(d, now, abbreviate)
|
|
|
|
|
|
def timesince(d=None, now=None, abbreviate=False):
|
|
|
- """
|
|
|
- Takes two datetime objects and returns the time between d and now
|
|
|
- as a nicely formatted string, e.g. "10 minutes". If d occurs after now,
|
|
|
- then "0 seconds" is returned. If abbreviate is True, it truncates values to,
|
|
|
- for example, "10m" or "4m 30s". Alternately it can take a second value
|
|
|
- and return the proper count.
|
|
|
-
|
|
|
- Units used are years, months, weeks, days, hours, minutes, and seconds.
|
|
|
- Microseconds are ignored. Up to two adjacent units will be
|
|
|
- displayed. For example, "2 weeks, 3 days" and "1 year, 3 months" are
|
|
|
- possible outputs, but "2 weeks, 3 hours" and "1 year, 5 days" are not.
|
|
|
-
|
|
|
- Adapted from the timesince filter in Django:
|
|
|
- http://docs.djangoproject.com/en/dev/ref/templates/builtins/#timesince
|
|
|
- """
|
|
|
-
|
|
|
+ """
|
|
|
+ Takes two datetime objects and returns the time between d and now
|
|
|
+ as a nicely formatted string, e.g. "10 minutes". If d occurs after now,
|
|
|
+ then "0 seconds" is returned. If abbreviate is True, it truncates values to,
|
|
|
+ for example, "10m" or "4m 30s". Alternately it can take a second value
|
|
|
+ and return the proper count.
|
|
|
+
|
|
|
+ Units used are years, months, weeks, days, hours, minutes, and seconds.
|
|
|
+ Microseconds are ignored. Up to two adjacent units will be
|
|
|
+ displayed. For example, "2 weeks, 3 days" and "1 year, 3 months" are
|
|
|
+ possible outputs, but "2 weeks, 3 hours" and "1 year, 5 days" are not.
|
|
|
+
|
|
|
+ Adapted from the timesince filter in Django:
|
|
|
+ http://docs.djangoproject.com/en/dev/ref/templates/builtins/#timesince
|
|
|
+ """
|
|
|
+
|
|
|
+ if abbreviate:
|
|
|
+ chunks = (
|
|
|
+ (60 * 60 * 24 * 365, lambda n: 'y'),
|
|
|
+ (60 * 60 * 24 * 30, lambda n: 'm'),
|
|
|
+ (60 * 60 * 24 * 7, lambda n : 'w'),
|
|
|
+ (60 * 60 * 24, lambda n : 'd'),
|
|
|
+ (60 * 60, lambda n: 'h'),
|
|
|
+ (60, lambda n: 'm'),
|
|
|
+ (1, lambda n : 's'),
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ chunks = (
|
|
|
+ (60 * 60 * 24 * 365, lambda n: ungettext('year', 'years', n)),
|
|
|
+ (60 * 60 * 24 * 30, lambda n: ungettext('month', 'months', n)),
|
|
|
+ (60 * 60 * 24 * 7, lambda n : ungettext('week', 'weeks', n)),
|
|
|
+ (60 * 60 * 24, lambda n : ungettext('day', 'days', n)),
|
|
|
+ (60 * 60, lambda n: ungettext('hour', 'hours', n)),
|
|
|
+ (60, lambda n: ungettext('minute', 'minutes', n)),
|
|
|
+ (1, lambda n : ungettext('second', 'seconds', n)),
|
|
|
+ )
|
|
|
+
|
|
|
+ # Convert datetime.date to datetime.datetime for comparison.
|
|
|
+ if not isinstance(d, datetime.datetime):
|
|
|
+ d = datetime.datetime(d.year, d.month, d.day)
|
|
|
+ if now and not isinstance(now, datetime.datetime):
|
|
|
+ now = datetime.datetime(now.year, now.month, now.day)
|
|
|
+
|
|
|
+ if not now:
|
|
|
+ if d.tzinfo:
|
|
|
+ now = datetime.datetime.now(LocalTimezone(d))
|
|
|
+ else:
|
|
|
+ now = datetime.datetime.now()
|
|
|
+
|
|
|
+ # ignore microsecond part of 'd' since we removed it from 'now'
|
|
|
+ delta = now - (d - datetime.timedelta(0, 0, d.microsecond))
|
|
|
+ since = delta.days * 24 * 60 * 60 + delta.seconds
|
|
|
+ if since <= 0:
|
|
|
+ # d is in the future compared to now, stop processing.
|
|
|
if abbreviate:
|
|
|
- chunks = (
|
|
|
- (60 * 60 * 24 * 365, lambda n: 'y'),
|
|
|
- (60 * 60 * 24 * 30, lambda n: 'm'),
|
|
|
- (60 * 60 * 24 * 7, lambda n : 'w'),
|
|
|
- (60 * 60 * 24, lambda n : 'd'),
|
|
|
- (60 * 60, lambda n: 'h'),
|
|
|
- (60, lambda n: 'm'),
|
|
|
- (1, lambda n : 's'),
|
|
|
- )
|
|
|
+ return u'0' + ugettext('s')
|
|
|
else:
|
|
|
- chunks = (
|
|
|
- (60 * 60 * 24 * 365, lambda n: ungettext('year', 'years', n)),
|
|
|
- (60 * 60 * 24 * 30, lambda n: ungettext('month', 'months', n)),
|
|
|
- (60 * 60 * 24 * 7, lambda n : ungettext('week', 'weeks', n)),
|
|
|
- (60 * 60 * 24, lambda n : ungettext('day', 'days', n)),
|
|
|
- (60 * 60, lambda n: ungettext('hour', 'hours', n)),
|
|
|
- (60, lambda n: ungettext('minute', 'minutes', n)),
|
|
|
- (1, lambda n : ungettext('second', 'seconds', n)),
|
|
|
- )
|
|
|
-
|
|
|
- # Convert datetime.date to datetime.datetime for comparison.
|
|
|
- if not isinstance(d, datetime.datetime):
|
|
|
- d = datetime.datetime(d.year, d.month, d.day)
|
|
|
- if now and not isinstance(now, datetime.datetime):
|
|
|
- now = datetime.datetime(now.year, now.month, now.day)
|
|
|
-
|
|
|
- if not now:
|
|
|
- if d.tzinfo:
|
|
|
- now = datetime.datetime.now(LocalTimezone(d))
|
|
|
- else:
|
|
|
- now = datetime.datetime.now()
|
|
|
-
|
|
|
- # ignore microsecond part of 'd' since we removed it from 'now'
|
|
|
- delta = now - (d - datetime.timedelta(0, 0, d.microsecond))
|
|
|
- since = delta.days * 24 * 60 * 60 + delta.seconds
|
|
|
- if since <= 0:
|
|
|
- # d is in the future compared to now, stop processing.
|
|
|
+ return u'0 ' + ugettext('seconds')
|
|
|
+ for i, (seconds, name) in enumerate(chunks):
|
|
|
+ count = since // seconds
|
|
|
+ if count != 0:
|
|
|
+ break
|
|
|
+ if abbreviate:
|
|
|
+ s = ugettext('%(number)d%(type)s') % {'number': count, 'type': name(count)}
|
|
|
+ else:
|
|
|
+ s = ugettext('%(number)d %(type)s') % {'number': count, 'type': name(count)}
|
|
|
+ if i + 1 < len(chunks):
|
|
|
+ # Now get the second item
|
|
|
+ seconds2, name2 = chunks[i + 1]
|
|
|
+ count2 = (since - (seconds * count)) // seconds2
|
|
|
+ if count2 != 0:
|
|
|
if abbreviate:
|
|
|
- return u'0' + ugettext('s')
|
|
|
+ s += ugettext(', %(number)d%(type)s') % {'number': count2, 'type': name2(count2)}
|
|
|
else:
|
|
|
- return u'0 ' + ugettext('seconds')
|
|
|
- for i, (seconds, name) in enumerate(chunks):
|
|
|
- count = since // seconds
|
|
|
- if count != 0:
|
|
|
- break
|
|
|
- if abbreviate:
|
|
|
- s = ugettext('%(number)d%(type)s') % {'number': count, 'type': name(count)}
|
|
|
- else:
|
|
|
- s = ugettext('%(number)d %(type)s') % {'number': count, 'type': name(count)}
|
|
|
- if i + 1 < len(chunks):
|
|
|
- # Now get the second item
|
|
|
- seconds2, name2 = chunks[i + 1]
|
|
|
- count2 = (since - (seconds * count)) // seconds2
|
|
|
- if count2 != 0:
|
|
|
- if abbreviate:
|
|
|
- s += ugettext(', %(number)d%(type)s') % {'number': count2, 'type': name2(count2)}
|
|
|
- else:
|
|
|
- s += ugettext(', %(number)d %(type)s') % {'number': count2, 'type': name2(count2)}
|
|
|
- return s
|
|
|
+ s += ugettext(', %(number)d %(type)s') % {'number': count2, 'type': name2(count2)}
|
|
|
+ return s
|