Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
MoinMoin.widget.browser.DataBrowserWidget Class Reference
Inheritance diagram for MoinMoin.widget.browser.DataBrowserWidget:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.widget.browser.DataBrowserWidget:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def setData
def render

Public Attributes

 data
 unqual_data_id
 data_id
 request

Static Public Attributes

 format = _format
 render = _format

Private Member Functions

def _name
def _makeoption
def _filteroptions
def _format

Private Attributes

 _all
 __all
 _notempty
 __notempty
 _empty
 __empty
 _filter
 __filter
 _show_header

Detailed Description

Definition at line 12 of file browser.py.


Constructor & Destructor Documentation

def MoinMoin.widget.browser.DataBrowserWidget.__init__ (   self,
  request,
  show_header = True,
  kw 
)

Definition at line 14 of file browser.py.

00014 
00015     def __init__(self, request, show_header=True, **kw):
00016         _ = request.getText
00017         base.Widget.__init__(self, request, **kw)
00018         self.data = None
00019         self.unqual_data_id = 'dbw.'
00020         self.data_id = request.formatter.qualify_id(self.unqual_data_id)
00021         # prefixed with __ are untranslated and to be used in the JS
00022         self._all = _('[all]')
00023         self.__all = '[all]'
00024         self._notempty = _('[not empty]')
00025         self.__notempty = '[notempty]'
00026         self._empty = _('[empty]')
00027         self.__empty = '[empty]'
00028         self._filter = _('filter')
00029         self.__filter = 'filter'
00030         self._show_header = show_header


Member Function Documentation

def MoinMoin.widget.browser.DataBrowserWidget._filteroptions (   self,
  idx 
) [private]
create options for all elements in the column
    given by idx

Definition at line 67 of file browser.py.

00067 
00068     def _filteroptions(self, idx):
00069         """ create options for all elements in the column
00070             given by idx
00071         """
00072         self.data.reset()
00073         row = self.data.next()
00074         # [empty] is a special already
00075         unique = ['']
00076 
00077         value = None
00078         name = '%sfilter%d' % (self.data_id, idx)
00079         if name in self.request.values:
00080             value = self.request.values.getlist(name)
00081         while row:
00082             option = row[idx]
00083             if isinstance(option, tuple):
00084                 option = option[1]
00085             if not option in unique:
00086                 unique.append(option)
00087             row = self.data.next()
00088 
00089         # fill in the empty field we left blank
00090         del unique[0]
00091         unique.sort()
00092         result = [self._makeoption(item, item == value) for item in unique]
00093         common = []
00094         common.append(self._makeoption(self._all, value == self.__all, self.__all))
00095         if '' in unique:
00096             common.extend([
00097                 self._makeoption(self._empty, value == self.__empty, self.__empty),
00098                 self._makeoption(self._notempty, value == self.__notempty, self.__notempty),
00099             ])
00100         return '\n'.join(common + result)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.widget.browser.DataBrowserWidget._format (   self,
  formatter = None,
  method = None 
) [private]
does the formatting of the table
@param formatter: formatter
@param method: None is the default and does not create a form
       while "GET" or "POST" will create the form using the given method

Definition at line 101 of file browser.py.

00101 
00102     def _format(self, formatter=None, method=None):
00103         """
00104         does the formatting of the table
00105         @param formatter: formatter
00106         @param method: None is the default and does not create a form
00107                        while "GET" or "POST" will create the form using the given method
00108         """
00109         fmt = formatter or self.request.formatter
00110 
00111         result = []
00112         if method:
00113             result.append(fmt.rawHTML('<form action="%s/%s" method="%s" name="%sform">' % (self.request.script_root, wikiutil.quoteWikinameURL(self.request.page.page_name), method, self.data_id)))
00114         result.append(fmt.div(1))
00115 
00116         havefilters = False
00117         for col in self.data.columns:
00118             if col.autofilter:
00119                 havefilters = True
00120                 break
00121         if havefilters:
00122             result.append(fmt.rawHTML('<input type="submit" value="%s" %s>' % (self._filter, self._name('submit'))))
00123 
00124         result.append(fmt.table(1, id='%stable' % self.unqual_data_id))
00125 
00126         # add header line
00127         if self._show_header:
00128             result.append(fmt.table_row(1))
00129             for idx in range(len(self.data.columns)):
00130                 col = self.data.columns[idx]
00131                 if col.hidden:
00132                     continue
00133                 cell_attrs = {'class': 'hcolumn%d' % idx}
00134                 result.append(fmt.table_cell(1, cell_attrs))
00135                 result.append(fmt.strong(1))
00136                 result.append(col.label or col.name)
00137                 result.append(fmt.strong(0))
00138 
00139                 if col.autofilter:
00140                     result.append(fmt.linebreak(False))
00141                     select = '<select %s onchange="dbw_update_search(\'%s\');">%s</select>' % (
00142                                       self._name('filter%d' % idx),
00143                                       self.data_id,
00144                                       self._filteroptions(idx))
00145                     result.append(fmt.rawHTML(select))
00146 
00147                 result.append(fmt.table_cell(0))
00148             result.append(fmt.table_row(0))
00149 
00150         # add data
00151         self.data.reset()
00152         row = self.data.next()
00153         if row is not None:
00154             filters = [None] * len(row)
00155 
00156             if havefilters:
00157                 for idx in range(len(row)):
00158                     name = '%sfilter%d' % (self.data_id, idx)
00159                     if name in self.request.values:
00160                         filters[idx] = self.request.getlist(name)
00161                         if filters[idx] == self._all:
00162                             filters[idx] = None
00163 
00164         while row:
00165             hidden = False
00166 
00167             if havefilters:
00168                 # check if row needs to be hidden due to filtering
00169                 for idx in range(len(row)):
00170                     if filters[idx]:
00171                         if isinstance(row[idx], tuple):
00172                             data = unicode(row[idx][1])
00173                         else:
00174                             data = unicode(row[idx])
00175                         if data != '' and filters[idx] == self._notempty:
00176                             continue
00177                         if data == '' and filters[idx] == self._empty:
00178                             continue
00179                         if data != filters[idx]:
00180                             hidden = True
00181                             break
00182 
00183             if not hidden:
00184                 result.append(fmt.table_row(1))
00185                 for idx in range(len(row)):
00186                     if self.data.columns[idx].hidden:
00187                         continue
00188                     cell_attrs = {'class': 'column%d' % idx}
00189                     if isinstance(row[idx], tuple):
00190                         result.append(fmt.table_cell(1, cell_attrs, abbr=unicode(row[idx][1])))
00191                         result.append(unicode(row[idx][0]))
00192                     else:
00193                         result.append(fmt.table_cell(1, cell_attrs))
00194                         result.append(unicode(row[idx]))
00195                     result.append(fmt.table_cell(0))
00196                 result.append(fmt.table_row(0))
00197 
00198             row = self.data.next()
00199 
00200         result.append(fmt.table(0))
00201         result.append(fmt.div(0))
00202         if method:
00203             result.append(fmt.rawHTML('</form>'))
00204         return ''.join(result)

