本文整理汇总了Python中dimagi.utils.dates.DateSpan.since方法的典型用法代码示例。如果您正苦于以下问题:Python DateSpan.since方法的具体用法?Python DateSpan.since怎么用?Python DateSpan.since使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dimagi.utils.dates.DateSpan
的用法示例。
在下文中一共展示了DateSpan.since方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_since
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def test_since(self):
enddate = datetime(2013, 7, 21, 12, 30, 45)
datespan_inclusive = DateSpan.since(7, enddate)
self.assertEqual(datespan_inclusive.enddate, datetime(2013, 7, 21, 0, 0, 0))
self.assertEqual(datespan_inclusive.startdate, datetime(2013, 7, 15, 0, 0, 0))
datespan_non_inclusive = DateSpan.since(7, enddate, inclusive=False)
self.assertEqual(datespan_non_inclusive.enddate, datetime(2013, 7, 21, 0, 0, 0))
self.assertEqual(datespan_non_inclusive.startdate, datetime(2013, 7, 14, 0, 0, 0))
示例2: datespan
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def datespan(self):
datespan = DateSpan.since(self.default_days, enddate=datetime.date.today(), timezone=self.timezone)
if self.get_start_date(self.request) is not None:
datespan.startdate = self.get_start_date(self.request)
if self.get_end_date(self.request) is not None:
datespan.enddate = self.get_end_date(self.request)
return datespan
示例3: update_context
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def update_context(self):
self.context["datespan_name"] = self.name
range = self.request.GET.get('range', None)
if range:
dates = str(range).split(_(' to '))
self.request.datespan.startdate = datetime.datetime.combine(
iso_string_to_date(dates[0]), datetime.time())
self.request.datespan.enddate = datetime.datetime.combine(
iso_string_to_date(dates[1]), datetime.time())
self.datespan = DateSpan.since(self.default_days, timezone=self.timezone, inclusive=self.inclusive)
if self.request.datespan.is_valid():
self.datespan.startdate = self.request.datespan.startdate
self.datespan.enddate = self.request.datespan.enddate
self.context['timezone'] = self.timezone.zone
self.context['datespan'] = self.datespan
report_labels = json.dumps({
'year_to_date': _('Year to Date'), 'last_month': _('Last Month'),
'last_quarter': _('Last Quarter'), 'last_two_quarters': _('Last Two Quarters'),
'last_three_quarters': _('Last Three Quarters'), 'last_year': _('Last Year'),
'last_two_years': _('Last Two Years'), 'last_three_years': _('Last Three Years'),
'last_four_years': _('Last Four Years')
})
self.context['report_labels'] = report_labels
self.context['separator'] = _(' to ')
示例4: wrapped_func
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def wrapped_func(*args, **kwargs):
# attempt to find the request object from all the argument
# values, checking first the args and then the kwargs
req = None
for arg in args:
if _is_http_request(arg):
req = arg
break
if not req:
for arg in kwargs.values():
if _is_http_request(arg):
req = arg
break
if req:
dict = req.POST if req.method == "POST" else req.GET
def date_or_nothing(param):
return datetime.strptime(dict[param], format_string)\
if param in dict and dict[param] else None
try:
startdate = date_or_nothing(from_param)
enddate = date_or_nothing(to_param)
except ValueError, e:
return HttpResponseBadRequest(unicode(e))
if startdate or enddate:
req.datespan = DateSpan(startdate, enddate, format_string)
else:
# default to the last N days
req.datespan = DateSpan.since(default_days, format=format_string, inclusive=inclusive)
req.datespan.is_default = True
示例5: order_fill_stats
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def order_fill_stats(locations, type=None, datespan=None):
"""
With a list of locations - display reporting
rates associated with those locations.
This method only looks at closed orders
"""
if locations:
if datespan == None:
# default to last 30 days
datespan = DateSpan.since(30)
base_points = SupplyPoint.objects.filter(location__in=locations, active=True)
if type is not None:
base_points = base_points.filter(type__code=type)
if base_points.count() > 0:
base_reqs = StockRequest.objects.filter(
supply_point__in=base_points, requested_on__gte=datespan.startdate, requested_on__lte=datespan.enddate
)
rec_reqs = base_reqs.filter(status=StockRequestStatus.RECEIVED)
totals = base_reqs.values("product").annotate(total=Count("pk"))
rec_totals = rec_reqs.values("product").annotate(total=Count("pk"))
eo_totals = base_reqs.filter(is_emergency=True).values("product").annotate(total=Count("pk"))
stocked_out = rec_reqs.filter(amount_received=0).values("product").annotate(total=Count("pk"))
not_stocked_out = rec_reqs.filter(amount_received__gt=0).exclude(
response_status=StockRequestStatus.STOCKED_OUT
)
under_supplied = (
not_stocked_out.filter(amount_requested__gt=F("amount_received"))
.values("product")
.annotate(total=Count("pk"))
)
well_supplied = (
not_stocked_out.filter(amount_requested=F("amount_received"))
.values("product")
.annotate(total=Count("pk"))
)
over_supplied = (
not_stocked_out.filter(amount_requested__lt=F("amount_received"))
.values("product")
.annotate(total=Count("pk"))
)
main_data = {}
for row in totals:
main_data[row["product"]] = defaultdict(lambda x: 0)
main_data[row["product"]]["product"] = Product.objects.get(pk=row["product"])
main_data[row["product"]]["total"] = row["total"]
def _update_main_data(main, to_update, tag):
for row in to_update:
main[row["product"]][tag] = row["total"]
_update_main_data(main_data, rec_totals, "filled")
_update_main_data(main_data, eo_totals, "emergency")
_update_main_data(main_data, stocked_out, "stocked_out")
_update_main_data(main_data, under_supplied, "under_supplied")
_update_main_data(main_data, well_supplied, "well_supplied")
_update_main_data(main_data, over_supplied, "over_supplied")
return r_2_s_helper("logistics/partials/order_fill_stats.html", {"data": main_data, "datespan": datespan})
return "" # no data, no report
示例6: update_context
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def update_context(self):
self.context["datespan_name"] = self.name
self.datespan = DateSpan.since(7, format="%Y-%m-%d", timezone=self.timezone)
if self.request.datespan.is_valid():
self.datespan.startdate = self.request.datespan.startdate
self.datespan.enddate = self.request.datespan.enddate
self.context['timezone'] = self.timezone.zone
self.context['datespan'] = self.datespan
示例7: update_context
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def update_context(self):
self.context["datespan_name"] = self.name
self.datespan = DateSpan.since(self.default_days, timezone=self.timezone, inclusive=self.inclusive)
if self.request.datespan.is_valid():
self.datespan.startdate = self.request.datespan.startdate
self.datespan.enddate = self.request.datespan.enddate
self.context['timezone'] = self.timezone.zone
self.context['datespan'] = self.datespan
示例8: stockonhand_table
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def stockonhand_table(supply_point, datespan=None):
if datespan is None:
datespan = DateSpan.since(settings.LOGISTICS_REPORTING_CYCLE_IN_DAYS)
sohs = supply_point.stocked_productstocks().order_by("product__name")
# update the stock quantities to match whatever reporting period has been specified
for soh in sohs:
soh.quantity = supply_point.historical_stock_by_date(soh.product, datespan.end_of_end_day)
return r_2_s_helper("logistics/partials/stockonhand_table_full.html", {"stockonhands": sohs, "datespan": datespan})
示例9: __init__
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def __init__(self, filter, value):
assert filter.type == 'date'
# todo: might want some better way to set defaults
if value is None:
# default to one week
value = DateSpan.since(7)
assert isinstance(value, DateSpan)
super(DateFilterValue, self).__init__(filter, value)
示例10: default_datespan
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def default_datespan(self):
# DateSpan.since() will make enddate default to yesterday when it's None
enddate = None
if self.default_datespan_end_date_to_today:
enddate = ServerTime(datetime.utcnow()).user_time(self.timezone).done().date()
datespan = DateSpan.since(self.datespan_default_days, enddate=enddate, inclusive=self.inclusive,
timezone=self.timezone)
datespan.max_days = self.datespan_max_days
datespan.is_default = True
return datespan
示例11: datespan_in_request
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def datespan_in_request(from_param="from", to_param="to",
format_string=ISO_DATE_FORMAT, default_days=30,
inclusive=True, default_function=None):
"""
Wraps a request with dates based on url params or defaults and
Checks date validity.
"""
# you can pass in a function to say what the default should be,
# if you don't it will pull the value from the last default_days
# in. If you override default_function, default_days is ignored.
if default_function is None:
default_function = lambda: DateSpan.since(default_days,
format=format_string,
inclusive=inclusive)
# this is loosely modeled after example number 4 of decorator
# usage here: http://www.python.org/dev/peps/pep-0318/
def get_dates(f):
def wrapped_func(*args, **kwargs):
# attempt to find the request object from all the argument
# values, checking first the args and then the kwargs
req = request_from_args_or_kwargs(*args, **kwargs)
if req:
req_dict = req.POST if req.method == "POST" else req.GET
def date_or_nothing(param):
date = req_dict.get(param, None)
return datetime.strptime(date, format_string) if date else None
try:
startdate = date_or_nothing(from_param)
enddate = date_or_nothing(to_param)
except ValueError as e:
return HttpResponseBadRequest(unicode(e))
if startdate or enddate:
req.datespan = DateSpan(startdate, enddate, format_string)
else:
req.datespan = default_function()
req.datespan.is_default = True
return f(*args, **kwargs)
if hasattr(f, "func_name"):
wrapped_func.func_name = f.func_name
# preserve doc strings
wrapped_func.__doc__ = f.__doc__
return wrapped_func
else:
# this means it wasn't actually a view.
return f
return get_dates
示例12: district_dashboard
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def district_dashboard(request, template="logistics/district_dashboard.html"):
districts = get_districts()
if request.location is None:
# pick a random location to start
location_code = settings.COUNTRY
request.location = get_object_or_404(Location, code=location_code)
facilities = SupplyPoint.objects.all()
#request.location = districts[0]
else:
facilities = request.location.all_child_facilities()
report = ReportingBreakdown(facilities,
DateSpan.since(settings.LOGISTICS_DAYS_UNTIL_LATE_PRODUCT_REPORT),
days_for_late=settings.LOGISTICS_DAYS_UNTIL_LATE_PRODUCT_REPORT)
return render_to_response(template,
{"reporting_data": report,
"graph_width": 200,
"graph_height": 200,
"districts": districts.order_by("code"),
"location": request.location},
context_instance=RequestContext(request))
示例13: get_data
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def get_data(domain, user=None, datespan=None):
"""
Returns a data structure like:
{ <Form display name>:
{ <date>: { count: <count>,
max: <time in ms>,
min: <time in ms>,
sum: <time in ms>
}
}
}
"""
if datespan is None:
datespan = DateSpan.since(days=30, format="%Y-%m-%dT%H:%M:%S")
all_data = defaultdict(lambda: defaultdict(lambda: 0))
startkey = ["udx", domain, user, datespan.startdate_param] if user \
else ["dx", domain, datespan.startdate_param]
endkey = ["udx", domain, user, datespan.enddate_param] if user \
else ["dx", domain, datespan.enddate_param]
view = get_db().view("formtrends/form_duration_by_user",
startkey=startkey,
endkey=endkey,
group=True,
reduce=True)
for row in view:
date = row["key"][-2]
xmlns = row["key"][-1]
form_name = xmlns_to_name(domain, xmlns, app_id=None)
data = all_data[form_name]
if not date in data:
data[date] = defaultdict(lambda: 0)
thisrow = row["value"]
for key, val in thisrow.items():
data[date][key] = data[date][key] + thisrow[key]
return all_data
示例14: datespan
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def datespan(self):
datespan = DateSpan.since(self.default_days, timezone=self.timezone, inclusive=self.inclusive)
if self.request.datespan.is_valid() and self.slug == "datespan":
datespan.startdate = self.request.datespan.startdate
datespan.enddate = self.request.datespan.enddate
return datespan
示例15: default_datespan
# 需要导入模块: from dimagi.utils.dates import DateSpan [as 别名]
# 或者: from dimagi.utils.dates.DateSpan import since [as 别名]
def default_datespan(self):
datespan = DateSpan.since(self.datespan_default_days, timezone=self.timezone, inclusive=self.inclusive)
datespan.is_default = True
return datespan