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)
def test_repeatBooking(self, repeat=True): dayofweek = 0 # day_map[form.cleaned_data['dayID'].upper()] cleaned_data = self.data start = cleaned_data['start'] end = cleaned_data['end'] year = int(start.year) month = int(start.month) day = int(start.day) #[8:10]) loc = cleaned_data['location'] s_time = str(start)[-8:] #get time substring e_time = str(end)[-8:] title = cleaned_data['title'] descr = cleaned_data['description'] b_list = [] if True: cal = Calendar() ydcal = cal.yeardays2calendar(year, width=6) if month > 5: w = ydcal[1] else: w = ydcal[0] for m in range(len(w)): if m + 1 < month: continue #skip past months for k in range(len(w[m])): #week in a month for d in range(len(w[m][k])): #days in a week cal_day = w[m][k][d] if (cal_day[0] < day and m + 1 == month) or cal_day[0] == 0: continue if cal_day[1] == dayofweek: # print("here") if m < 9: #format month cal_m = "0" + str(m + 1) else: cal_m = str(m + 1) if cal_day[0] < 9: #format day cal_d = "0" + str(cal_day[0]) else: cal_d = str(cal_day[0]) date_format = str(year) + "-" + cal_m + "-" + cal_d start_rec = date_format + " " + s_time end_rec = date_format + " " + e_time b = Booking(location=loc, start=start_rec, end=end_rec, title=title, description=descr) b.save() b_list.append(b) self.assertTrue(False) return b_list
def repeat_booking(data): location = data['location'] start = data['start'] end = data['end'] if data['repeat'] == "noRepeat": repeat = False elif data['repeat'] == "weekly": repeat = True else: repeat = False day_map = { "MON": 0, "TUE": 1, "WED": 2, "THU": 3, "FRI": 4, "SAT": 5, "SUN": 6 } dayofweek = day_map[data['day'].upper()] year = int(start.year) month = int(start.month) day = int(start.day) loc = location s_time = str(start)[11:] #get time substring e_time = str(end)[11:] #YYYY-MM-DDTHH:MMZ title = data['title'] descr = data['description'] person = data['person'] group = data['group'] cal = Calendar() ydcal = cal.yeardays2calendar(year, width=6) if month > 5: w = ydcal[1] else: w = ydcal[0] for m in range(len(w)): if m + 1 < month: continue # skip past months for k in range(len(w[m])): for d in range(len(w[m][k])): cal_day = w[m][k][d] if (cal_day[0] <= day and m + 1 == month) or cal_day[0] == 0: continue if cal_day[1] == dayofweek: if m < 9: # format month cal_m = "0" + str(m + 1) else: cal_m = str(m + 1) if cal_day[0] < 9: # format day cal_d = "0" + str(cal_day[0]) else: cal_d = str(cal_day[0]) date_format = str(year) + "-" + cal_m + "-" + cal_d start_rec = date_format + " " + s_time end_rec = date_format + " " + e_time booking = Booking(location=location, start=start_rec, group=group, end=end_rec, title=title, description=descr, person=person) booking.save(repeatable=True) for data_elements in data: if data_elements == "request": data["request"].delete()