コード例 #1
0
def getSaturday():
    
    today = date.today()
    thisyear = today.year
    thismonth = today.month
    nextyear, nextmonth = calendar._nextmonth(year=thisyear, month=thismonth)
    # print(nextyear, nextmonth)

    thissaturday=[]
    nextsaturday=[]

    cal = calendar.monthcalendar(thisyear, thismonth)
    for week in cal:
        # THURSDAY
        if week[calendar.SATURDAY]:
            # print('%2s: %2s' % (str(thismonth).zfill(2), str(week[calendar.SATURDAY]).zfill(2)))
            thissaturday.append({'year':thisyear, 'month': thismonth, 'day':week[calendar.SATURDAY]})

    cal = calendar.monthcalendar(nextyear, nextmonth)
    for week in cal:
        if week[calendar.SATURDAY]:
            # print('%2s: %2s' % (str(nextmonth).zfill(2), str(week[calendar.SATURDAY]).zfill(2)))
            nextsaturday.append({'year':nextyear, 'month': nextmonth, 'day':week[calendar.SATURDAY]})

    return thissaturday, nextsaturday
コード例 #2
0
def monthly(request, date):
    context = {}
    date_list = []  # 传递给前端日历坐标系的数据
    # 获得url传过来的参数
    # date = datetime.datetime.strptime(request.GET.get("month"), "%Y-%m")  # 字符串转化为日期格式
    date = datetime.datetime.strptime(date, "%Y-%m")  # 字符串转化为日期格式
    mdays = calendar.monthrange(date.year, date.month)[1]  # 获取该月份的天数
    # python3.8.1中,把calendar模块的prevmonth和nextmonth函数修改为了_prevmonth和_nextmonth函数
    # prev_month = "-".join([str(x) for x in (calendar.prevmonth(date.year, date.month))])  # 上个月,字符串格式为2019-7
    # next_month = "-".join([str(x) for x in (calendar.nextmonth(date.year, date.month))])  # 下个月,字符串格式为2019-9
    prev_month = "-".join([
        str(x) for x in (calendar._prevmonth(date.year, date.month))
    ])  # 上个月,字符串格式为2019-7
    next_month = "-".join([
        str(x) for x in (calendar._nextmonth(date.year, date.month))
    ])  # 下个月,字符串格式为2019-9

    # 每月数据,按天分组并取出最后一条数据
    sql_groupBy_day = f"""SELECT MAX(Painting_Date)
                         FROM Painting_Production_Records
                         WHERE (CONVERT(varchar(7), Painting_Date, 120) = '{str(date)[:7]}')
                         GROUP BY CONVERT(varchar(10), Painting_Date, 120)"""
    rows = odbc_ms.select_query(sql_groupBy_day)
    print(sql_groupBy_day)
    print(rows)
    # 获得该月哪些天有生产计划(按天存储), 同理获取该月哪些天有停线记录(按天存储)
    # 借鉴的andon系统,这里不需要停线记录,所以停线记录为空
    mps_date = sorted([x[0].day for x in rows])
    line_stop_date = []

    date_start_with = date.strftime(
        '%Y-%m-')  # 格式化字符串,格式为2019-09-,留着后续添加在'天'的前方组成日期,格式为:2019-09-01。
    # 获取传送给前端日历坐标系的数据
    for i in range(1, mdays + 1):  # 循环遍历该月的天数
        element = []
        if i < 10:
            element.append(date_start_with + '0' + str(i))
        else:
            element.append(date_start_with + str(i))
        if i in mps_date:
            element.append('有生产')
        else:
            element.append('无生产')
        if i in line_stop_date:
            element.append('有停线')

        date_list.append(element)

    context['prev_month'] = prev_month
    context['next_month'] = next_month
    context['date_list'] = json.dumps(date_list)
    context['calendar_range'] = json.dumps(
        date.strftime('%Y-%m'))  # 告诉前端日历坐标系,要显示哪个年月的数据
    context['this_month'] = date
    return render(request, 'Painting/monthly.html', context)
