Пример #1
0
        def as_table2(ar):
            # 20150810
            # ar.renderer = settings.SITE.plugins.bootstrap3.renderer
            ar.renderer = self

            t = xghtml.Table()
            ar.dump2html(t, ar.sliced_data_iterator)

            #~ print ar.get_total_count()
            return E.tostring(t.as_element())
Пример #2
0
def table2html(ar, as_main=True):
    """This is not a docstring."""
    as_main = True
    t = xghtml.Table()
    t.attrib.update(class_="table table-striped table-hover")
    if ar.limit is None:
        ar.limit = PLAIN_PAGE_LENGTH
    pglen = ar.limit
    if ar.offset is None:
        page = 1
    else:
        """
        (assuming pglen is 5)
        offset page
        0      1
        5      2
        """
        page = int(ar.offset / pglen) + 1

    ar.dump2html(t, ar.sliced_data_iterator)
    if not as_main:
        url = ar.get_request_url()  # open in own window
        return E.div(E.a(ar.get_title(), href=url), t.as_element())

    buttons = []
    kw = dict()
    kw = {}
    if pglen != PLAIN_PAGE_LENGTH:
        kw[constants.URL_PARAM_LIMIT] = pglen

    if page > 1:
        kw[constants.URL_PARAM_START] = pglen * (page - 2)
        prev_url = ar.get_request_url(**kw)
        kw[constants.URL_PARAM_START] = 0
        first_url = ar.get_request_url(**kw)
    else:
        prev_url = None
        first_url = None
    buttons.append(('<<', _("First page"), first_url))
    buttons.append(('<', _("Previous page"), prev_url))

    next_start = pglen * page
    if next_start < ar.get_total_count():
        kw[constants.URL_PARAM_START] = next_start
        next_url = ar.get_request_url(**kw)
        last_page = int((ar.get_total_count() - 1) / pglen)
        kw[constants.URL_PARAM_START] = pglen * last_page
        last_url = ar.get_request_url(**kw)
    else:
        next_url = None
        last_url = None
    buttons.append(('>', _("Next page"), next_url))
    buttons.append(('>>', _("Last page"), last_url))

    return E.div(buttons2pager(buttons), t.as_element())
Пример #3
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", E.tostring(e)
     if header_level is not None:
         return E.div(E.h2(self.actor.label), e)
     return e
Пример #4
0
        def as_table(action_spec):
            a = settings.SITE.modules.resolve(action_spec)
            ar = a.request(user=AnonymousUser.instance())
            # 20150810
            # ar.renderer = settings.SITE.plugins.bootstrap3.renderer
            ar.renderer = self

            t = xghtml.Table()
            ar.dump2html(t, ar.sliced_data_iterator)

            #~ print ar.get_total_count()
            return E.tostring(t.as_element())
Пример #5
0
    def as_html_table(self, ar):
        t = xghtml.Table()
        ar.dump2html(t, ar.data_iterator)

        return xghtml.E.tostring(t.as_element())
Пример #6
0
    def get_slave_summary(self, response, ar):
        """Presents this response as a table with one row per question and one
        column for each response of the same poll.  The answers for
        this response are editable if this response is not registered.
        The answers of other responses are never editable.

        """
        if response is None:
            return
        if response.poll_id is None:
            return
        AnswerRemarks = rt.modules.polls.AnswerRemarksByAnswer
        all_responses = rt.modules.polls.Response.objects.filter(
            poll=response.poll).order_by('date')
        if response.partner:
            all_responses = all_responses.filter(partner=response.partner)
        ht = xghtml.Table()
        ht.attrib.update(cellspacing="5px", bgcolor="#ffffff", width="100%")
        cellattrs = dict(align="left", valign="top", bgcolor="#eeeeee")
        headers = [_("Question")]
        for r in all_responses:
            if r == response:
                headers.append(dd.fds(r.date))
            else:
                headers.append(ar.obj2html(r, dd.fds(r.date)))
        ht.add_header_row(*headers, **cellattrs)
        ar.master_instance = response  # must set it because
        # get_data_rows() needs it.
        # 20151211
        # editable = Responses.update_action.request_from(ar).get_permission(
        #     response)
        sar = Responses.update_action.request_from(ar)
        sar.selected_rows = [response]
        editable = sar.get_permission()

        kv = dict(response=response)
        insert = AnswerRemarks.insert_action.request_from(ar, known_values=kv)
        detail = AnswerRemarks.detail_action.request_from(ar)
        # editable = insert.get_permission(response)
        for answer in self.get_data_rows(ar):
            cells = [self.question.value_from_object(answer, ar)]
            for r in all_responses:
                if editable and r == response:
                    insert.known_values.update(question=answer.question)
                    detail.known_values.update(question=answer.question)
                    items = [self.answer_buttons.value_from_object(answer, ar)]
                    if answer.remark.remark:
                        items += [E.br(), answer.remark.remark]
                    if answer.remark.pk:
                        items += [
                            ' ',
                            detail.ar2button(answer.remark,
                                             _("Remark"),
                                             icon_name=None)
                        ]
                        # ar.obj2html(answer.remark, _("Remark"))]
                    else:
                        btn = insert.ar2button(answer.remark,
                                               _("Remark"),
                                               icon_name=None)
                        # sar = RemarksByAnswer.request_from(ar, answer)
                        # btn = sar.insert_button(_("Remark"), icon_name=None)
                        items += [" (", btn, ")"]

                else:
                    other_answer = AnswersByResponseRow(r, answer.question)
                    items = [str(other_answer)]
                    if other_answer.remark.remark:
                        items += [E.br(), answer.remark.remark]
                cells.append(E.p(*items))
            ht.add_body_row(*cells, **cellattrs)

        return ar.html_text(ht.as_element())
Пример #7
0
def table2html(ar, as_main=True):
    """Represent the given table request as an HTML table.

    `ar` is the request to be rendered, an instance of
    :class:`lino.core.tablerequest.TableRequest`.

    The returned HTML enclosed in a ``<div>`` tag and generated using
    :mod:`lino.utils.xmlgen.html`.

    If `as_main` is True, include additional elements such as a paging
    toolbar. (This argument is currently being ignored.)

    """
    as_main = True
    t = xghtml.Table()
    t.attrib.update(class_="table table-striped table-hover")
    if ar.limit is None:
        ar.limit = PLAIN_PAGE_LENGTH
    pglen = ar.limit
    if ar.offset is None:
        page = 1
    else:
        """
        (assuming pglen is 5)
        offset page
        0      1
        5      2
        """
        page = int(old_div(ar.offset, pglen)) + 1

    ar.dump2html(t, ar.sliced_data_iterator)
    if not as_main:
        url = ar.get_request_url()  # open in own window
        return E.div(E.a(ar.get_title(), href=url), t.as_element())

    buttons = []
    kw = dict()
    kw = {}
    if pglen != PLAIN_PAGE_LENGTH:
        kw[constants.URL_PARAM_LIMIT] = pglen

    if page > 1:
        kw[constants.URL_PARAM_START] = pglen * (page - 2)
        prev_url = ar.get_request_url(**kw)
        kw[constants.URL_PARAM_START] = 0
        first_url = ar.get_request_url(**kw)
    else:
        prev_url = None
        first_url = None
    buttons.append(('<<', _("First page"), first_url))
    buttons.append(('<', _("Previous page"), prev_url))

    next_start = pglen * page
    if next_start < ar.get_total_count():
        kw[constants.URL_PARAM_START] = next_start
        next_url = ar.get_request_url(**kw)
        last_page = int(old_div((ar.get_total_count() - 1), pglen))
        kw[constants.URL_PARAM_START] = pglen * last_page
        last_url = ar.get_request_url(**kw)
    else:
        next_url = None
        last_url = None
    buttons.append(('>', _("Next page"), next_url))
    buttons.append(('>>', _("Last page"), last_url))

    return E.div(buttons2pager(buttons), t.as_element())