def weeklyNavigation(cls, obj, ar): today = obj.date prev = cls.date2pk(DurationUnits.months.add_duration(today, -1)) next = cls.date2pk(DurationUnits.months.add_duration(today, 1)) elems = cls.calender_header(ar) header = [ ar.goto_pk(prev, "<<"), " ", "{} {}".format(monthname(today.month), today.year), " ", ar.goto_pk(next, ">>")] elems.append(E.h2(*header, align="center")) rows = [] for week in CALENDAR.monthdatescalendar(today.year, today.month): # each week is a list of seven datetime.date objects. cells = [] current_week = week[0].isocalendar()[1] cells.append(E.td(str(current_week))) for day in week: pk = cls.date2pk(day) if day.isocalendar()[1] == today.isocalendar()[1]: cells.append(E.td(str(day.day))) else: cells.append(E.td(ar.goto_pk(pk, str(day.day)))) rows.append(E.tr(*cells, align="center")) elems.append(E.table(*rows, align="center")) elems.append(E.p(ar.goto_pk(0, gettext("This week")), align="center")) # for o in range(-10, 10): # elems.append(ar.goto_pk(o, str(o))) # elems.append(" ") return E.div(*elems)
def to_html(self, ar): self.analyze_view() get_rnd = rt.models.cal.EventGenerator.get_cal_entry_renderer if self.mode == TABLE_MODE: sep = ' ' fmt = get_rnd(day_and_weekday) elif self.mode == UL_MODE: sep = ' ' fmt = get_rnd(day_and_weekday) elif self.mode == PLAIN_MODE: sep = ', ' fmt = get_rnd(dd.fds) def xxx(list_of_entries): elems = [] for e in list_of_entries: if len(elems): elems.append(sep) elems.extend(fmt(e, ar)) return elems if self.mode == TABLE_MODE: rows = [] cells = [E.th("")] + [E.th(monthname(m+1)) for m in range(12)] # print(''.join([tostring(c) for c in cells])) rows.append(E.tr(*cells)) for y in self.years.values(): cells = [E.td(str(y.year), width="4%")] for m in y.months: # every m is a list of etree elems cells.append(E.td(*xxx(m), width="8%", **ar.renderer.cellattrs)) # print(str(y.year) +":" + ''.join([tostring(c) for c in cells])) rows.append(E.tr(*cells)) return E.table(*rows, **ar.renderer.tableattrs) if self.mode == UL_MODE: items = [] for y in self.years.values(): for m, lst in enumerate(y.months): if len(lst): items.append(E.li( monthname(m+1), " ", str(y.year), ": ", *xxx(lst))) return E.ul(*items) if self.mode == PLAIN_MODE: elems = [] for y in self.years.values(): for lst in y.months: if len(lst): if len(elems): elems.append(sep) elems.extend(xxx(lst)) return E.p(*elems) raise Exception("20180720")
def get_report(ar, today=None, weeksback=1, weeksforth=0, datefmt=dd.fds): if not ar.user.user_type.has_required_roles([SiteUser]): return E.p() if today is None: today = dd.today() start_date = today - ONE_DAY * today.weekday() - weeksback * SEVEN_DAYS numweeks = weeksback + weeksforth + 1 days = dict() cd = start_date numdays = numweeks * 7 for i in range(numdays): days[cd] = [] cd += ONE_DAY end_date = cd for r in REPORTERS: r(days, ar, start_date, end_date) headers = [E.th(Weekdays.choices[i][1], **ar.cellattrs) for i in range(7)] rows = [E.tr(*headers)] cd = start_date for week in range(numweeks): week = [] for weekday in range(7): chunks = days[cd] chunks.insert(0, datefmt(cd)) week.append(E.td(*chunks, **ar.cellattrs)) cd += ONE_DAY rows.append(E.tr(*week)) # print 20150420, rows return E.table(*rows, **ar.tableattrs)
def func(fld, obj, ar): # obj is the first day of the week to show # pv = ar.param_values today = dd.today() # if pv is None: # return qs = cls.get_calendar_entries(ar, None) # qs = Event.objects.all() # qs = Event.calendar_param_filter(qs, pv) mi = ar.master_instance if mi is None: return target_day = cls.get_row_by_pk(ar, obj.pk + int(wd.value) - 1) current_month = mi.date.month nav = mi.planner # offset = ar.master_instance.pk # offset = int(ar.rqdata.get('mk', 0) or 0) if ar.rqdata else ar.master_instance.pk # current_date = dd.today(offset) # pk = offset + int(wd.value) - 1 # target_day = cls.get_row_by_pk(ar, pk) # if target_day is None: # return # target_day = week[int(wd.value)-1] qs = qs.filter(start_date=target_day.date) qs = qs.order_by('start_time') chunks = [ E.p(e.obj2href(ar, cls.get_calview_div(e, ar))) for e in qs ] # pk = date2pk(target_day) # nav.daily_view # sar = ar.spawn_request(actor=actor, param_values=ar.param_values) # rnd = settings.SITE.kernel.default_renderer # def func(day, text): # # day.navigation_mode = actor.navigation_mode # return rnd.ar2button(sar, day, text, style="", icon_name=None, title=str(day)) # daily = nav.daily_button_func(ar) daily_link = daily(target_day, str(target_day.date.day)) if target_day.date == today: daily_link = E.b(daily_link) # header_items = [daily_link] # header_items = Event.gen_insert_button(cls, header_items, ar, target_day) header_items = [daily_link] btn = ar.gen_insert_button(Events, start_date=target_day.date) if btn: header_items.append(btn) header = E.div(*header_items, align="center", CLASS="header") return E.table( E.tr(E.td(*[header, E.div(*join_elems(chunks))])), CLASS="fixed-table cal-month-cell {} {} {}".format( "current-month" if current_month == target_day.date.month else "other-month", "current-day" if target_day.date == today else "", "cal-in-past" if target_day.date < today else ""))
def func(fld, week, ar): pv = ar.param_values if pv is None: return qs = Event.objects.all() qs = Event.calendar_param_filter(qs, pv) offset = int(ar.rqdata.get('mk', 0) or 0) if ar.rqdata else ar.master_instance.pk today = dd.today() current_date = dd.today(offset) target_day = week[int(pc.value) - 1] qs = qs.filter(start_date=target_day) qs = qs.order_by('start_time') chunks = [ E.p(e.obj2href(ar, e.colored_calendar_fmt(pv))) for e in qs ] pk = date2pk(target_day) daily, weekly, monthly = make_link_funcs(ar) daily_link = daily(Day(pk), str(target_day.day)) if target_day == today: daily_link = E.b(daily_link) header_items = [daily_link] header_items = gen_insert_button(cls, header_items, Event, ar, target_day) header = E.div(*header_items, align="center", CLASS="header") return E.table( E.tr(E.td(*[header, E.div(*join_elems(chunks))])), CLASS="fixed-table cal-month-cell {} {} {}".format( "current-month" if current_date.month == target_day.month else "other-month", "current-day" if target_day == today else "", "cal-in-past" if target_day < today else ""))
def func(fld, obj, ar): # obj is a Plannable instance qs = Event.objects.all() qs = Event.calendar_param_filter(qs, ar.param_values) delta_days = int(ar.rqdata.get('mk', 0) or 0) if ar.rqdata else ar.master_instance.pk # current_day = dd.today() + timedelta(days=delta_days) current_day = dd.today(delta_days) current_week_day = current_day + \ timedelta(days=int(week_day.value) - current_day.weekday() - 1) qs = qs.filter(start_date=current_week_day) qs = qs.order_by('start_time') chunks = obj.get_weekly_chunks(ar, qs, current_week_day) return E.table(E.tr(E.td(E.div(*join_elems(chunks)))), CLASS="fixed-table")
def func(fld, obj, ar): # obj is a Plannable instance qs = cls.get_calendar_entries(ar, obj) delta_days = int(ar.rqdata.get('mk', 0) or 0) if ar.rqdata else ar.master_instance.pk # current_day = dd.today() + timedelta(days=delta_days) delta_days += int(week_day.value) - dd.today().weekday() - 1 today = dd.today(delta_days) # current_week_day = current_day + \ # timedelta(days=int(week_day.value) - current_day.weekday() - 1) qs = qs.filter(start_date=today) qs = qs.order_by('start_time') if obj is cls.model.HEADER_ROW: chunks = obj.get_header_chunks(ar, qs, today) else: chunks = obj.get_weekly_chunks(ar, qs, today) return E.table(E.tr(E.td(E.div(*join_elems(chunks)))), CLASS="fixed-table")
def row2html(self, recno, columns, row, sums, **cellattrs): has_numeric_value = False cells = [] for i, col in enumerate(columns): v = col.field._lino_atomizer.full_value_from_object(row, self) if v is None: td = E.td(**cellattrs) else: nv = col.value2num(v) if nv != 0: sums[i] += nv has_numeric_value = True td = col.value2html(self, v, **cellattrs) col.apply_cell_format(td) self.actor.apply_cell_format(self, row, col, recno, td) cells.append(td) if self.actor.hide_zero_rows and not has_numeric_value: return None return cells
def to_html(self, ar): self.analyze_view() if self.mode == TABLE_MODE: sep = ' ' fmt = day_and_weekday elif self.mode == UL_MODE: sep = ' ' fmt = day_and_weekday elif self.mode == PLAIN_MODE: sep = ', ' fmt = dd.fds def rnd(obj, ar): if self.model is rt.models.cal.Guest: d = obj.event.start_date evt = obj.event else: d = obj.start_date evt = obj # if show_auto_num and evt.auto_type: # yield str(evt.auto_type)+":" yield ar.obj2html(evt, fmt(d)) if obj.state.button_text: yield str(obj.state.button_text) # return (fdmy(d) + ": ", ar.obj2html(evt, lbl)) def xxx(list_of_entries): elems = [] # for e in reversed(list_of_entries): for e in list_of_entries: if len(elems): elems.append(sep) elems.extend(rnd(e, ar)) return elems if self.mode == TABLE_MODE: rows = [] cells = [E.th("")] + [E.th(monthname(m + 1)) for m in range(12)] # print(''.join([tostring(c) for c in cells])) rows.append(E.tr(*cells)) for y in self.years.values(): cells = [E.td(str(y.year), width="4%")] for m in y.months: # every m is a list of etree elems cells.append( E.td(*xxx(m), width="8%", **ar.renderer.cellattrs)) # print(str(y.year) +":" + ''.join([tostring(c) for c in cells])) rows.append(E.tr(*cells)) return E.table(*rows, **ar.renderer.tableattrs) if self.mode == UL_MODE: items = [] for y in self.years.values(): for m, lst in enumerate(reversed(y.months)): # January is [11], Dec is [0] if len(lst): items.append( E.li(monthname(12 - m), " ", str(y.year), ": ", *xxx(lst))) return E.ul(*items) if self.mode == PLAIN_MODE: elems = [] for y in self.years.values(): for lst in y.months: if len(lst): if len(elems): elems.append(sep) elems.extend(xxx(lst)) return E.p(*elems) raise Exception("20180720")
def to_html(self, ar): self.analyze_view() if self.mode == TABLE_MODE: sep = ' ' fmt = day_and_weekday elif self.mode == UL_MODE: sep = ' ' fmt = day_and_weekday elif self.mode == PLAIN_MODE: sep = ', ' fmt = dd.fds def rnd(obj, ar): if self.model is rt.models.cal.Guest: d = obj.event.start_date evt = obj.event else: d = obj.start_date evt = obj # if show_auto_num and evt.auto_type: # yield str(evt.auto_type)+":" yield ar.obj2html(evt, fmt(d)) if obj.state.button_text: yield str(obj.state.button_text) # return (fdmy(d) + ": ", ar.obj2html(evt, lbl)) def xxx(list_of_entries): elems = [] # for e in reversed(list_of_entries): for e in list_of_entries: if len(elems): elems.append(sep) elems.extend(rnd(e, ar)) return elems if self.mode == TABLE_MODE: rows = [] cells = [E.th("")] + [E.th(monthname(m+1)) for m in range(12)] # print(''.join([tostring(c) for c in cells])) rows.append(E.tr(*cells)) for y in self.years.values(): cells = [E.td(str(y.year), width="4%")] for m in y.months: # every m is a list of etree elems cells.append(E.td(*xxx(m), width="8%", **ar.renderer.cellattrs)) # print(str(y.year) +":" + ''.join([tostring(c) for c in cells])) rows.append(E.tr(*cells)) return E.table(*rows, **ar.renderer.tableattrs) if self.mode == UL_MODE: items = [] for y in self.years.values(): for m, lst in enumerate(reversed(y.months)): # January is [11], Dec is [0] if len(lst): items.append(E.li( monthname(12-m), " ", str(y.year), ": ", *xxx(lst))) return E.ul(*items) if self.mode == PLAIN_MODE: elems = [] for y in self.years.values(): for lst in y.months: if len(lst): if len(elems): elems.append(sep) elems.extend(xxx(lst)) return E.p(*elems) raise Exception("20180720")
def navigation_panel(cls, obj, ar): if ar is None: return None # if ar.actor.navigator is None: # # raise Exception("Oops, {} has no navigator".format(cls)) # print("Oops, {} has no navigator".format(cls)) # return None today = obj.date # daily, weekly, monthly = obj.cal_view.navigator.make_link_funcs(ar) daily = obj.planner.daily_button_func(ar) weekly = obj.planner.weekly_button_func(ar) monthly = obj.planner.monthly_button_func(ar) if obj.navigation_mode == 'day': long_unit = DurationUnits.months short_unit = DurationUnits.days current_view = daily elif obj.navigation_mode == 'week': long_unit = DurationUnits.months short_unit = DurationUnits.weeks current_view = weekly elif obj.navigation_mode == 'month': long_unit = DurationUnits.years short_unit = DurationUnits.months current_view = monthly else: raise Exception("20200224") daily_mode = bool(obj.navigation_mode == 'day') weekly_mode = bool(obj.navigation_mode == 'week') month_mode = bool(obj.navigation_mode == 'month') # todo ensure that the end of the month is always in the view. # long_unit = DurationUnits.years if month_mode else DurationUnits.months long_prev = cls.get_row_by_pk( ar, date2pk(long_unit.add_duration(today, -1))) long_next = cls.get_row_by_pk( ar, date2pk(long_unit.add_duration(today, 1))) # next_unit = DurationUnits.weeks if weekly_mode else DurationUnits.days if day_view else DurationUnits.months short_prev = cls.get_row_by_pk( ar, date2pk(short_unit.add_duration(today, -1))) short_next = cls.get_row_by_pk( ar, date2pk(short_unit.add_duration(today, 1))) # current_view = weekly if weekly_mode else daily # current_view = daily # if not day_view: # current_view = monthly if month_mode else weekly elems = [] #cls.calender_header(ar) # Month div rows, cells = [], [] for i, month in enumerate(YearMonths.get_list_items()): pk = date2pk( DurationUnits.months.add_duration(today, i + 1 - today.month)) if today.month == i + 1: if not month_mode: cells.append( E.td( E.b(monthly(cls.get_row_by_pk(ar, pk), str(month))))) else: cells.append(E.td(E.b(str(month)))) else: cells.append( E.td(monthly(cls.get_row_by_pk(ar, pk), str(month)))) if (i + 1) % 3 == 0: rows.append(E.tr(*cells, align="center")) cells = [] monthly_div = E.div(E.table(*rows, align="center"), CLASS="cal-month-table") header = [ current_view(long_prev, "<<"), " ", current_view(short_prev, "<"), E.span( E.span("{} {}".format(monthname(today.month), today.year), E.br(), monthly_div)), current_view(short_next, ">"), " ", current_view(long_next, ">>") ] elems.append(E.h2(*header, align="center")) weekdaysFirstLetter = " " + "".join( [gettext(week.text)[0] for week in Weekdays.objects()]) rows = [ E.tr(*[ E.td(E.b(day_of_week)) for day_of_week in weekdaysFirstLetter ], align='center') ] for week in CALENDAR.monthdatescalendar(today.year, today.month): # each week is a list of seven datetime.date objects. cells = [] current_week = week[0].isocalendar()[1] this_week = False for day in week: pk = date2pk(day) link = daily(cls.get_row_by_pk(ar, pk), str(day.day)) if day == dd.today(): link = E.b(link, CLASS="cal-nav-today") if day == today and daily_mode: cells.append(E.td(E.b(str(day.day)))) else: cells.append(E.td(link)) if day.isocalendar()[1] == today.isocalendar()[1]: this_week = True else: if this_week and weekly_mode: txt = E.b(str(current_week)) else: pk = date2pk(week[0]) txt = weekly(cls.get_row_by_pk(ar, pk), str(current_week)) cells = [E.td(txt, CLASS="cal-week")] + cells rows.append(E.tr(*cells, align="center")) today = cls.get_row_by_pk(ar, 0) elems.append(E.table(*rows, align="center")) elems.append(E.p(daily(today, gettext("Today")), align="center")) elems.append(E.p(weekly(today, gettext("This week")), align="center")) elems.append(E.p(monthly(today, gettext("This month")), align="center")) # for o in range(-10, 10): # elems.append(ar.goto_pk(o, str(o))) # elems.append(" ") return E.div(*elems, CLASS="lino-nav-cal")
def navigation_panel(cls, obj, ar): day_view = bool(cls.navigation_mode == 'day') weekly_view = bool(cls.navigation_mode == 'week') month_view = bool(cls.navigation_mode == 'month') # todo ensure that the end of the month is always in the view. today = obj.date daily, weekly, monthly = make_link_funcs(ar) long_unit = DurationUnits.years if month_view else DurationUnits.months prev_month = Day(date2pk(long_unit.add_duration(today, -1))) next_month = Day(date2pk(long_unit.add_duration(today, 1))) next_unit = DurationUnits.weeks if weekly_view else DurationUnits.days if day_view else DurationUnits.months prev_view = Day(date2pk(next_unit.add_duration(today, -1))) next_view = Day(date2pk(next_unit.add_duration(today, 1))) # current_view = weekly if weekly_view else daily current_view = daily if not day_view: current_view = monthly if month_view else weekly elems = [] #cls.calender_header(ar) # Month div rows, cells = [], [] for i, month in enumerate(YearMonths.get_list_items()): # each week is a list of seven datetime.date objects. pk = date2pk( DurationUnits.months.add_duration( today, int(month.value) - today.month)) if today.month == int(month.value): if not month_view: cells.append(E.td(E.b(monthly(Day(pk), str(month))))) else: cells.append(E.td(E.b(str(month)))) else: cells.append(E.td(monthly(Day(pk), str(month)))) if (i + 1) % 3 == 0: rows.append(E.tr(*cells, align="center")) cells = [] monthly_div = E.div(E.table(*rows, align="center"), CLASS="cal-month-table") header = [ current_view(prev_month, "<<"), " ", current_view(prev_view, "<"), E.span( E.span("{} {}".format(monthname(today.month), today.year), E.br(), monthly_div)), current_view(next_view, ">"), " ", current_view(next_month, ">>") ] elems.append(E.h2(*header, align="center")) weekdaysFirstLetter = " " + "".join( [gettext(week.text)[0] for week in Weekdays.objects()]) rows = [ E.tr(*[ E.td(E.b(day_of_week)) for day_of_week in weekdaysFirstLetter ], align='center') ] for week in CALENDAR.monthdatescalendar(today.year, today.month): # each week is a list of seven datetime.date objects. cells = [] current_week = week[0].isocalendar()[1] this_week = False for day in week: pk = date2pk(day) link = daily(Day(pk), str(day.day)) if day == dd.today(): link = E.b(link, CLASS="cal-nav-today") if day == today and day_view: cells.append(E.td(E.b(str(day.day)))) else: cells.append(E.td(link)) if day.isocalendar()[1] == today.isocalendar()[1]: this_week = True else: cells = [ E.td(E.b(str(current_week)) if this_week and weekly_view else weekly(Day(pk), str(current_week)), CLASS="cal-week") ] + cells rows.append(E.tr(*cells, align="center")) elems.append(E.table(*rows, align="center")) elems.append(E.p(daily(Day(), gettext("Today")), align="center")) elems.append(E.p(weekly(Day(), gettext("This week")), align="center")) elems.append(E.p(monthly(Day(), gettext("This month")), align="center")) # for o in range(-10, 10): # elems.append(ar.goto_pk(o, str(o))) # elems.append(" ") return E.div(*elems, CLASS="lino-nav-cal")