def get_table_summary(self, obj, ar): items = [] def add(title, flt): links = [] sar = self.request(master_instance=obj, filter=flt) # logger.info("20141009 %s", sar.data_iterator.query) n = sar.get_total_count() if n: for i, ex in enumerate(sar): txt = self.format_excerpt(ex) if ex.build_time is not None: txt += " (%s)" % naturaltime(ex.build_time) links.append(ar.obj2html(ex, txt)) if i >= self.MORE_LIMIT: # links.append(ar.href_to_request(sar, _("more"))) links.append('...') break items.append(E.li(title, " : ", *join_elems(links, sep=', '))) # qs = sar.data_iterator Q = models.Q add(gettext("not printed"), Q(build_time__isnull=True)) add(gettext("Today"), Q(build_time__gte=dd.today() - ONE_DAY)) t7 = dd.today() - ONE_WEEK add(gettext("Last week"), Q(build_time__lte=dd.today(), build_time__gte=t7)) add(gettext("Older"), Q(build_time__lt=t7)) return E.ul(*items)
def calender_header(ar): header = "Calendar Type" elems = [E.h2(*header, align="center")] today_url = ar.renderer.js2url(""" Lino.cal.DailyView.detail.run(null, {"record_id": 0}) """) week_url = ar.renderer.js2url(""" Lino.cal.WeeklyView.detail.run(null, {"record_id": 0}) """) elems.append(E.p(ar.renderer.href(today_url, gettext("Day")), align="center")) elems.append(E.p(ar.renderer.href(week_url, gettext("Week")), align="center")) elems.append(E.p(ar.goto_pk(0, gettext("This month")), align="center")) return elems
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 format_as_html(self, ar): elems = [] if len(self.used_events) == 0: return E.p(gettext("No invoiced events")) # used_events = list(self.used_events) invoiced = self.used_events[self.invoiced_events:] coming = self.used_events[:self.invoiced_events] fmt = self.generator.get_invoiceable_event_formatter() # def fmt(ev): # return self.generator.format_invoiceable_event(ev, ar) if len(invoiced) > 0: elems.append("{0} : ".format(_("Invoiced"))) if len(invoiced) > MAX_SHOWN: elems.append("(...) ") invoiced = invoiced[-MAX_SHOWN:] elems += join_elems(map(fmt, invoiced), sep=', ') # s += ', '.join(map(fmt, invoiced)) # elems.append(E.p(s)) if len(coming) > 0: if len(elems) > 0: elems.append(E.br()) elems.append("{0} : ".format(_("Not invoiced"))) elems += join_elems(map(fmt, coming), sep=', ') # s += ', '.join(map(fmt, coming)) # elems.append(E.p(s)) return E.p(*elems)
def find_links(self, ar, child, parent): if not dd.is_installed('humanlinks'): return [] types = {} # mapping LinkType -> list of parents for lnk in rt.models.humanlinks.Link.objects.filter(child=child): # child=child, parent=p): tt = lnk.type.as_child(lnk.child) l = types.setdefault(tt, []) l.append(lnk.parent) elems = [] for tt, parents in types.items(): if len(elems): elems.append(', ') text = join_elems( [parent.format_family_member(ar, p) for p in parents], sep=gettext(" and ")) elems += [tt, gettext(" of ")] + text return elems
def find_links(self, ar, child, parent): if not dd.is_installed('humanlinks'): return [] types = {} # mapping LinkType -> list of parents for lnk in rt.models.humanlinks.Link.objects.filter(child=child): # child=child, parent=p): tt = lnk.type.as_child(lnk.child) l = types.setdefault(tt, []) l.append(lnk.parent) elems = [] for tt, parents in types.items(): if len(elems): elems.append(', ') text = join_elems( [parent.format_family_member(ar, p) for p in parents], sep=" {} ".format(gettext("and"))) elems += [tt, gettext(" of ")] + text return elems
def __str__(rule): lst = [] only = [] lst.append(gettext("VAT rule {}: ".format(rule.value))) if rule.trade_type is not None: only.append(str(rule.trade_type)) if rule.vat_regime is not None: only.append(str(rule.vat_regime)) if rule.vat_area is not None: only.append(str(rule.vat_area)) if rule.vat_class is not None: only.append(str(rule.vat_class)) if len(only): lst.append(gettext("if ({}) then".format(', '.join(only)))) lst.append(gettext("apply {} %".format(rule.rate))) lst.append(gettext("and book to {}").format(rule.vat_account)) if rule.vat_returnable_account is not None: lst.append(gettext("(return to {})").format(rule.vat_returnable_account)) return '\n'.join(lst)
def get_table_summary(self, obj, ar): sar = self.request(master_instance=obj) elems = [] # n = sar.get_total_count() # if n == 0: # elems += [_("Not member of any household."), E.br()] # else: items = [] for m in sar.data_iterator: args = (str(m.role), gettext(" in "), ar.obj2html(m.household)) if m.primary: items.append(E.li(E.b("\u2611 ", *args))) else: btn = m.set_primary.as_button_elem( ar, "\u2610 ", style="text-decoration:none;") items.append(E.li(btn, *args)) if len(items) > 0: elems += [gettext("%s is") % obj] elems.append(E.ul(*items)) if self.insert_action is not None: sar = self.insert_action.request_from(ar) if sar.get_permission(): elems.append(E.br()) sar.known_values.update(person=obj) # sar.known_values.pop('child', None) elems += [ sar.ar2button(None, gettext("Join an existing household"), icon_name=None), " ", gettext("or"), " ", ar.instance_action_button(obj.create_household, gettext("create a new one")), # " ", # rt.models.households.Household._meta.verbose_name, "." ] return E.div(*elems)
def ca_fmt(ar, ca): if ar is None or ca is None: return '' elems = [] obj = ca.get_object() if obj is None: elems.append(gettext("(undefined)")) else: elems.append(ar.obj2html(obj)) elems.append(u" ({})".format(ca)) return E.div(*elems)
def get_table_summary(self, obj, ar): sar = self.request(master_instance=obj) elems = [] # n = sar.get_total_count() # if n == 0: # elems += [_("Not member of any household."), E.br()] # else: items = [] for m in sar.data_iterator: args = (str(m.role), gettext(" in "), ar.obj2html(m.household)) if m.primary: items.append(E.li(E.b("\u2611 ", *args))) else: btn = m.set_primary.as_button_elem( ar, "\u2610 ", style="text-decoration:none;") items.append(E.li(btn, *args)) if len(items) > 0: elems += [gettext("%s is") % obj] elems.append(E.ul(*items)) if self.insert_action is not None: sar = self.insert_action.request_from(ar) if sar.get_permission(): elems.append(E.br()) sar.known_values.update(person=obj) # sar.known_values.pop('child', None) elems += [ sar.ar2button( None, gettext("Join an existing household"), icon_name=None), " ", gettext("or"), " ", ar.instance_action_button( obj.create_household, gettext("create a new one")), # " ", # rt.models.households.Household._meta.verbose_name, "."] return E.div(*elems)
def description(cls, rule, ar): if ar is None: return '' lst = [] only = [] lst.append(gettext("Rate {}".format(rule.rate))) if rule.trade_type is not None: only.append(str(rule.trade_type)) if rule.vat_regime is not None: only.append(str(rule.vat_regime)) if rule.vat_area is not None: only.append(str(rule.vat_area)) if rule.vat_class is not None: only.append(str(rule.vat_class)) if len(only): lst.append(gettext("When {}".format(', '.join(only)))) lst.append(gettext("Book to {}").format(rule.vat_account)) if rule.vat_returnable: lst.append(gettext("Returnable to {}").format(rule.vat_returnable_account)) return '\n'.join(lst)
def ca_fmt(ar, ca): if ar is None or ca is None: return '' elems = [] obj = ca.get_object() if obj is None: elems.append(gettext("(undefined)")) else: # elems.append(ar.obj2html(obj)) elems.append(str(obj)) elems.append(u" ({})".format(ca)) return E.div(*elems)
def before_execute(self, ar, obj): if obj.event_type and obj.event_type.force_guest_states: # no need to check guest states because they will be forced return rgs = self.refuse_guest_states if not rgs: return # presto changes refuse_guest_states in its workflow_module, that's why # we re-evaluate it here for each request. # rgs = (GuestStates.get_by_name(x) for x in self.refuse_guest_states.split()) # qs = obj.guest_set.filter(state=GuestStates.invited) qs = obj.guest_set.filter(state__in=self.refuse_guest_states) count = qs.count() if count > 0: guest_states = (" " + gettext("or") + " ").join([str(s.text) for s in rgs]) msg = gettext( "Cannot mark as {state} because {count} " "participants are {guest_states}.") raise Warning(msg.format( count=count, state=self.target_state, guest_states=guest_states))
def welcome_messages(ar): """Yield messages for the welcome page.""" #todo show all users active sessions Session = rt.models.working.Session # Ticket = rt.models.tickets.Ticket # TicketStates = rt.models.tickets.TicketStates me = ar.get_user() # your open sessions (i.e. those you are busy with) qs = Session.objects.filter(end_time__isnull=True) working = {me: [E.b(str(_("You are busy with ")))]} if qs.count() == 0: return for ses in qs: if ses.user not in working: working[ses.user] = [ ar.obj2html(ses.user), gettext(" is working on: ") ] txt = str(ses.ticket) working[ses.user].append( ar.obj2html(ses.ticket, txt, title=getattr(ses.ticket, 'summary', "") or getattr(ses.ticket, 'name', ""))) if ses.user == me: working[ses.user] += [ ' (', ar.instance_action_button(ses.end_session, EndTicketSession.label), ')' ] working[ses.user].append(', ') if len(working[me]) > 1: working[me][-1] = working[me][-1].replace(", ", ".") result = E.p(*working.pop(me)) else: result = E.p() working.pop(me) for u, s in working.items(): if len(result): result.append(E.br()) s[-1] = s[-1].replace(", ", ".") result.append(E.span(*s)) yield result
def welcome_messages(ar): """Yield messages for the welcome page.""" #todo show all users active sessions Session = rt.models.working.Session # Ticket = rt.models.tickets.Ticket # TicketStates = rt.models.tickets.TicketStates me = ar.get_user() # your open sessions (i.e. those you are busy with) qs = Session.objects.filter(end_time__isnull=True) working = {me:[E.b(six.text_type(_("You are busy with ")))]} if qs.count() == 0: return for ses in qs: if ses.user not in working: working[ses.user] = [ar.obj2html(ses.user), gettext(" is working on: ")] txt = six.text_type(ses.ticket) working[ses.user].append( ar.obj2html(ses.ticket, txt, title=getattr(ses.ticket,'summary',"") or getattr(ses.ticket,'name',""))) if ses.user == me: working[ses.user] += [ ' (', ar.instance_action_button( ses.end_session, EndTicketSession.label), ')'] working[ses.user].append(', ') if len(working[me]) > 1: working[me][-1] = working[me][-1].replace(", ", ".") result = E.p(*working.pop(me)) else: result = E.p() working.pop(me) for u, s in working.items(): if len(result): result.append(E.br()) s[-1] = s[-1].replace(", ", ".") result.append(E.span(*s)) yield result
def get_table_summary(self, obj, ar): """The :meth:`summary view <lino.core.actors.Actor.get_table_summary>` for :class:`LinksByHuman`. """ if obj is None: return '' # if obj.pk is None: # return '' # raise Exception("20150218") sar = self.request_from(ar, master_instance=obj) links = [] for lnk in sar: if lnk.parent is None or lnk.child is None: pass else: if lnk.child_id == obj.id: i = (lnk.type.as_child(obj), lnk.parent) else: i = (lnk.type.as_parent(obj), lnk.child) links.append(i) try: links.sort(key=lambda a: a[1].birth_date.as_date(), reverse=True) # except AttributeError: except (AttributeError, ValueError): # AttributeError: 'str' object has no attribute 'as_date' # possible when empty birth_date # ValueError: day is out of range for month pass items = [] for type, other in links: items.append( E.li(str(type), gettext(" of "), obj.format_family_member(ar, other), " (%s)" % other.age)) elems = [] if len(items) > 0: elems += [gettext("%s is") % obj.first_name] elems.append(E.ul(*items)) else: elems.append(gettext("No relationships.")) # Buttons for creating relationships: if self.insert_action is not None: sar = self.insert_action.request_from(ar) if sar.get_permission(): actions = [] for lt in self.addable_link_types: sar.known_values.update(type=lt, parent=obj) sar.known_values.pop('child', None) #sar = ar.spawn(self, known_values=dict(type=lt, parent=obj)) btn = sar.ar2button(None, lt.as_parent(obj), icon_name=None) actions.append(btn) if not lt.symmetric: actions.append('/') sar.known_values.update(type=lt, child=obj) sar.known_values.pop('parent', None) btn = sar.ar2button(None, lt.as_child(obj), icon_name=None) actions.append(btn) actions.append(' ') if len(actions) > 0: elems += [E.br(), gettext("Create relationship as ")] + actions return E.div(*elems)
def get_change_info(self, ar, cw): yield E.p( gettext("Subject"), ': ', self.subject, E.br(), gettext("Client"), ': ', ar.obj2memo(self.project))
def __str__(self): if self.build_time: return str(naturaltime(self.build_time)) # return _("%(owner)s (printed %(time)s)") % dict( # owner=self.owner, time=naturaltime(self.build_time)) return gettext("Unprinted %s #%s") % (self._meta.verbose_name, self.pk)
def get_table_summary(self, obj, ar): """The :meth:`summary view <lino.core.actors.Actor.get_table_summary>` for :class:`LinksByHuman`. """ if obj is None: return '' # if obj.pk is None: # return '' # raise Exception("20150218") sar = self.request_from(ar, master_instance=obj) links = [] for lnk in sar: if lnk.parent is None or lnk.child is None: pass else: if lnk.child_id == obj.id: i = (lnk.type.as_child(obj), lnk.parent) else: i = (lnk.type.as_parent(obj), lnk.child) links.append(i) try: links.sort( key=lambda a: a[1].birth_date.as_date(), reverse=True) # except AttributeError: except (AttributeError, ValueError): # AttributeError: 'str' object has no attribute 'as_date' # possible when empty birth_date # ValueError: day is out of range for month pass items = [] for type, other in links: items.append(E.li( str(type), gettext(" of "), obj.format_family_member(ar, other), " (%s)" % other.age )) elems = [] if len(items) > 0: elems += [gettext("%s is") % obj.first_name] elems.append(E.ul(*items)) else: elems.append(gettext("No relationships.")) # Buttons for creating relationships: if self.insert_action is not None: sar = self.insert_action.request_from(ar) if sar.get_permission(): actions = [] for lt in self.addable_link_types: sar.known_values.update(type=lt, parent=obj) sar.known_values.pop('child', None) #sar = ar.spawn(self, known_values=dict(type=lt, parent=obj)) btn = sar.ar2button(None, lt.as_parent(obj), icon_name=None) actions.append(btn) if not lt.symmetric: actions.append('/') sar.known_values.update(type=lt, child=obj) sar.known_values.pop('parent', None) btn = sar.ar2button(None, lt.as_child(obj), icon_name=None) actions.append(btn) actions.append(' ') if len(actions) > 0: elems += [E.br(), gettext("Create relationship as ")] + actions return E.div(*elems)
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")