当前位置: 首页>>代码示例>>Python>>正文


Python dates.DateSpan类代码示例

本文整理汇总了Python中dimagi.utils.dates.DateSpan的典型用法代码示例。如果您正苦于以下问题:Python DateSpan类的具体用法?Python DateSpan怎么用?Python DateSpan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DateSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_end_before_start

 def test_end_before_start(self):
     startdate = datetime(2015, 02, 01)
     enddate = datetime(2015, 01, 01)
     datespan = DateSpan(startdate, enddate)
     self.assertFalse(datespan.is_valid())
     self.assertEqual(datespan.get_validation_reason(),
                      "You can't have an end date of %s after start date of %s" % (enddate, startdate))
开发者ID:bytearchive,项目名称:dimagi-utils,代码行数:7,代码来源:dates.py

示例2: test_adjustment

 def test_adjustment(self):
     end = datetime(2014, 3, 7, 2, tzinfo=pytz.utc)
     start = end = datetime(2014, 2, 7, 2, tzinfo=pytz.utc)
     ds = DateSpan(start, end)
     pst = pytz.timezone('US/Pacific')
     ds.set_timezone(pst)
     self.assertEqual(ds.enddate - end, timedelta(hours=8))
     self.assertEqual(ds.startdate - start, timedelta(hours=8))
     self.assertEqual(ds.timezone, pst)
开发者ID:bytearchive,项目名称:dimagi-utils,代码行数:9,代码来源:dates.py

示例3: test_since

    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))
开发者ID:bytearchive,项目名称:dimagi-utils,代码行数:9,代码来源:dates.py

示例4: datespan_from_beginning

def datespan_from_beginning(domain_object, timezone):
    if use_new_exports(domain_object.name):
        startdate = domain_object.date_created
    else:
        startdate = get_first_form_submission_received(domain_object.name)
    now = datetime.utcnow()
    datespan = DateSpan(startdate, now, timezone=timezone)
    datespan.is_default = True
    return datespan
开发者ID:,项目名称:,代码行数:9,代码来源:

示例5: datespan_from_beginning

def datespan_from_beginning(domain_object, timezone):
    from corehq import toggles
    if toggles.NEW_EXPORTS.enabled(domain_object.name):
        startdate = domain_object.date_created
    else:
        startdate = get_first_form_submission_received(domain_object.name)
    now = datetime.utcnow()
    datespan = DateSpan(startdate, now, timezone=timezone)
    datespan.is_default = True
    return datespan
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:10,代码来源:util.py

示例6: datespan

 def datespan(self):
     now = datetime.datetime.utcnow()
     year, month = add_months(now.year, now.month, -1)
     last_month = DateSpan.from_month(month, year)
     self.request.datespan = last_month
     self.context.update(dict(datespan=last_month))
     return last_month
开发者ID:dimagi,项目名称:commcare-hq,代码行数:7,代码来源:dates.py

示例7: wrapped_func

 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
开发者ID:unicefuganda,项目名称:dimagi-utils,代码行数:29,代码来源:datespan.py

示例8: datespan

 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
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:7,代码来源:filters.py

示例9: update_context

    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 ')
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:28,代码来源:fields.py

示例10: datespan

 def datespan(self):
     if self._datespan is None:
         datespan = DateSpan.from_month(self.month, self.year)
         self.request.datespan = datespan
         self.context.update(dict(datespan=datespan))
         self._datespan = datespan
     return self._datespan
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:7,代码来源:__init__.py

示例11: order_fill_stats

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
开发者ID:dimagi,项目名称:rapidsms-logistics,代码行数:59,代码来源:logistics_report_tags.py

示例12: stockonhand_table

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})
开发者ID:dimagi,项目名称:rapidsms-logistics,代码行数:8,代码来源:logistics_report_tags.py

示例13: update_context

 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
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:8,代码来源:fields.py

示例14: update_context

 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
开发者ID:comm-scriptek,项目名称:commcare-hq,代码行数:8,代码来源:fields.py

示例15: __init__

 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)
开发者ID:dslowikowski,项目名称:commcare-hq,代码行数:8,代码来源:filters.py


注:本文中的dimagi.utils.dates.DateSpan类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。