示例#1
0
    def update(self, fields=None, caption=None, highlighters=None, **kwargs):
        """ This method is used to change HTMLTable initial data, thus, changing representation
            Can be used for example, when some function returns partly configured HTMLTable instance,
            but user want's to display more fields for example, or add some custom highlighters

            arguments same as for constructor, except 'recordlist' arg, which is absent in this method

            :return: self
        """
        self._caption = _(self._recordlist) if caption is None else _(caption)
        fields = [] if fields is None else fields
        for field in fields:
            if isinstance(field, HField):
                self._fields.append(field)
            elif isinstance(field, six.string_types):
                self._fields.append(HField(field))
            elif callable(field):
                self._fields.append(HField(field))
            elif isinstance(field, (tuple, list)) and len(field) == 2:
                self._fields.append(HField(field[0], name=field[1]))
            else:
                raise ValueError('Unsupported field type: %s' % repr(field))

        if highlighters is not None:
            self._highlighters.update(highlighters)

        return self
示例#2
0
    def _repr_html_(self):
        """ Builds HTML representation for IPython
        """
        model = self.model
        help_text = (u"To get information about columns access property<br/>"
                     u"&nbsp;<i>.columns_info</i><br/>"
                     u"Also there are available standard server-side methods:<br/>"
                     u"&nbsp;<i>search</i>, <i>read</i>, <i>write</i>, <i>unlink</i></br>"
                     u"And special methods provided <i>openerp_proxy's orm</i>:"
                     u"<ul style='margin-top:1px'>"
                     u"<li><i>search_records</i> - same as <i>search</i> but returns <i>RecordList</i> instance</li>"
                     u"<li><i>read_records</i> - same as <i>read</i> but returns <i>Record</i> or <i>RecordList</i> instance</li>"
                     u"<ul><br/>")

        data = u"".join((
            tr(th("Name"), td(model.name)),
            tr(th("Proxy"), td(self.proxy.get_url())),
            tr(th("Model"), td(model.model)),
            tr(th("Record count"), td(self.search([], count=True))),
        ))

        table = TMPL_TABLE % {'styles': '',
                              'caption': u"Object '%s'" % _(model.name),
                              'rows': data}

        return TMPL_INFO_WITH_HELP % {'info': table, 'help': help_text}
示例#3
0
    def as_html(self, *fields):
        """ Returns HTML representation of this Record.
            By default show all record fields.
            all passed positional arguments are treated as field names to be displayed.
            Also posible to pass dotted related fields like ('move_dest_id.location_dest_id')
            Type of all positional arguments should be string or HField instances

           :param list fields: list of field names to display in HTML representation
           :return: ipython's HTML object representing this record
           :rtype: HTML
        """
        table_tmpl = u"<table><caption>Record %s</caption><tr><th>Column</th><th>Value</th></tr>%s</table>"
        row_tmpl = u"<tr><th>%s</th><td>%s</td></tr>"

        if not fields:
            fields = sorted((HField(col_name, name=col_data['string'])
                             for col_name, col_data in self._columns_info.items()
                             if col_name in self._object.simple_fields),
                            key=lambda x: _(x))
            self.read()
        else:
            # TODO: implement in better way this prefetching
            read_fields = (f.split('.')[0] for f in fields if isinstance(f, six.string_types) and f.split('.')[0] in self._columns_info)
            prefetch_fields = [f for f in read_fields if f not in self._data]
            self.read(prefetch_fields)

        parsed_fields = []
        for field in fields:
            if isinstance(field, HField):
                parsed_fields.append(field)
            elif isinstance(field, six.string_types):
                parsed_fields.append(HField(field))
            else:
                raise TypeError("Bad type of field %s" % repr(field))

        body = ""
        for field in parsed_fields:
            row = row_tmpl % (_(field), field(self))
            body += row

        return HTML(table_tmpl % (self._name, body))
示例#4
0
    def as_html_table(self, fields=None):
        """ Generates HTMLTable representation for this columns info

            :param fields: list of fields to display instead of defaults
            :return: generated HTMLTable instanse
            :rtype: HTMLTable
        """
        fields = self.default_fields if fields is None else fields
        info_struct = [{'name': key,
                        'info': val} for key, val in self.items()]
        info_struct.sort(key=lambda x: x['name'])
        return HTMLTable(info_struct, fields, caption=u'Fields for %s' % _(self._object.name))
