Description

It would be nice if the tables generated with DataBrowserWidget were styleable, i.e. identified with a CSS class through which themes can differentiate them from regular tables generated with wiki syntax. MoinMoin uses the data browser component for generating some ui elements, for example the attachments and user administration in SystemAdmin, the page package installation in LanguageSetup, the macro-generated smiley table in HelpOnSmileys, etc. Sometimes it's nice to give these ui elements different styles from regular tables, for example remove the border.

Component selection

I think all clients of the DataBrowserWidget could be obligated to define a CSS class for allowing special style for their tables. Maybe they could pass a css_class param in the constructor. Here are the MoinMoin components to be changed:

Component

Suggested class

UI element

action.AttachFile

attachment_admin

SystemAdmin

action.Despam

despam

Despam action

action.info

page_history

Page history

action.language_setup

language_setup

LanguageSetup

macro.ShowSmileys

smileys

HelpOnSmileys

parser.text_csv

csv

{{{#!csv, see HelpOnParsers

stats.hitcounts

hitcounts

EventStats/HitCounts

stats.languages

languages

EventStats/Languages

stats.useragents

useragents

EventStats/UserAgents

userform.admin

user_admin

SystemAdmin

Discussion

Patch 1

Please have a look if that is what you have expected. -- ReimarBauer 2010-03-22 13:47:39

   1 diff -r 7e18782d09b2 MoinMoin/action/AttachFile.py
   2 --- a/MoinMoin/action/AttachFile.py	Fri Mar 19 20:23:50 2010 +0100
   3 +++ b/MoinMoin/action/AttachFile.py	Mon Mar 22 00:40:39 2010 +0100
   4 @@ -1163,10 +1163,12 @@
   5  
   6      if data:
   7          from MoinMoin.widget.browser import DataBrowserWidget
   8 -
   9 +        div = ['<div id="attachment-admin">']
  10          browser = DataBrowserWidget(request)
  11          browser.setData(data, sort_columns=[0, 1])
  12 -        return browser.render(method="GET")
  13 +        div.append(browser.render(method="GET"))
  14 +        div.append('</div>')
  15 +        return '\n'.join(div)
  16  
  17      return ''
  18  
  19 diff -r 7e18782d09b2 MoinMoin/action/Despam.py
  20 --- a/MoinMoin/action/Despam.py	Fri Mar 19 20:23:50 2010 +0100
  21 +++ b/MoinMoin/action/Despam.py	Mon Mar 22 00:40:39 2010 +0100
  22 @@ -89,7 +89,7 @@
  23      macro = tmp()
  24      macro.request = request
  25      macro.formatter = request.html_formatter
  26 -
  27 +    request.write('<div id="despam">')
  28      request.write("<table>")
  29      for line in log.reverse():
  30          if line.ed_time_usecs < timestamp:
  31 @@ -106,6 +106,7 @@
  32  
  33      request.write('''
  34  </table>
  35 +</div>
  36  <p>
  37  <form method="post" action="%(url)s">
  38  <input type="hidden" name="action" value="Despam">
  39 diff -r 7e18782d09b2 MoinMoin/action/language_setup.py
  40 --- a/MoinMoin/action/language_setup.py	Fri Mar 19 20:23:50 2010 +0100
  41 +++ b/MoinMoin/action/language_setup.py	Mon Mar 22 00:40:39 2010 +0100
  42 @@ -74,7 +74,9 @@
  43  
  44      table = DataBrowserWidget(request)
  45      table.setData(data)
  46 -    page_table = ''.join(table.format(method='GET'))
  47 +    div = ['<div id="language-setup">']
  48 +    div.append(table.format(method='GET'))
  49 +    div.append('</div>')
  50  
  51      fmt = request.formatter
  52      lang_links = [request.page.link_to_raw(request, _lang,
  53 @@ -90,7 +92,7 @@
  54      request.theme.send_title(title, page=request.page, pagename=pagename)
  55      request.write(request.formatter.startContent("content"))
  56      request.write(lang_selector)
  57 -    request.write(page_table)
  58 +    request.write(''.join(div))
  59      request.write(request.formatter.endContent())
  60      request.theme.send_footer(pagename)
  61      request.theme.send_closing_html()
  62 diff -r 7e18782d09b2 MoinMoin/macro/ShowSmileys.py
  63 --- a/MoinMoin/macro/ShowSmileys.py	Fri Mar 19 20:23:50 2010 +0100
  64 +++ b/MoinMoin/macro/ShowSmileys.py	Mon Mar 22 00:40:39 2010 +0100
  65 @@ -49,7 +49,10 @@
  66      if data:
  67          browser = DataBrowserWidget(macro.request)
  68          browser.setData(data)
  69 -        return browser.render(method="GET")
  70 +        div = ['<div id="smileys">']
  71 +        div.append(browser.render(method="GET"))
  72 +        div.append('</div>')
  73 +        return '\n'.join(div)
  74  
  75      return ''
  76  
  77 diff -r 7e18782d09b2 MoinMoin/parser/text_csv.py
  78 --- a/MoinMoin/parser/text_csv.py	Fri Mar 19 20:23:50 2010 +0100
  79 +++ b/MoinMoin/parser/text_csv.py	Mon Mar 22 00:40:39 2010 +0100
  80 @@ -185,4 +185,7 @@
  81      def format(self, formatter):
  82          browser = DataBrowserWidget(self.request, show_header=self._show_header)
  83          browser.setData(self.data)
  84 -        self.request.write(browser.render(method="GET"))
  85 +        div = ['<div id="csv">']
  86 +        div.append(browser.render(method="GET"))
  87 +        div.append('</div>')
  88 +        self.request.write('\n'.join(div))
  89 diff -r 7e18782d09b2 MoinMoin/stats/hitcounts.py
  90 --- a/MoinMoin/stats/hitcounts.py	Fri Mar 19 20:23:50 2010 +0100
  91 +++ b/MoinMoin/stats/hitcounts.py	Mon Mar 22 00:40:39 2010 +0100
  92 @@ -187,7 +187,10 @@
  93  
  94      table = DataBrowserWidget(request)
  95      table.setData(hits)
  96 -    return table.render(method="GET")
  97 +    div = ['<div id="hitcounts">']
  98 +    div.append(table.render(method="GET"))
  99 +    div.append('</div>')
 100 +    return '\n'.join(div)
 101  
 102  
 103  def draw(pagename, request):
 104 diff -r 7e18782d09b2 MoinMoin/stats/languages.py
 105 --- a/MoinMoin/stats/languages.py	Fri Mar 19 20:23:50 2010 +0100
 106 +++ b/MoinMoin/stats/languages.py	Mon Mar 22 00:40:39 2010 +0100
 107 @@ -87,5 +87,8 @@
 108  
 109      table = DataBrowserWidget(request)
 110      table.setData(languages)
 111 -    return table.render(method="GET")
 112 +    div = ['<div id="languages">']
 113 +    div.append(table.render(method="GET"))
 114 +    div.append('</div>')
 115 +    return '\n'.join(div)
 116  
 117 diff -r 7e18782d09b2 MoinMoin/stats/useragents.py
 118 --- a/MoinMoin/stats/useragents.py	Fri Mar 19 20:23:50 2010 +0100
 119 +++ b/MoinMoin/stats/useragents.py	Mon Mar 22 00:40:39 2010 +0100
 120 @@ -116,7 +116,10 @@
 121  
 122      table = DataBrowserWidget(request)
 123      table.setData(agents)
 124 -    return table.render(method="GET")
 125 +    div = ['<div id="useragents">']
 126 +    div.append(table.render(method="GET"))
 127 +    div.append('</div>')
 128 +    return '\n'.join(div)
 129  
 130  def draw(pagename, request):
 131      import shutil, cStringIO
 132 diff -r 7e18782d09b2 MoinMoin/userform/admin.py
 133 --- a/MoinMoin/userform/admin.py	Fri Mar 19 20:23:50 2010 +0100
 134 +++ b/MoinMoin/userform/admin.py	Mon Mar 22 00:40:39 2010 +0100
 135 @@ -106,8 +106,10 @@
 136  
 137          browser = DataBrowserWidget(request)
 138          browser.setData(data, sort_columns=[0])
 139 -        return browser.render()
 140 -
 141 +        div = ['<div id="admin">']
 142 +        div.append(browser.render())
 143 +        div.append('</div>')
 144 +        return '\n'.join(div)
 145      # No data
 146      return ''
 147  
StyleableDataBrowserTables.patch

Patch 2

I think an easier way is to pass some css class to be aplied directly in the table element, rather than wrapping it with some identified div every time. Even though I think we should enforce the css_class param, the patch below does not break Moin "API". -- RenatoSilva

   1 --- MoinMoin/widget/browser.py  2010-02-28 15:28:47 +0000
   2 +++ MoinMoin/widget/browser.py  2010-04-10 18:36:29 +0000
   3 @@ -11,7 +11,7 @@
   4 
   5  class DataBrowserWidget(base.Widget):
   6 
   7 -    def __init__(self, request, show_header=True, **kw):
   8 +    def __init__(self, request, show_header=True, css_class="", **kw):
   9          _ = request.getText
  10          base.Widget.__init__(self, request, **kw)
  11          self.data = None
  12 @@ -27,6 +27,7 @@
  13          self._filter = _('filter')
  14          self.__filter = 'filter'
  15          self._show_header = show_header
  16 +        self.css_class = "dbw-table %s" % css_class
  17 
  18      def setData(self, dataset):
  19          """ Sets the data for the browser (see MoinMoin.util.dataset).
  20 @@ -120,7 +121,7 @@
  21          if havefilters:
  22              result.append(fmt.rawHTML('<input type="submit" value="%s" %s>' % (self._filter, self._name('submit'))))
  23 
  24 -        result.append(fmt.table(1, id='%stable' % self.unqual_data_id))
  25 +        result.append(fmt.table(1, id='%stable' % self.unqual_data_id, css_class=self.css_class))
  26 
  27          # add header line
  28          if self._show_header:
  29 --- MoinMoin/action/AttachFile.py       2010-02-28 15:28:45 +0000
  30 +++ MoinMoin/action/AttachFile.py       2010-04-10 18:50:25 +0000
  31 @@ -1163,7 +1163,7 @@
  32      if data:
  33          from MoinMoin.widget.browser import DataBrowserWidget
  34 
  35 -        browser = DataBrowserWidget(request)
  36 +        browser = DataBrowserWidget(request, css_class="attachment-admin")
  37          browser.setData(data)
  38          return browser.render(method="GET")
  39 
  40 --- MoinMoin/action/Despam.py   2010-02-28 15:28:45 +0000
  41 +++ MoinMoin/action/Despam.py   2010-04-10 18:55:31 +0000
  42 @@ -72,7 +72,7 @@
  43                      'editor': repr(editor),
  44                  })))
  45 
  46 -    table = DataBrowserWidget(request)
  47 +    table = DataBrowserWidget(request, css_class="despam")
  48      table.setData(dataset)
  49      return table.render(method="GET")
  50 
  51 --- MoinMoin/action/info.py     2010-02-28 15:28:45 +0000
  52 +++ MoinMoin/action/info.py     2010-04-10 19:33:33 +0000
  53 @@ -316,7 +316,7 @@
  54              request.write(_('No log entries found.'))
  55              return
  56 
  57 -        history_table = DataBrowserWidget(request)
  58 +        history_table = DataBrowserWidget(request, css_class="page-history")
  59          history_table.setData(history)
  60 
  61          div = html.DIV(id="page-history")
  62 --- MoinMoin/action/language_setup.py   2010-02-28 15:28:45 +0000
  63 +++ MoinMoin/action/language_setup.py   2010-04-10 18:57:09 +0000
  64 @@ -72,7 +72,7 @@
  65              install_link = request.page.link_to(request, label_install, querystr=querystr)
  66          data.addRow((pageset_name, install_link))
  67 
  68 -    table = DataBrowserWidget(request)
  69 +    table = DataBrowserWidget(request, css_class="language-setup")
  70      table.setData(data)
  71      page_table = ''.join(table.format(method='GET'))
  72 
  73 --- MoinMoin/macro/ShowSmileys.py       2010-02-28 15:28:46 +0000
  74 +++ MoinMoin/macro/ShowSmileys.py       2010-04-10 19:00:02 +0000
  75 @@ -47,7 +47,7 @@
  76 
  77      # display table
  78      if data:
  79 -        browser = DataBrowserWidget(macro.request)
  80 +        browser = DataBrowserWidget(macro.request, css_class="smileys")
  81          browser.setData(data)
  82          return browser.render(method="GET")
  83 
  84 --- MoinMoin/parser/text_csv.py 2010-02-28 15:28:46 +0000
  85 +++ MoinMoin/parser/text_csv.py 2010-04-10 19:01:34 +0000
  86 @@ -183,6 +183,6 @@
  87          self.data = data
  88 
  89      def format(self, formatter):
  90 -        browser = DataBrowserWidget(self.request, show_header=self._show_header)
  91 +        browser = DataBrowserWidget(self.request, show_header=self._show_header, css_class="csv")
  92          browser.setData(self.data)
  93          self.request.write(browser.render(method="GET"))
  94 --- MoinMoin/stats/hitcounts.py 2010-02-28 15:28:46 +0000
  95 +++ MoinMoin/stats/hitcounts.py 2010-04-10 19:03:46 +0000
  96 @@ -185,7 +185,7 @@
  97              se = 0.0
  98              sd = 0.0
  99 
 100 -    table = DataBrowserWidget(request)
 101 +    table = DataBrowserWidget(request, css_class="hitcounts")
 102      table.setData(hits)
 103      return table.render(method="GET")
 104 
 105 --- MoinMoin/stats/languages.py 2010-02-28 15:28:46 +0000
 106 +++ MoinMoin/stats/languages.py 2010-04-10 19:03:54 +0000
 107 @@ -85,7 +85,7 @@
 108      else: # If we don't have any users, we can safely assume that the only real user is the visitor (who is normally ignored, though) who is using "Browser setting"
 109          languages.addRow((browserlang, "100% (1)"))
 110 
 111 -    table = DataBrowserWidget(request)
 112 +    table = DataBrowserWidget(request, css_class="languages")
 113      table.setData(languages)
 114      return table.render(method="GET")
 115 
 116 --- MoinMoin/stats/useragents.py        2010-02-28 15:28:46 +0000
 117 +++ MoinMoin/stats/useragents.py        2010-04-10 19:04:05 +0000
 118 @@ -114,7 +114,7 @@
 119          if total > cnt_printed:
 120              agents.addRow((_('Others'), "%.2f" % (100 * (total - cnt_printed) / total)))
 121 
 122 -    table = DataBrowserWidget(request)
 123 +    table = DataBrowserWidget(request, css_class="useragents")
 124      table.setData(agents)
 125      return table.render(method="GET")
 126 
 127 --- MoinMoin/userform/admin.py  2010-02-28 15:28:46 +0000
 128 +++ MoinMoin/userform/admin.py  2010-04-10 19:06:59 +0000
 129 @@ -104,7 +104,7 @@
 130      if data:
 131          from MoinMoin.widget.browser import DataBrowserWidget
 132 
 133 -        browser = DataBrowserWidget(request)
 134 +        browser = DataBrowserWidget(request, css_class="user-admin")
 135          browser.setData(data)
 136          return browser.render()

Plan


CategoryMoinMoinBug

MoinMoin: MoinMoinBugs/StyleableDataBrowserTables (last edited 2020-12-26 11:50:34 by RenatoSilva)