Ejemplo n.º 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, header_links=False)

            #~ print ar.get_total_count()
            return tostring(t.as_element())
Ejemplo n.º 2
0
 def table2xhtml(self, **kwargs):
     """
     Return an HTML representation of this table request.
     """
     t = xghtml.Table()
     self.dump2html(t, self.sliced_data_iterator, **kwargs)
     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
Ejemplo n.º 3
0
    def get_table_summary(self, response, ar):
        if response is None:
            return
        if response.poll_id is None:
            return
        AnswerRemarks = rt.models.polls.AnswerRemarksByAnswer
        all_responses = rt.models.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 = [str(_("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()
        # editable = insert.get_permission(response)
        kv = dict(response=response)
        insert = AnswerRemarks.insert_action.request_from(ar, known_values=kv)
        detail = AnswerRemarks.detail_action.request_from(ar)
        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())
Ejemplo n.º 4
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:`etgen.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.set('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())