示例#5
0
    def _repr_html_(self):
        help_text = (u"This is report representation.<br/>"
                     u"call <i>generate<i> method to generate new report<br/>"
                     u"&nbsp;<i>.generate([1, 2, 3])</i><br/>"
                     u"Also <i>generate</i> method can receive <br/>"
                     u"RecordList or Record instance as first argument.<br/>"
                     u"For more information look in "
                     u"<a href='http://pythonhosted.org/openerp_proxy/module_ref/openerp_proxy.service.html#module-openerp_proxy.service.report'>documentation</a>")

        data = u"".join((
            tr(th("Name"), td(self.report_action.name)),
            tr(th("Service name"), td(self.name)),
            tr(th("Model"), td(self.report_action.model)),
        ))

        table = TMPL_TABLE % {'styles': '',
                              'caption': u'Report %s' % _(self.report_action.name),
                              'rows': data}
        return TMPL_INFO_WITH_HELP % {'info': table, 'help': help_text}
示例#6
0
    def _repr_html_(self):
        """ Builds HTML representation for IPython
        """
        trow = u"<tr>%s</tr>"
        tdata = u"<td>%s</td>"
        thead = u"<th>%s</th>"
        help_text = (u"To get HTML Table representation of this record call method:<br/>"
                     u"&nbsp;<i>.as_html()</i><br/>"
                     u"Optionaly You can pass list of fields You want to see:<br/>"
                     u"&nbsp;<i>.as_html('name', 'origin')</i><br/>"
                     u"for better information get doc on <i>as_html</i> method:<br/>"
                     u"&nbsp;<i>.as_html?</i><br/>")

        data = u"".join((
            tr(th("Object"), td(self._object)),
            tr(th("Proxy"), td(self._proxy.get_url())),
            tr(th("Name"), td(self._name)),
        ))

        table = TMPL_TABLE % {'styles': '',
                              'caption': _(self),
                              'rows': data}

        return TMPL_INFO_WITH_HELP % {'info': table, 'help': help_text}
示例#7
0
    def _repr_html_(self):
        """ Builds HTML representation for IPython
        """
        help_text = (u"To get table representation of data call method<br/>"
                     u"&nbsp;<i>.as_html_table</i><br/>"
                     u"passing as arguments fields You want to see in resulting table<br/>"
                     u"for better information get doc on as_html_table method:<br/>"
                     u"&nbsp;<i>.as_html_table?</i><br/>"
                     u"example of using this mehtod:<br/>"
                     u"&nbsp;<i>.as_html_table('id','name','_name')</i><br/>"
                     u"Here <i>_name</i> field is aliase for result of <i>name_get</i> method"
                     u"called on record")

        data = u"".join((
            tr(th("Object"), td(self.object)),
            tr(th("Proxy"), td(self.object.proxy.get_url())),
            tr(th("Record count"), td(len(self))),
        ))

        table = TMPL_TABLE % {'styles': '',
                              'caption': _(self),
                              'rows': data}

        return TMPL_INFO_WITH_HELP % {'info': table, 'help': help_text}
示例#8
0
 def message(self):
     return u"Field %s not found in obj %s" % (_(self.field), _(self.obj))
示例#9
0
 def _get_data():
     for url in self._databases.keys():
         index = self._index_url(url)
         aliases = (_(al) for al, aurl in self.aliases.items() if aurl == url)
         yield (url, index, u", ".join(aliases))
示例#10
0
def td(val):
    return TMPL_TABLE_DATA % _(val)
示例#11
0
def th(val):
    return TMPL_TABLE_HEADER % _(val)
示例#12
0
 def _get_selection(x):
     return u'<br/>\n'.join((u"%s - %s" % (_(repr(i[0])), _(i[1]))
                             for i in x['info'].get('selection', []) or []))
示例#13
0
 def preprocess_field(field):
     """ Process some special cases of field to be correctly displayed
     """
     if isinstance(field, HTML):
         return field._repr_html_()
     return _(field)
示例#14
0
 def iheaders(self):
     """ Iterator in headers
         :type: list of unicode strings
     """
     return (_(field) for field in self.fields)
示例#15
0
 def __unicode__(self):
     return _(self._name) if self._name is not None else _(self._field)