Beispiel #1
0
def my_request(login_id, month_year):
    if month_year and not isinstance(month_year, date):
        month_year = datetime.strptime(month_year, '%Y-%m').date()

    session = get_db_session()
    operator = OperatorQuery(session).get_operator_of_user_id(current_user.id)

    CalendarDay = namedtuple('CalendarDay',
                             ('date', 'outer_month', 'notices', 'requests'))

    def is_between(date, start, end):
        return start.date() <= date <= end.date()

    def create_date(date, notices):
        return CalendarDay(
            date, date.year != month_year.year
            or date.month != month_year.month, notices, [
                request for request in operator.requests
                if is_between(date, request.at_from, request.at_to)
            ])

    calender = Calendar()
    calender.setfirstweekday(SUNDAY)
    weeks = [[create_date(_date, None)
              for _date in week] for week in calender.monthdatescalendar(
                  month_year.year, month_year.month)]
    return render_template('request.html', month_year=month_year, weeks=weeks)
 def create_calendar_table(self):
     self.calendar_layout.clear_widgets()
     calendars = Calendar()
     calendars.setfirstweekday(calendar.SUNDAY)
     selected_month = self.month - 1
     year_dates = calendars.yeardays2calendar(year=self.year, width=1)
     th1 = KV.invoice_tr(0, 'Su')
     th2 = KV.invoice_tr(0, 'Mo')
     th3 = KV.invoice_tr(0, 'Tu')
     th4 = KV.invoice_tr(0, 'We')
     th5 = KV.invoice_tr(0, 'Th')
     th6 = KV.invoice_tr(0, 'Fr')
     th7 = KV.invoice_tr(0, 'Sa')
     self.calendar_layout.add_widget(Builder.load_string(th1))
     self.calendar_layout.add_widget(Builder.load_string(th2))
     self.calendar_layout.add_widget(Builder.load_string(th3))
     self.calendar_layout.add_widget(Builder.load_string(th4))
     self.calendar_layout.add_widget(Builder.load_string(th5))
     self.calendar_layout.add_widget(Builder.load_string(th6))
     self.calendar_layout.add_widget(Builder.load_string(th7))
     if year_dates[selected_month]:
         for month in year_dates[selected_month]:
             for week in month:
                 for day in week:
                     if day[0] > 0:
                         item = Factory.CalendarButton(text="[b]{}[/b]".format(day[0]))
                     else:
                         item = Factory.CalendarButton(disabled=True)
                     self.calendar_layout.add_widget(item)
Beispiel #3
0
def get_all_calendar_dates(year: int,
                           planner_start_day: DayOfTheWeek) -> List[date]:
    calendar_dates = []
    calendar = Calendar()
    calendar.setfirstweekday(planner_start_day.value)
    for month in range(1, 13):
        for full_date in calendar.itermonthdates(year=year, month=month):
            calendar_dates.append(full_date)
    return calendar_dates
Beispiel #4
0
 def new(work_categories: [], month: int, year: int):
     calendar = SysCalendar()
     calendar.setfirstweekday(SUNDAY)
     monthdatescalendar = [
         y for x in calendar.monthdatescalendar(year, month) for y in x
         if y.year == year and y.month == month
     ]
     days = [
         DaySetting.new(x, day_abbr[x.weekday()], work_categories)
         for x in monthdatescalendar
     ]
     return MonthlySetting(
         UuidFactory.new_uuid(), month, year, days,
         len([x for x in monthdatescalendar if x.weekday() in [5, 6]]))