コード例 #1
0
    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)
コード例 #2
0
ファイル: dashboard.py プロジェクト: zyrobin/lino
    def render_request(self, ar, sar):
        """
        Render the given table action
        request. `ar` is the incoming request (the one which displays
        the dashboard), `sar` is the table we want to show (a child of
        `ar`).

        This is a helper function for shared use by :class:`ActorItem`
        and :class:`RequestItem`.
        """
        T = sar.actor
        if not sar.get_total_count():
            # print("20180212 render no rows in ", sar)
            return ''
        if self.header_level is None:
            s = ''
        else:
            s = tostring(E.h2(
                str(sar.actor.get_title_base(sar)),
                ' ', ar.window_action_button(
                    T.default_action,
                    # label="🗗",
                    # label="☌",  # conjunction
                    # label="◱", # 25F1
                    # label="◳", # 25F3
                    # label="⏍", # 23CD
                    label="⏏", # 23CF
                    # label="⍐", # 2350
                    # style="text-decoration:none; font-size:80%;",
                    style="text-decoration:none;",
                    title=_("Show this table in own window"))))

        s += tostring(ar.show(sar))
        return s
コード例 #3
0
ファイル: ui.py プロジェクト: lino-framework/xl
 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)
コード例 #4
0
ファイル: dashboard.py プロジェクト: gary-ops/lino
    def render_request(self, ar, sar):
        """
        Render the given table action
        request. `ar` is the incoming request (the one which displays
        the dashboard), `sar` is the table we want to show (a child of
        `ar`).

        This is a helper function for shared use by :class:`ActorItem`
        and :class:`RequestItem`.
        """
        T = sar.actor
        if self.min_count is not None:
            if sar.get_total_count() < self.min_count:
                # print("20180212 render no rows in ", sar)
                return
        if self.header_level is not None:
            buttons = sar.plain_toolbar_buttons()
            buttons.append(sar.open_in_own_window_button())
            elems = []
            for b in buttons:
                elems.append(b)
                elems.append(' ')

            yield E.h2(str(
                sar.actor.get_title_base(sar)), ' ', *elems)

        yield sar
コード例 #5
0
ファイル: dashboard.py プロジェクト: lino-framework/lino
    def render_request(self, ar, sar):
        """
        Render the given table action
        request. `ar` is the incoming request (the one which displays
        the dashboard), `sar` is the table we want to show (a child of
        `ar`).

        This is a helper function for shared use by :class:`ActorItem`
        and :class:`RequestItem`.
        """
        T = sar.actor
        if self.min_count is not None:
            if sar.get_total_count() < self.min_count:
                # print("20180212 render no rows in ", sar)
                return
        if self.header_level is not None:
            buttons = sar.plain_toolbar_buttons()
            buttons.append(
                ar.window_action_button(
                    T.default_action,
                    label="⏏", # 23CF
                    style="text-decoration:none;",
                    title=_("Show this table in own window")))
            
            elems = []
            for b in buttons:
                elems.append(b)
                elems.append(' ')
            
            yield E.h2(str(
                sar.actor.get_title_base(sar)), ' ', *elems)

        yield sar
コード例 #6
0
 def table2xhtml(self, header_level=None, **kw):
     """
     Return an HTML representation of this table request.
     """
     t = xghtml.Table()
     self.dump2html(t, self.sliced_data_iterator, **kw)
     e = t.as_element()
     # print "20150822 table2xhtml", tostring(e)
     if header_level is not None:
         return E.div(E.h2(str(self.actor.label)), e)
     return e
コード例 #7
0
ファイル: report.py プロジェクト: zyrobin/lino
 def get_story(cls, self, ar):
     """
     Yield a sequence of story items. Every item can be (1) an
     ElementTree element or (2) a table or (3) an action request.
     """
     # cls.check_params(cls.param_values)
     if cls.report_items is None:
         raise Exception("{0} has no report_items".format(cls))
     for A in cls.report_items:
         yield E.h2(str(A.label))
         # if A.help_text:
         #     yield E.p(str(A.help_text))
         yield A
コード例 #8
0
ファイル: ui.py プロジェクト: lino-framework/xl
 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
コード例 #9
0
ファイル: report.py プロジェクト: lino-framework/lino
 def get_story(cls, self, ar):
     """
     Yield a sequence of story items. Every item can be (1) an
     ElementTree element or (2) a table or (3) an action request.
     """
     # cls.check_params(cls.param_values)
     if cls.report_items is None:
         raise Exception("{0} has no report_items".format(cls))
     for A in cls.report_items:
         yield E.h2(str(A.label))
         # if A.help_text:
         #     yield E.p(str(A.help_text))
         yield A
コード例 #10
0
ファイル: ui.py プロジェクト: forexblog/xl
    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")
コード例 #11
0
ファイル: ui.py プロジェクト: einarfelix/xl
    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")