本文整理汇总了Python中django.utils.duration.duration_string方法的典型用法代码示例。如果您正苦于以下问题:Python duration.duration_string方法的具体用法?Python duration.duration_string怎么用?Python duration.duration_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.duration
的用法示例。
在下文中一共展示了duration.duration_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_report_round_duration
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def test_report_round_duration(db):
"""Should round the duration of a report to 15 minutes."""
report = ReportFactory.create()
report.duration = timedelta(hours=1, minutes=7)
report.save()
assert duration_string(report.duration) == "01:00:00"
report.duration = timedelta(hours=1, minutes=8)
report.save()
assert duration_string(report.duration) == "01:15:00"
report.duration = timedelta(hours=1, minutes=53)
report.save()
assert duration_string(report.duration) == "02:00:00"
示例2: prepare_value
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def prepare_value(self, value):
if isinstance(value, datetime.timedelta):
return duration_string(value)
return value
示例3: date_interval_sql
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def date_interval_sql(self, timedelta):
return "'%s'" % duration_string(timedelta), []
示例4: value_to_string
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def value_to_string(self, obj):
val = self._get_val_from_obj(obj)
return '' if val is None else duration_string(val)
示例5: get_purchased_time
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def get_purchased_time(self, obj):
"""
Calculate purchased time for given project.
Only acknowledged hours are included.
"""
orders = Order.objects.filter(project=obj, acknowledged=True)
data = orders.aggregate(purchased_time=Sum("duration"))
return duration_string(data["purchased_time"] or timedelta(0))
示例6: get_spent_time
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def get_spent_time(self, obj):
"""
Calculate spent time for given project.
Reports which are not billable or are in review are excluded.
"""
reports = Report.objects.filter(
task__project=obj, not_billable=False, review=False
)
data = reports.aggregate(spent_time=Sum("duration"))
return duration_string(data["spent_time"] or timedelta())
示例7: get_root_meta
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def get_root_meta(self, resource, many):
"""Add total hours over whole result (not just page) to meta."""
if many:
view = self.context["view"]
queryset = view.filter_queryset(view.get_queryset())
data = queryset.aggregate(total_time=Sum(self.duration_field))
data["total_time"] = duration_string(data["total_time"] or timedelta(0))
return data
return {}
示例8: get_root_meta
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def get_root_meta(self, resource, many):
if not many:
queryset = Report.objects.filter(task__project=self.instance)
data = queryset.aggregate(spent_time=Sum("duration"))
data["spent_time"] = duration_string(data["spent_time"] or timedelta(0))
billable_data = queryset.filter(not_billable=False, review=False).aggregate(
spent_billable=Sum("duration")
)
data["spent_billable"] = duration_string(
billable_data["spent_billable"] or timedelta(0)
)
return data
return {}
示例9: get_balance
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def get_balance(self, instance):
balance_date = self.get_date(instance)
start = date(balance_date.year, 1, 1)
# id is mapped to user instance
_, _, balance = instance.id.calculate_worktime(start, balance_date)
return duration_string(balance)
示例10: get_used_duration
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def get_used_duration(self, instance):
"""
Calculate duration of absence type.
For absence types which fill worktime this will be None.
"""
# id is mapped to absence type
absence_type = instance.id
if not absence_type.fill_worktime:
return None
start = self._get_start(instance)
absences = sum(
[
absence.calculate_duration(
models.Employment.objects.get_at(instance.user, absence.date)
)
for absence in Absence.objects.filter(
user=instance.user,
date__range=[start, instance.date],
type_id=instance.id,
).select_related("type")
],
timedelta(),
)
return duration_string(absences)
示例11: date_interval_sql
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def date_interval_sql(self, timedelta):
return "'%s'" % duration_string(timedelta)
示例12: value_to_string
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def value_to_string(self, obj):
val = self.value_from_object(obj)
return '' if val is None else duration_string(val)
示例13: to_representation
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def to_representation(self, value):
return duration_string(value)
# Choice types...
示例14: test_durationfield_prepare_value
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def test_durationfield_prepare_value(self):
field = DurationField()
td = datetime.timedelta(minutes=15, seconds=30)
self.assertEqual(field.prepare_value(td), duration_string(td))
self.assertEqual(field.prepare_value('arbitrary'), 'arbitrary')
self.assertIsNone(field.prepare_value(None))
示例15: __init__
# 需要导入模块: from django.utils import duration [as 别名]
# 或者: from django.utils.duration import duration_string [as 别名]
def __init__(self, param, cursor, strings_only=False):
# With raw SQL queries, datetimes can reach this function
# without being converted by DateTimeField.get_db_prep_value.
if settings.USE_TZ and (isinstance(param, datetime.datetime) and
not isinstance(param, Oracle_datetime)):
if timezone.is_naive(param):
warnings.warn("Oracle received a naive datetime (%s)"
" while time zone support is active." % param,
RuntimeWarning)
default_timezone = timezone.get_default_timezone()
param = timezone.make_aware(param, default_timezone)
param = Oracle_datetime.from_datetime(param.astimezone(timezone.utc))
if isinstance(param, datetime.timedelta):
param = duration_string(param)
if ' ' not in param:
param = '0 ' + param
string_size = 0
# Oracle doesn't recognize True and False correctly in Python 3.
# The conversion done below works both in 2 and 3.
if param is True:
param = 1
elif param is False:
param = 0
if hasattr(param, 'bind_parameter'):
self.force_bytes = param.bind_parameter(cursor)
elif isinstance(param, Database.Binary):
self.force_bytes = param
else:
# To transmit to the database, we need Unicode if supported
# To get size right, we must consider bytes.
self.force_bytes = convert_unicode(param, cursor.charset,
strings_only)
if isinstance(self.force_bytes, six.string_types):
# We could optimize by only converting up to 4000 bytes here
string_size = len(force_bytes(param, cursor.charset, strings_only))
if hasattr(param, 'input_size'):
# If parameter has `input_size` attribute, use that.
self.input_size = param.input_size
elif string_size > 4000:
# Mark any string param greater than 4000 characters as a CLOB.
self.input_size = Database.CLOB
else:
self.input_size = None