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


Python TimeAgent.str2dt方法代码示例

本文整理汇总了Python中nell.utilities.TimeAgent.str2dt方法的典型用法代码示例。如果您正苦于以下问题:Python TimeAgent.str2dt方法的具体用法?Python TimeAgent.str2dt怎么用?Python TimeAgent.str2dt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nell.utilities.TimeAgent的用法示例。


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

示例1: read

# 需要导入模块: from nell.utilities import TimeAgent [as 别名]
# 或者: from nell.utilities.TimeAgent import str2dt [as 别名]
    def read(self, request, *args, **kws):
        if len(args) == 1:
            tz,          = args
            startPeriods = request.GET.get("startPeriods", datetime.now().strftime("%Y-%m-%d"))
            daysPeriods  = request.GET.get("daysPeriods",  '14')

            dt           = TimeAgent.str2dt(startPeriods)
            start        = dt if tz == 'UTC' else TimeAgent.est2utc(dt)
            duration     = int(daysPeriods) * 24 * 60
            periods      = Period.get_periods(start, duration)
            pjson = [DssPeriodHttpAdapter(p).jsondict(tz) for p in periods]
            return HttpResponse(
                json.dumps(dict(total   = len(periods)
                              , periods = pjson
                              , success = 'ok'))
              , content_type = "application/json")
        else:
            tz, id = args
            p      = Period.objects.get(id = id)
            return HttpResponse(
                json.dumps(dict(DssPeriodHttpAdapter(p).jsondict(tz)
                              , success = 'ok'))
              , content_type = "application/json")
开发者ID:mmccarty,项目名称:nell,代码行数:25,代码来源:DssPeriodResource.py

示例2: read

# 需要导入模块: from nell.utilities import TimeAgent [as 别名]
# 或者: from nell.utilities.TimeAgent import str2dt [as 别名]
    def read(self, request, *args, **kws):

        tz = args[0]
        # one or many?
        if len(args) == 1:
            # we are getting periods from within a range of dates
            sortField = jsonMap.get(request.GET.get("sortField", "start"), "start")
            order = "-" if request.GET.get("sortDir", "ASC") == "DESC" else ""

            # Either filter by date, or by something else.
            filterWnd = request.GET.get("filterWnd", None)

            # make sure we have defaults for dates
            defStart = datetime.now().strftime("%Y-%m-%d") if filterWnd is None else None
            defDays = "1" if filterWnd is None else None

            # Filtering by date involves a pair of keywords
            filterWnd = request.GET.get("filterWnd", None)
            filterElc = request.GET.get("filterElc", None)

            # make sure we have defaults for dates
            defStart = datetime.now().strftime("%Y-%m-%d") if filterWnd is None and filterElc is None else None
            defDays = "1" if filterWnd is None and filterElc is None else None

            startPeriods = request.GET.get("startPeriods", defStart)
            daysPeriods = request.GET.get("daysPeriods", defDays)

            if startPeriods is not None and daysPeriods is not None:
                if startPeriods is None:
                    startPeriods = datetime.now().strftime("%Y-%m-%d")
                if daysPeriods is None:
                    daysPeriods = "1"
                dt = TimeAgent.str2dt(startPeriods)
                start = dt if tz == "UTC" else TimeAgent.est2utc(dt)
                duration = int(daysPeriods) * 24 * 60
                periods = Period.get_periods(start, duration)
            else:
                # filter by something else
                query_set = Period.objects

                # window id
                # filterWnd = request.GET.get("filterWnd", None)
                if filterWnd is not None:
                    wId = int(filterWnd)
                    query_set = query_set.filter(window__id=wId)

                # elective id
                # filterElc = request.GET.get("filterElc", None)
                if filterElc is not None:
                    eId = int(filterElc)
                    query_set = query_set.filter(elective__id=eId)

                periods = query_set.order_by(order + sortField)

            return HttpResponse(
                json.dumps(
                    dict(total=len(periods), periods=[PeriodHttpAdapter(p).jsondict(tz) for p in periods], success="ok")
                ),
                content_type="application/json",
            )
        else:
            # we're getting a single period as specified by ID
            p_id = int(args[1])
            # p       = Period.objects.get(id = p_id)
            p = get_object_or_404(Period, id=p_id)
            adapter = PeriodHttpAdapter(p)
            return HttpResponse(
                json.dumps(dict(period=adapter.jsondict(tz), success="ok")), content_type="application/json"
            )
开发者ID:,项目名称:,代码行数:71,代码来源:


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