コード例 #3
0
ファイル: views.py プロジェクト: weiyl-chenjie/ytwebserver
def monthly(request, menu_id, date):
    context = {}
    date_list = []  # 传递给前端日历坐标系的数据
    # 获得url传过来的参数
    # menu_id = request.GET.get("menu")
    # print(menu_id)
    # date = datetime.datetime.strptime(request.GET.get("month"), "%Y-%m")  # 字符串转化为日期格式
    menu_id = menu_id
    date = datetime.datetime.strptime(date, "%Y-%m")  # 字符串转化为日期格式

    menu_obj = Menu.objects.get(id=menu_id)  # 获得menu_id对应的数据项

    mdays = calendar.monthrange(date.year, date.month)[1]  # 获取该月份的天数
    # python3.8.1中,把calendar模块的prevmonth和nextmonth函数修改为了_prevmonth和_nextmonth函数
    # prev_month = "-".join([str(x) for x in (calendar.prevmonth(date.year, date.month))])  # 上个月,字符串格式为2019-7
    # next_month = "-".join([str(x) for x in (calendar.nextmonth(date.year, date.month))])  # 下个月,字符串格式为2019-9
    prev_month = "-".join([
        str(x) for x in (calendar._prevmonth(date.year, date.month))
    ])  # 上个月,字符串格式为2019-7
    next_month = "-".join([
        str(x) for x in (calendar._nextmonth(date.year, date.month))
    ])  # 下个月,字符串格式为2019-9

    # 查询本月计划生产的menu_info_id为menu_id的所有项目,并按日期去重, 同理查询停线记录的信息
    month_range = [date, datetime.datetime.strptime(next_month, "%Y-%m")]
    mps = list(
        Mps.objects.filter(start_time__range=month_range,
                           menu_info_id=menu_id).distinct(
                               "start_time__day").values("start_time"))
    line_stop = list(
        LineStop.objects.filter(start_time__range=month_range,
                                menu_info_id=menu_id).distinct(
                                    "start_time__day").values("start_time"))

    # 获得该月哪些天有生产计划(按天存储), 同理获取该月哪些天有停线记录(按天存储)
    mps_date = [x['start_time'].day for x in mps]
    line_stop_date = [x['start_time'].day for x in line_stop]

    date_start_with = date.strftime(
        '%Y-%m-')  # 格式化字符串,格式为2019-09-,留着后续添加在'天'的前方组成日期,格式为:2019-09-01。
    # 获取传送给前端日历坐标系的数据
    for i in range(1, mdays + 1):  # 循环遍历该月的天数
        element = []
        if i < 10:
            element.append(date_start_with + '0' + str(i))
        else:
            element.append(date_start_with + str(i))
        if i in mps_date:
            element.append('有生产')
        else:
            element.append('无生产')
        if i in line_stop_date:
            element.append('有停线')

        date_list.append(element)

    context['prev_month'] = prev_month
    context['next_month'] = next_month
    context['date_list'] = json.dumps(date_list)
    context['calendar_range'] = json.dumps(
        date.strftime('%Y-%m'))  # 告诉前端日历坐标系,要显示哪个年月的数据
    context['this_month'] = date
    context['menu_obj'] = menu_obj
    return render(request, 'andon/monthly.html', context)
コード例 #4
0
ファイル: datechooser.py プロジェクト: Ghost543/ttkbootstrap
 def on_next_month(self):
     year, month = calendar._nextmonth(self.date.year, self.date.month)
     self.date = datetime(year=year, month=month, day=1).date()
     self.dframe.destroy()
     self.draw_calendar()
コード例 #5
0
 def nextmonth(self):
     return calendar._nextmonth(self.year, self.month)
コード例 #6
0
 def update_event(self, inp=-1):
     self.set_output_val(0, calendar._nextmonth(self.input(0), self.input(1)))
コード例 #7
0
 def on_next_month(self):
     """Callback for changing calendar to next month"""
     year, month = calendar._nextmonth(self.date.year, self.date.month)
     self.date = datetime(year=year, month=month, day=1).date()
     self.dframe.destroy()
     self.draw_calendar()