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 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 about_html(cls): body = [] body.append(settings.SITE.welcome_html()) if settings.SITE.languages: body.append( E.p( str(_("Languages")) + ": " + ', '.join( [lng.django_code for lng in settings.SITE.languages]))) # print "20121112 startup_time", settings.SITE.startup_time.date() # showing startup time here makes no sense as this is a constant text # body.append(E.p( # gettext("Server uptime"), ' : ', # E.b(dtfmt(settings.SITE.startup_time)), # ' ({})'.format(settings.TIME_ZONE))) if settings.SITE.is_demo_site: body.append(E.p(gettext(_("This is a Lino demo site.")))) if settings.SITE.the_demo_date: s = _("We are running with simulated date set to {0}.").format( dd.fdf(settings.SITE.the_demo_date)) body.append(E.p(s)) body.append(E.p(str(_("Source timestamps:")))) items = [] times = [] packages = set(['django']) items.append( E.li(gettext("Server timestamp"), ' : ', E.b(dtfmt(settings.SITE.kernel.code_mtime)))) for p in settings.SITE.installed_plugins: packages.add(p.app_name.split('.')[0]) for src in packages: label = src value = codetime('%s.*' % src) if value is not None: times.append((label, value)) times.sort(key=lambda x: x[1]) for label, value in times: items.append(E.li(str(label), ' : ', E.b(dtfmt(value)))) body.append(E.ul(*items)) body.append( E.p("{} : {}".format( _("Complexity factors"), ', '.join(analyzer.get_complexity_factors(dd.today()))))) return rt.html_text(E.div(*body))
def get_table_summary(self, obj, ar): if ar is None: return '' elems = [] # Button for starting a session from ticket sar = obj.start_session.request_from(ar) # if ar.renderer.is_interactive and sar.get_permission(): # if sar.get_permission(): # btn = sar.ar2button(obj) # elems += [E.p(btn)] # Active sessions: active_sessions = [] session_summaries = E.ul() qs = rt.models.working.Session.objects.filter(ticket=obj) tot = Duration() for ses in qs: d = ses.get_duration() if d is not None: tot += d if ses.end_time is None: txt = "{0} since {1}".format(ses.user, ses.start_time) lnk = ar.obj2html(ses, txt) sar = ses.end_session.request_from(ar) if sar.get_permission(): lnk = E.span(lnk, " ", sar.ar2button(ses)) active_sessions.append(lnk) if ses.summary: session_summaries.insert(0, E.li( "%s %s: %s"%(ses.user, naturaltime(datetime.combine( ses.start_date, ses.start_time)) ,ses.summary) ) ) # elems.append(E.p(_("Total {0} hours.").format(tot))) elems.append(E.p(_("Total %s hours.") % tot)) if len(active_sessions) > 0: elems.append(E.p( ensureUtf(_("Active sessions")), ": ", *join_elems(active_sessions, ', '))) if len(session_summaries) > 0: elems.append(session_summaries) return ar.html_text(E.div(*elems))
def about_html(cls): body = [] body.append(settings.SITE.welcome_html()) if settings.SITE.languages: body.append( E.p( str(_("Languages")) + ": " + ', '.join( [lng.django_code for lng in settings.SITE.languages]))) # print "20121112 startup_time", settings.SITE.startup_time.date() def dtfmt(dt): if isinstance(dt, float): dt = datetime.datetime.fromtimestamp(dt) # raise ValueError("Expected float, go %r" % dt) return str(_("%(date)s at %(time)s")) % dict( date=dd.fds(dt.date()), time=settings.SITE.strftime(dt.time())) value = settings.SITE.startup_time label = _("Server uptime") body.append( E.p(str(label), ' : ', E.b(dtfmt(value)), ' ({})'.format(settings.TIME_ZONE))) if settings.SITE.is_demo_site: s = str(_("This is a Lino demo site.")) body.append(E.p(s)) if settings.SITE.the_demo_date: s = _("We are running with simulated date set to {0}.").format( dd.fdf(settings.SITE.the_demo_date)) body.append(E.p(s)) body.append(E.p(str(_("Source timestamps:")))) items = [] times = [] packages = set(['lino', 'django', 'atelier']) for p in settings.SITE.installed_plugins: packages.add(p.app_name.split('.')[0]) for src in packages: label = src value = codetime('%s.*' % src) if value is not None: times.append((label, value)) times.sort(key=lambda x: x[1]) for label, value in times: items.append(E.li(str(label), ' : ', E.b(dtfmt(value)))) body.append(E.ul(*items)) return rt.html_text(E.div(*body))
def about_html(cls): body = [] body.append(settings.SITE.welcome_html()) if settings.SITE.languages: body.append(E.p(str(_("Languages")) + ": " + ', '.join([ lng.django_code for lng in settings.SITE.languages]))) # print "20121112 startup_time", settings.SITE.startup_time.date() def dtfmt(dt): if isinstance(dt, float): dt = datetime.datetime.fromtimestamp(dt) # raise ValueError("Expected float, go %r" % dt) return str(_("%(date)s at %(time)s")) % dict( date=dd.fds(dt.date()), time=settings.SITE.strftime(dt.time())) value = settings.SITE.startup_time label = _("Server uptime") body.append(E.p( str(label), ' : ', E.b(dtfmt(value)), ' ({})'.format(settings.TIME_ZONE))) if settings.SITE.is_demo_site: s = str(_("This is a Lino demo site.")) body.append(E.p(s)) if settings.SITE.the_demo_date: s = _("We are running with simulated date set to {0}.").format( dd.fdf(settings.SITE.the_demo_date)) body.append(E.p(s)) body.append(E.p(str(_("Source timestamps:")))) items = [] times = [] packages = set(['lino', 'django', 'atelier']) for p in settings.SITE.installed_plugins: packages.add(p.app_name.split('.')[0]) for src in packages: label = src value = codetime('%s.*' % src) if value is not None: times.append((label, value)) times.sort(key=lambda x: x[1]) for label, value in times: items.append(E.li(str(label), ' : ', E.b(dtfmt(value)))) body.append(E.ul(*items)) return rt.html_text(E.div(*body))
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 get_table_summary(self, obj, ar): if ar is None: return '' elems = [] # Button for starting a session from ticket sar = obj.start_session.request_from(ar) # if ar.renderer.is_interactive and sar.get_permission(): # if sar.get_permission(): # btn = sar.ar2button(obj) # elems += [E.p(btn)] # Active sessions: active_sessions = [] session_summaries = E.ul() qs = rt.models.working.Session.objects.filter(ticket=obj) tot = Duration() for ses in qs: d = ses.get_duration() if d is not None: tot += d if ses.end_time is None: txt = "{0} since {1}".format(ses.user, ses.start_time) lnk = ar.obj2html(ses, txt) sar = ses.end_session.request_from(ar) if sar.get_permission(): lnk = E.span(lnk, " ", sar.ar2button(ses)) active_sessions.append(lnk) if ses.summary: session_summaries.insert( 0, E.li("%s %s: %s" % (ses.user, naturaltime( datetime.combine(ses.start_date, ses.start_time)), ses.summary))) # elems.append(E.p(_("Total {0} hours.").format(tot))) elems.append(E.p(_("Total %s hours.") % tot)) if len(active_sessions) > 0: elems.append( E.p(ensureUtf(_("Active sessions")), ": ", *join_elems(active_sessions, ', '))) if len(session_summaries) > 0: elems.append(session_summaries) return ar.html_text(E.div(*elems))
def get_table_summary(self, mi, ar): if ar is None: return '' sar = self.request_from(ar, master_instance=mi) def fmt(obj): return str(obj) elems = [] for obj in sar: # if len(elems) > 0: # elems.append(', ') lbl = fmt(obj) # if obj.state.button_text: # lbl = "{0}{1}".format(lbl, obj.state.button_text) elems.append(ar.obj2html(obj, lbl)) elems = join_elems(elems, sep=', ') toolbar = [] ar2 = self.insert_action.request_from(sar) if ar2.get_permission(): btn = ar2.ar2button() toolbar.append(btn) if len(toolbar): toolbar = join_elems(toolbar, sep=' ') elems.append(E.p(*toolbar)) return ar.html_text(E.div(*elems))
def build_confirmation_message(self): self.analyze() items = [] def collect_summary(prefix, fk_qs): parts = [] for fld, qs in fk_qs: if qs.count() > 0: parts.append( "%d %s" % ( qs.count(), str( fld.model._meta.verbose_name_plural))) if len(parts) != 0: items.append(E.li(', '.join(parts), ' ', E.b(prefix))) collect_summary(ugettext("will be deleted."), self.volatiles) collect_summary(ugettext("will get reassigned."), self.related + self.generic_related) items.append(E.li(ugettext("%s will be deleted") % self.obj)) msg = ugettext("Are you sure you want to merge " "%(this)s into %(merge_to)s?") % dict( this=self.obj, merge_to=self.merge_to) if len(items) != 0: return rt.html_text(E.div(E.p(msg), E.ul(*items))) return msg
def get_table_summary(cls, obj, ar, max_num=10, **context): context = ar.get_printable_context(**context) qs = rt.models.blogs.Entry.objects.filter(pub_date__isnull=False) qs = qs.order_by("-pub_date") render = dd.plugins.jinja.render_jinja elems = [] for num, e in enumerate(qs): if num >= max_num: break context.update(obj=e) # s = render(ar, 'blogs/entry.html', context) elems.append(E.h2(e.title or str(e), " ", e.obj2href( ar, u"⏏", **{'style': "text-decoration:none"}))) # s = ar.parse_memo(e.short_preview) s = e.short_preview tree = etree.parse(StringIO(s), html_parser) # elems.extend(tree.iter()) # elems.append(tree.iter().next()) elems.append(tree.getroot()) elems.append(E.p( _("{} by {}").format(dd.fdf(e.pub_date), e.user))) # elems.append(E.p( # _("{} by {}").format(dd.fdf(e.pub_date), e.user), # " ", e.obj2href(ar, "(edit)"))) return E.div(*elems)
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 print_actions(self, ar): if ar is None: return '' elems = [] elems.append(ar.instance_action_button(self.print_presence_sheet)) elems.append(ar.instance_action_button(self.print_presence_sheet_html)) return E.p(*join_elems(elems, sep=", "))
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 print_actions(self, ar): if ar is None: return '' elems = [] elems.append(ar.instance_action_button( self.write_xml)) return E.p(*join_elems(elems, sep=", "))
def contact_details(self, ar): if ar is None: return '' sar = rt.models.phones.ContactDetailsByPartner.request(parent=ar, master_instance=self) items = [o.detail_type.as_html(o, sar) for o in sar if not o.end_date] return E.p(*join_elems(items, sep=', '))
def get_table_summary(self, obj, ar): sar = self.request_from(ar, master_instance=obj) items = [o.detail_type.as_html(o, sar) for o in sar if not o.end_date] html = [] if len(items) == 0: html += _("No contact details") else: html += join_elems(items, sep=', ') ins = self.insert_action.request_from(sar) if ins.get_permission(): # kw = dict(label=u"⊕") # 2295 circled plus # kw.update(icon_name=None) # # kw.update( # # style="text-decoration:none; font-size:120%;") # btn = ins.ar2button(**kw) btn = ins.ar2button() # if len(items) > 0: # html.append(E.br()) html.append(' ') html.append(btn) if True: html.append(' ') html.append(sar.as_button(icon_name="wrench")) # GEAR # html.append(sar.as_button(u"⚙")) # GEAR # html.append(sar.as_button( # u"⚙", style="text-decoration:none; font-size:140%;")) # GEAR else: html.append(E.br()) html.append(sar.as_button(_("Manage contact details"))) return E.p(*html)
def suppliers(self, ar): """Displays a list of candidate suppliers. This means: all suppliers who have at least one of the skills required by this object. """ if ar is None: return '' if not isinstance(self, dd.plugins.skills.demander_model): return '' Offer = rt.models.skills.Competence Demand = rt.models.skills.Demand skills = set() for dem in Demand.objects.filter(demander=self): skills.add(dem.skill) # skills |= set(dem.skill.get_parental_line()) elems = [] for spl in Offer.objects.filter(faculty__in=skills): if spl.end_user is not None: elems.append(spl.end_user.obj2href(ar)) elems = join_elems(elems, ', ') return E.p(*elems)
def get_change_body(self, ar, cw): ctx = dict(user=ar.user, what=ar.obj2memo(self)) if cw is None: elems = [E.p(_("{user} created {what}").format(**ctx), ".")] elems += list(self.get_change_info(ar, cw)) else: items = list(cw.get_updates_html(["_user_cache"])) if len(items) == 0: return elems = [] elems += list(self.get_change_info(ar, cw)) elems.append( E.p(_("{user} modified {what}").format(**ctx), ":")) elems.append(E.ul(*items)) # print("20170210 {}".format(tostring(E.div(*elems)))) return tostring(E.div(*elems))
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, obj, ar): # obj is a DailyPlannerRow instance mi = ar.master_instance if mi is None: # e.g. when using DailySlave from dashboard. mi = cls.calendar_view.get_row_by_pk(ar, 0) qs = cls.get_calendar_entries(ar, obj) qs = qs.filter(event_type__planner_column=pc) qs = qs.filter(start_date=mi.date) # pv = ar.param_values # qs = Event.calendar_param_filter(qs, pv) # current_day = pv.get('date', dd.today()) # if current_day: # qs = qs.filter(start_date=current_day) # if obj is cls.model.HEADER_ROW: # qs = qs.filter(start_time__isnull=True) # else: # get_plannable_entries # if obj.start_time: # qs = qs.filter(start_time__gte=obj.start_time, # start_time__isnull=False) # if obj.end_time: # qs = qs.filter(start_time__lt=obj.end_time, # start_time__isnull=False) qs = qs.order_by('start_time') chunks = [e.obj2href(ar, cls.get_calview_div(e, ar)) for e in qs] return E.p(*join_elems(chunks))
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 what(self, obj, ar): chunks = [] if obj.name: chunks += [E.b(str(obj)), E.br()] chunks += sepjoin(obj.features.all()) #~ if obj.url: #~ chunks += [E.br(),E.a(_("More"),href=obj.url)] return E.p(*chunks)
def print_actions(self, ar): if ar is None: return '' elems = [] elems.append(ar.instance_action_button(self.print_labels)) elems.append(ar.instance_action_button(self.print_members)) elems.append(ar.instance_action_button(self.print_members_html)) return E.p(*join_elems(elems, sep=", "))
def partners(self, ar): if ar is None: return '' elems = [] qs = rt.models.sepa.Account.objects.filter(iban=self.iban) for obj in qs: elems.append(ar.obj2html(obj.partner)) return E.p(*join_elems(elems, ', '))
def get_change_body(self, ar, cw): ctx = dict(user=ar.user, what=ar.obj2memo(self)) if cw is None: elems = [E.p( _("{user} created {what}").format(**ctx), ".")] elems += list(self.get_change_info(ar, cw)) else: items = list(cw.get_updates_html(["_user_cache"])) if len(items) == 0: return elems = [] elems += list(self.get_change_info(ar, cw)) elems.append(E.p( _("{user} modified {what}").format(**ctx), ":")) elems.append(E.ul(*items)) # print("20170210 {}".format(tostring(E.div(*elems)))) return tostring(E.div(*elems))
def print_actions(self, ar): if ar is None: return '' elems = [] elems.append(ar.instance_action_button( self.print_presence_sheet)) elems.append(ar.instance_action_button( self.print_presence_sheet_html)) return E.p(*join_elems(elems, sep=", "))
def body_subject_to_elems(ar, title, description): if description: elems = [E.p(E.b(title), E.br())] elems += rich_text_to_elems(ar, description) else: elems = [E.b(title)] # return E.span(self.title) return elems
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 description(cls, self, ar): # raise Exception("20191003") if ar is None: return '' elems = [] elems.append(ar.obj2html(self.account)) voucher = self.voucher.get_mti_leaf() if voucher is not None: elems.extend(voucher.get_movement_description(self, ar)) return E.p(*join_elems(elems, " / "))
def description(cls, self, ar): if ar is None: return '' elems = [] voucher = self.voucher.get_mti_leaf() if voucher is not None: elems.extend(voucher.get_movement_description(self, ar)) if self.project: elems.append(ar.obj2html(self.project)) return E.p(*join_elems(elems, " / "))
def get_table_summary(self, obj, ar): chunks = [] for other in ar.spawn(self, master_instance=obj): chunks.append(ar.obj2html(other)) if len(chunks): s = getattr(obj, obj.dupable_words_field) words = ', '.join(obj.get_dupable_words(s)) chunks.append(_("Phonetic words: {0}").format(words)) return E.p(*join_elems(chunks)) return ''
def pupil_info(self, ar): txt = self.pupil.get_full_name(nominative=True) if ar is None: elems = [txt] else: elems = [ar.obj2html(self.pupil, txt)] elems += [', '] elems += join_elems(list(self.pupil.address_location_lines()), sep=', ') return E.p(*elems)
def get(self, request, app_label=None, actor=None, pk=None): ar = action_request(app_label, actor, request, request.GET, False) ar.renderer = settings.SITE.plugins.bootstrap3.renderer navigator = None if pk and pk != '-99999' and pk != '-99998': elem = ar.get_row_by_pk(pk) if elem is None: raise http.Http404("%s has no row with primary key %r" % (ar.actor, pk)) #~ raise Exception("20120327 %s.get_row_by_pk(%r)" % (rpt,pk)) if ar.actor.show_detail_navigator: ni = navinfo(ar.data_iterator, elem) if ni: # m = elem.__class__ buttons = [] #~ buttons.append( ('*',_("Home"), '/' )) buttons.append( ('<<', _("First page"), ar.pk2url(ni['first']))) buttons.append( ('<', _("Previous page"), ar.pk2url(ni['prev']))) buttons.append( ('>', _("Next page"), ar.pk2url(ni['next']))) buttons.append( ('>>', _("Last page"), ar.pk2url(ni['last']))) navigator = buttons2pager(buttons) else: navigator = E.p("No navinfo") else: elem = None main = layout2html(ar, elem) # The `method="html"` argument isn't available in Python 2.6, # only 2.7. It is useful to avoid side effects in case of # empty elements: the default method (xml) writes an empty # E.div() as "<div/>" while in HTML5 it must be "<div></div>" # (and the ending / is ignored). #~ return tostring(main, method="html") #~ return tostring(main) # return main context = dict( title=ar.get_action_title(), obj=elem, form=main, navigator=navigator, ) #~ template = web.jinja_env.get_template('detail.html') context.update(ar=ar) return http_response(ar, ar.actor.detail_html_template, context)
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_table_summary(cls, obj, ar): sar = cls.request_from(ar, master_instance=obj, is_on_main_actor=False) elems = [] if cls.insert_action is not None and isinstance(obj, cls.model): ir = cls.insert_action.request_from(sar) # print(20170217, sar) # sar.known_values = dict( # reply_to=comment, **gfk2lookup( # comment.__class__.owner, comment.owner)) # if ar.get_user().is_authenticated: if ir.get_permission(): # ir.known_values.update(emotion=emo) ir.known_values.update(reply_to=obj) # **gfk2lookup(obj.__class__.owner, obj.owner) ir.clear_cached_status() btn = ir.ar2button(None, _(" Reply "), icon_name=None) # btn.set("style", "padding-left:10px") elems += [" [", btn, "]"] # if ir.get_permission(): # chunks = [gettext("Write new comment:"), " "] # for i, emo in enumerate(Emotions.get_list_items()): # if i: # chunks.append(" | ") # ir.known_values.update(emotion=emo) # ir.clear_cached_status() # chunks.append(ir.ar2button( # None, emo.button_text or emo.text, icon_name=None, # title=str(emo.text))) # elems.append(E.p(*chunks)) n = 0 for com in sar.data_iterator: n += 1 if n > cls.preview_limit: elems.append(E.p("...")) break elems.append(E.p(*cls.summary_row(sar, com))) return E.div(*elems)
def print_actions(self, ar): if ar is None: return '' elems = [] elems.append(ar.instance_action_button( self.print_labels)) elems.append(ar.instance_action_button( self.print_members)) elems.append(ar.instance_action_button( self.print_members_html)) return E.p(*join_elems(elems, sep=", "))
def pupil_info(self, ar): txt = self.pupil.get_full_name(nominative=True) if ar is None: elems = [txt] else: elems = [ar.obj2html(self.pupil, txt)] elems += [', '] elems += join_elems( list(self.pupil.address_location_lines()), sep=', ') return E.p(*elems)
def move_buttons(obj, ar): if ar is None: return '' actor = ar.actor l = [] state = None # TODO: support a possible state? for n in obj.move_action_names: ba = actor.get_action_by_name(n) if ba.get_row_permission(ar, obj, state): l.append(ar.renderer.action_button(obj, ar, ba)) l.append(' ') return E.p(*l)
def get_overview_elems(self, ar): elems = super(Client, self).get_overview_elems(ar) # elems.append(E.br()) elems.append(ar.get_data_value(self, 'eid_info')) notes = [] for obj in rt.models.cal.Task.objects.filter( project=self, state=TaskStates.important): notes.append(E.b(ar.obj2html(obj, obj.summary))) if len(notes): notes = join_elems(notes, " / ") elems.append(E.p(*notes, **{'class': "lino-info-yellow"})) return elems
def get_overview_elems(self, ar): # elems = super(AddressOwner, self).get_overview_elems(ar) elems = [] # e.g. in amici a company inherits from AddressOwner but # is not a partner_model because there we want multiple # addresses only for persons, not for companies. if isinstance(self, dd.plugins.addresses.partner_model): sar = ar.spawn('addresses.AddressesByPartner', master_instance=self) # btn = sar.as_button(_("Manage addresses"), icon_name="wrench") btn = sar.as_button(_("Manage addresses")) # elems.append(E.p(btn, align="right")) elems.append(E.p(btn)) return elems
def get_calendar_summary(cls, obj, ar): # print("20181121 get_calendar_summary", cls) # note that objects can be either Event or Guest. if the view # is called for Guest, we waht to display the guest states # (not the event states). But when user clicks on a date they # want to show the event even when we are calling from Guest. if ar is None or obj is None: return '' state_coll = {} cal = CalendarRenderer(cls.model) # sar = ar.spawn(parent=ar, master_instance=obj) # sar = ar.actor.request(parent=ar, master_instance=obj) sar = cls.request_from(ar, master_instance=obj) # sar = cls.request(parent=ar, master_instance=obj) # print("20181121 {}".format(ar.actor)) # print("20181121 {}".format(cls.get_filter_kw(sar))) # print("20181121 {}".format(len(list(sar)))) for obj in sar: if obj.state in state_coll: state_coll[obj.state] += 1 else: state_coll[obj.state] = 1 cal.collect(obj) elems = [cal.to_html(ar)] # choicelist = EntryStates choicelist = cls.workflow_state_field.choicelist ul = [] for st in choicelist.get_list_items(): ul.append(_("{} : {}").format(st, state_coll.get(st, 0))) toolbar = [] toolbar += join_elems(ul, sep=', ') # elems = join_elems(ul, sep=E.br) if isinstance(obj, rt.models.cal.EventGenerator): ar1 = obj.do_update_events.request_from(sar) if ar1.get_permission(): btn = ar1.ar2button(obj) toolbar.append(btn) ar2 = cls.insert_action.request_from(sar) if ar2.get_permission(): btn = ar2.ar2button() toolbar.append(btn) if len(toolbar): toolbar = join_elems(toolbar, sep=' ') elems.append(E.p(*toolbar)) return ar.html_text(E.div(*elems))
def description(cls, self, ar): if ar is None: return '' elems = [] elems.append(ar.obj2html(self.account)) voucher = self.voucher.get_mti_leaf() if voucher is not None: if voucher.narration: elems.append(voucher.narration) p = voucher.get_partner() if p is not None: elems.append(ar.obj2html(p)) if self.partner and self.partner != p: elems.append(ar.obj2html(self.partner)) return E.p(*join_elems(elems, " / "))
def body_subject_to_elems(ar, title, description): """ Convert the given `title` and `description` to a list of HTML elements. Used by :mod:`lino.modlib.notify` and by :mod:`lino_xl.lib.sales` """ if description: elems = [E.p(E.b(title), E.br())] elems += rich_text_to_elems(ar, description) else: elems = [E.b(title)] # return E.span(self.title) return elems
def get_table_summary(self, obj, ar): """Implements :meth:`summary view <lino.core.actors.Actor.get_table_summary>`. """ sar = self.request_from(ar, master_instance=obj) # tags = [str(c.topic) for c in sar] tags = [six.text_type(c.topic) for c in sar] # tags = [c.obj2href(ar) for c in sar] # chunks = join_elems(tags, sep=', ') # iar = self.insert_action.request_from(sar) # if iar.get_permission(): # chunks.append(' ') # chunks.append(iar.ar2button()) # return ar.html_text(E.p(*chunks)) return ar.html_text(E.p(', '.join(tags)))
def get_overview_elems(self, ar): elems = [] buttons = self.get_mti_buttons(ar) # buttons = join_elems(buttons, ', ') elems.append(E.p(str(_("See as ")), *buttons, style="font-size:8px;text-align:right;padding:3pt;")) elems += self.get_name_elems(ar) elems.append(E.br()) elems += join_elems(list(self.address_location_lines()), sep=E.br) elems = [ E.div(*forcetext(elems), style="font-size:18px;font-weigth:bold;" "vertical-align:bottom;text-align:middle")] elems += AddressOwner.get_overview_elems(self, ar) elems += ContactDetailsOwner.get_overview_elems(self, ar) return elems
def get_language_knowledge(self, *buttons): self.load_language_knowledge() lst = [] for lng in settings.SITE.languages: cl = self._cef_levels.get(lng.django_code, "---") lst.append("{}: {}".format(lng.name, cl)) # if cl is None: # lst.append("{}: {}".format(lng.name, )) # else: # lst.append("{}: {}".format(lng.name, cl)) if len(self._mother_tongues): lst.append("{}: {}".format( _("Mother tongues"), self.mother_tongues)) lst += buttons lst = join_elems(lst, E.br) return E.p(*lst)
def get_table_summary(self, obj, ar): """Customized :meth:`summary view <lino.core.actors.Actor.get_table_summary>` for this table. """ sar = self.request_from(ar, master_instance=obj) html = [] items = [ ar.obj2html(o, str(o.end_user)) for o in sar] if len(items) > 0: html += join_elems(items, sep=', ') return E.p(*html)
def qs2summary(ar, objects, separator=comma, max_items=5, **kw): """Render a collection of objects as a single paragraph. :param max_items: don't include more than the specified number of items. """ elems = [] n = 0 for i in objects: if n: elems.append(separator()) n += 1 elems += list(ar.summary_row(i, **kw)) if n >= max_items: elems += [separator(), '...'] break return E.p(*elems)
def get_table_summary(self, obj, ar): """The :meth:`summary view <lino.core.actors.Actor.get_table_summary>` for this table. """ sar = self.request_from(ar, master_instance=obj) chunks = [] items = [o.obj2href(ar) for o in sar] if len(items) > 0: chunks += join_elems(items, ", ") sar = self.insert_action.request_from(sar) if sar.get_permission(): chunks.append(sar.ar2button()) return E.p(*chunks)
def description(cls, self, ar): if ar is None: return '' elems = [] elems.append(ar.obj2html(self.account)) if self.voucher.narration: elems.append(self.voucher.narration) voucher = self.voucher.get_mti_leaf() if voucher is not None: p = voucher.get_partner() if p is not None and p != ar.master_instance: elems.append(ar.obj2html(p)) elif self.partner: elems.append(ar.obj2html(self.partner)) if self.project: elems.append(ar.obj2html(self.project)) return E.p(*join_elems(elems, " / "))
def func(fld, obj, ar): # obj is the DailyPlannerRow instance pv = ar.param_values qs = Event.objects.filter(event_type__planner_column=pc) if pv.user: qs = qs.filter(user=pv.user) if pv.date: qs = qs.filter(start_date=pv.date) if obj.start_time: qs = qs.filter(start_time__gte=obj.start_time, start_time__isnull=False) if obj.end_time: qs = qs.filter(start_time__lt=obj.end_time, start_time__isnull=False) if not obj.start_time and not obj.end_time: qs = qs.filter(start_time__isnull=True) qs = qs.order_by('start_time') chunks = [e.obj2href(ar, fmt(e)) for e in qs] return E.p(*join_elems(chunks))
def show_menu(self, ar, mnu, level=1): """ Render the given menu as an HTML element. Used for writing test cases. """ if not isinstance(mnu, Menu): assert isinstance(mnu, MenuItem) if mnu.bound_action: sar = mnu.bound_action.actor.request( action=mnu.bound_action, user=ar.user, subst_user=ar.subst_user, requesting_panel=ar.requesting_panel, renderer=self, **mnu.params) # print("20170113", sar) url = sar.get_request_url() else: url = mnu.href assert mnu.label is not None if url is None: return E.p() # spacer return E.li(E.a(str(mnu.label), href=url, tabindex="-1")) items = [self.show_menu(ar, mi, level + 1) for mi in mnu.items] #~ print 20120901, items if level == 1: return E.ul(*items, **{'class':'nav navbar-nav'}) if mnu.label is None: raise Exception("%s has no label" % mnu) if level == 2: cl = 'dropdown' menu_title = E.a( str(mnu.label), E.b(' ', **{'class': "caret"}), href="#", data_toggle="dropdown", **{'class':'dropdown-toggle'}) elif level == 3: menu_title = E.a(str(mnu.label), href="#") cl = 'dropdown-submenu' else: raise Exception("Menu with more than three levels") return E.li( menu_title, E.ul(*items, **{'class':'dropdown-menu'}), **{'class':cl})