Here is the call graph for this function:

def MoinMoin.widget.browser.DataBrowserWidget._makeoption (   self,
  item,
  selected,
  ntitem = None 
) [private]
create an option for a <select> form element
@param item: string containing the item name to show
@param selected: indicates whether the item should be default or not

Definition at line 50 of file browser.py.

00050 
00051     def _makeoption(self, item, selected, ntitem=None):
00052         """ create an option for a <select> form element
00053         @param item: string containing the item name to show
00054         @param selected: indicates whether the item should be default or not
00055         """
00056         if selected:
00057             selected = ' selected'
00058         else:
00059             selected = ''
00060         assert(isinstance(item, basestring))
00061         if ntitem is None:
00062             ntitem = item
00063         return '<option value="%s"%s>%s</option>' % (
00064             wikiutil.escape(ntitem, True),
00065             selected,
00066             wikiutil.escape(item))

Here is the caller graph for this function:

def MoinMoin.widget.browser.DataBrowserWidget._name (   self,
  elem 
) [private]
return name tag for a HTML element
@param elem: element name, will be prefixed by data id

Definition at line 44 of file browser.py.

00044 
00045     def _name(self, elem):
00046         """ return name tag for a HTML element
00047         @param elem: element name, will be prefixed by data id
00048         """
00049         return 'name="%s%s"' % (self.data_id, elem)

Here is the caller graph for this function:

def MoinMoin.widget.base.Widget.render (   self) [inherited]

Reimplemented in MoinMoin.widget.dialog.Status, and MoinMoin.widget.dialog.Dialog.

Definition at line 14 of file base.py.

00014 
00015     def render(self):
00016         raise NotImplementedError
00017 
Sets the data for the browser (see MoinMoin.util.dataset).

@param dataset: dataset containing either ascii, unicode or tuples.
        If a dataset entry contains a tuple then the first
        item in the tuple is displayed and the second item
        is used for autofilters.

Definition at line 31 of file browser.py.

00031 
00032     def setData(self, dataset):
00033         """ Sets the data for the browser (see MoinMoin.util.dataset).
00034 
00035         @param dataset: dataset containing either ascii, unicode or tuples.
00036                         If a dataset entry contains a tuple then the first
00037                         item in the tuple is displayed and the second item
00038                         is used for autofilters.
00039         """
00040         self.data = dataset
00041         if dataset.data_id:
00042             self.unqual_data_id = 'dbw.%s.' % dataset.data_id
00043             self.data_id = self.request.formatter.qualify_id(self.unqual_data_id)


Member Data Documentation

Definition at line 22 of file browser.py.

Definition at line 26 of file browser.py.

Definition at line 28 of file browser.py.

Definition at line 24 of file browser.py.

Definition at line 21 of file browser.py.

Definition at line 25 of file browser.py.

Definition at line 27 of file browser.py.

Definition at line 23 of file browser.py.

Definition at line 29 of file browser.py.

Definition at line 17 of file browser.py.

Definition at line 19 of file browser.py.

Definition at line 205 of file browser.py.

Definition at line 207 of file browser.py.

Definition at line 12 of file base.py.

Definition at line 18 of file browser.py.


The documentation for this class was generated from the following file: