Exemplo n.º 1
0
 def tt_daylabel(self, cell=None, day=None):
     if hasattr(self, 'tt_%s_daylabel' % self.tt_pars['nodeId']):
         return getattr(self, 'tt_%s_daylabel' % self.tt_pars['nodeId'])(cell, day=day)
     daylabel = cell.div(_class='daylabel', **rect(top=1, bottom=1, left=1, right=1))
     daylabel.div(toText(day, format='eeee', locale=self.locale), _class='daylabel_wd daylabel_wd%i' % day.weekday())
     daylabel.div(toText(day, format='d', locale=self.locale), _class='daylabel_day')
     daylabel.div(toText(day, format='MMMM', locale=self.locale), _class='daylabel_month')
Exemplo n.º 2
0
 def tt_daylabel(self, cell=None, day=None):
     if hasattr(self, 'tt_%s_daylabel' % self.tt_pars['nodeId']):
         return getattr(self,
                        'tt_%s_daylabel' % self.tt_pars['nodeId'])(cell,
                                                                   day=day)
     daylabel = cell.div(_class='daylabel',
                         **rect(top=1, bottom=1, left=1, right=1))
     daylabel.div(toText(day, format='eeee', locale=self.locale),
                  _class='daylabel_wd daylabel_wd%i' % day.weekday())
     daylabel.div(toText(day, format='d', locale=self.locale),
                  _class='daylabel_day')
     daylabel.div(toText(day, format='MMMM', locale=self.locale),
                  _class='daylabel_month')
Exemplo n.º 3
0
    def writeRow(self, row, sheet_name=None):
        """TODO
        
        :param row: TODO"""
        sheet_name = sheet_name or self.sheet_base_name
        current_row = self.sheets[sheet_name]['current_row'] + 1
        self.sheets[sheet_name]['current_row'] = current_row
        sheet = self.sheets[sheet_name]['sheet']
        columns = self.sheets[sheet_name]['columns']
        coltypes = self.sheets[sheet_name]['coltypes']
        colsizes = self.sheets[sheet_name]['colsizes']

        for c, col in enumerate(columns):
            value = row.get(col)
            if isinstance(value, list):
                value = ','.join([str(x != None and x or '') for x in value])
            coltype = coltypes.get(col)
            if coltype in ('R', 'F', 'N'):
                sheet.write(current_row, c, value, self.float_style)
            elif coltype in ('L', 'I'):
                sheet.write(current_row, c, value, self.int_style)
            else:
                value = toText(value, self.locale)
                sheet.write(current_row, c, value)
            colsizes[c] = max(colsizes.get(c, 0), self.fitwidth(value))
Exemplo n.º 4
0
    def writeRow(self, row, sheet_name=None):
        """TODO
        
        :param row: TODO"""
        sheet_name = sheet_name or self.sheet_base_name
        current_row = self.sheets[sheet_name]['current_row'] + 1
        self.sheets[sheet_name]['current_row'] = current_row
        sheet = self.sheets[sheet_name]['sheet']
        columns = self.sheets[sheet_name]['columns']
        coltypes = self.sheets[sheet_name]['coltypes']
        colsizes = self.sheets[sheet_name]['colsizes']

        for c, col in enumerate(columns):
            value = row.get(col)
            if isinstance(value, list):
                value = ','.join([str(x != None and x or '') for x in value])
            coltype = coltypes.get(col)
            if coltype in ('R', 'F', 'N'):
                sheet.write(current_row, c, value, self.float_style)
            elif coltype in ('L', 'I'):
                sheet.write(current_row, c, value, self.int_style)
            else:
                value = toText(value, self.locale)
                sheet.write(current_row, c, value)
            colsizes[c] = max(colsizes.get(c, 0), self.fitwidth(value))
Exemplo n.º 5
0
    def prepareTableRow(self,
                        row,
                        totals=False,
                        excel=False,
                        excel_nobr=False):
        row = dict(row)
        pkey = row.pop('pkey', None)
        i = self.counter
        if self.row_cb:
            # you can return a new row object or modify the current one:
            # row is the actual db cursor, so maybe mutable or not
            row = self.row_cb(pkey, row, i) or row
        if not row:  # if row_cb clean row object skip the whole row
            self._counter = self._counter - 1
            return ''

        for k, v in row.items():
            row[k] = gnrstring.toText(
                v,
                locale=self.locale,
                format=self.getColumnFormat(k, v),
                mask=self.row_maskDict.get(k)) or ' '

        row['pkey'] = pkey or ''
        row['odd_even'] = 'odd_row' * (i % 2) or 'even_row'
        return row
Exemplo n.º 6
0
 def __call__(self, row):
     result = {}
     for k, v in row.items():
         result[k] = gnrstring.toText(v, locale=self.locale,
                                      format=self.colformats.get(k) or self.typeformats.get(type(v)),
                                      mask=self.colmasks.get(k)
                                      ) or self.emptyValue
     return result
Exemplo n.º 7
0
 def toText(self, obj, locale=None, format=None, mask=None, encoding=None):
     locale = locale or self.locale
     encoding = locale or self.encoding
     return toText(obj,
                   locale=locale,
                   format=format,
                   mask=mask,
                   encoding=encoding)
Exemplo n.º 8
0
 def __call__(self, row):
     result = {}
     for k, v in row.items():
         result[k] = gnrstring.toText(
             v,
             locale=self.locale,
             format=self.colformats.get(k) or self.typeformats.get(type(v)),
             mask=self.colmasks.get(k)) or self.emptyValue
     return result
Exemplo n.º 9
0
 def tt_mytt_slot(self, pane, slot=None, width=None, height=None):
     patient = slot['patient']
     if patient is None:
         status = 'ttfree'
     elif patient == '-':
         status = 'ttunavailable'
     else:
         status = 'ttbusy'
     slotdiv = pane.div(_class='ttslot %s' % status, height='100%')
     slotdiv.div(_class='ttslot_T').span(toText(slot['ts'], format='HH:mm'), margin='5px')
Exemplo n.º 10
0
def periodCaption(dateFrom=None, dateTo=None, locale=None):
    """Convert two dates to a string in the specified locale that
    :meth:`decodeDatePeriod` will understand
    
    :param dateFrom: the beginning period date
    :param dateTo: the ending period date
    :param locale: the current locale (e.g: en, en_us, it)"""
    localNoPeriod = gnrlocale.getDateKeywords('no period', locale)[0]
    localTo = gnrlocale.getDateKeywords('to', locale)[0]
    localFrom = gnrlocale.getDateKeywords('from', locale)[0]
    textFrom = toText(dateFrom, locale=locale)
    textTo = toText(dateTo, locale=locale)
    if dateFrom and dateTo:
        return '%s %s %s %s' % (localFrom, textFrom, localTo, textTo)
    if dateFrom:
        return '%s %s' % (localFrom, textFrom)
    elif dateTo:
        return '%s %s' % (localTo, textTo)
    else:
        return localNoPeriod
Exemplo n.º 11
0
 def toText(self, obj, locale=None, format=None, mask=None, encoding=None, **kwargs):
     """TODO
     
     :param obj: TODO
     :param locale: the current locale (e.g: en, en_us, it)
     :param format: TODO
     :param mask: TODO
     :param encoding: the multibyte character encoding you choose"""
     locale = locale or self.locale
     encoding = locale or self.encoding
     return toText(obj, locale=locale, format=format, mask=mask, encoding=encoding, **kwargs)
Exemplo n.º 12
0
def periodCaption(dateFrom=None, dateTo=None, locale=None):
    """Convert two dates to a string in the specified locale that
    :meth:`decodeDatePeriod` will understand
    
    :param dateFrom: the beginning period date
    :param dateTo: the ending period date
    :param locale: the current locale (e.g: en, en_us, it)"""
    localNoPeriod = gnrlocale.getDateKeywords('no period', locale)[0]
    localTo = gnrlocale.getDateKeywords('to', locale)[0]
    localFrom = gnrlocale.getDateKeywords('from', locale)[0]
    textFrom = toText(dateFrom, locale=locale)
    textTo = toText(dateTo, locale=locale)
    if dateFrom and dateTo:
        return '%s %s %s %s' % (localFrom, textFrom, localTo, textTo)
    if dateFrom:
        return '%s %s' % (localFrom, textFrom)
    elif dateTo:
        return '%s %s' % (localTo, textTo)
    else:
        return localNoPeriod
Exemplo n.º 13
0
def periodCaption(dateFrom=None, dateTo=None, locale=None):
    """Convert two dates to a string in the specified locale that decodeDatePeriod will understand.
    
    :param dateFrom: add???. Default value is ``None``
    :param dateTo: add???. Default value is ``None``
    :param locale: add???. Default value is ``None``
    :returns: add???
    """
    localNoPeriod = gnrlocale.getDateKeywords('no period', locale)[0]
    localTo = gnrlocale.getDateKeywords('to', locale)[0]
    localFrom = gnrlocale.getDateKeywords('from', locale)[0]
    textFrom = toText(dateFrom, locale=locale)
    textTo = toText(dateTo, locale=locale)
    if dateFrom and dateTo:
        return '%s %s %s %s' % (localFrom, textFrom, localTo, textTo)
    if dateFrom:
        return '%s %s' % (localFrom, textFrom)
    elif dateTo:
        return '%s %s' % (localTo, textTo)
    else:
        return localNoPeriod
Exemplo n.º 14
0
def periodCaption(dateFrom=None, dateTo=None, locale=None):
    """Convert two dates to a string in the specified locale that decodeDatePeriod will understand.
    
    :param dateFrom: add???. Default value is ``None``
    :param dateTo: add???. Default value is ``None``
    :param locale: add???. Default value is ``None``
    :returns: add???
    """
    localNoPeriod = gnrlocale.getDateKeywords('no period', locale)[0]
    localTo = gnrlocale.getDateKeywords('to', locale)[0]
    localFrom = gnrlocale.getDateKeywords('from', locale)[0]
    textFrom = toText(dateFrom, locale=locale)
    textTo = toText(dateTo, locale=locale)
    if dateFrom and dateTo:
        return '%s %s %s %s' % (localFrom, textFrom, localTo, textTo)
    if dateFrom:
        return '%s %s' % (localFrom, textFrom)
    elif dateTo:
        return '%s %s' % (localTo, textTo)
    else:
        return localNoPeriod
Exemplo n.º 15
0
 def getOneBlock(self, row, grouplist, prevperiod=False):
     if prevperiod:
         data = self.dataprev
     else:
         data = self.data
     path = '.'.join([grouplist[0]] + [toText(row[x]).replace('.', '_') for x in grouplist[1:]])
     result = data.getNode(path)
     if result is None:
         data.setItem(path, None)
         if prevperiod:
             self.data.setItem(path, None) # if a path is only in prev period put in in current also
         result = data.getNode(path)
     return result
Exemplo n.º 16
0
 def getOneBlock(self, row, grouplist, prevperiod=False):
     if prevperiod:
         data = self.dataprev
     else:
         data = self.data
     path = ".".join([grouplist[0]] + [toText(row[x]).replace(".", "_") for x in grouplist[1:]])
     result = data.getNode(path)
     if result is None:
         data.setItem(path, None)
         if prevperiod:
             self.data.setItem(path, None)  # if a path is only in prev period put in in current also
         result = data.getNode(path)
     return result
Exemplo n.º 17
0
 def toText(self, obj, locale=None, format=None, mask=None, encoding=None, **kwargs):
     """add???
     
     :param obj: add???
     :param locale: add???. Default value is ``None``
     :param format: add???. Default value is ``None``
     :param mask: add???. Default value is ``None``
     :param encoding: The multibyte character encoding you choose. Default value is ``None``
     :returns: add???
     """
     locale = locale or self.locale
     encoding = locale or self.encoding
     return toText(obj, locale=locale, format=format, mask=mask, encoding=encoding, **kwargs)
Exemplo n.º 18
0
def errorTxt():
    """TODO"""
    el = sys.exc_info()
    tb_text = traceback.format_exc()
    e = el[2]
    while e.tb_next:
        e = e.tb_next
        
    locals_list = []
    for k, v in e.tb_frame.f_locals.items():
        try:
            from gnr.core.gnrstring import toText
            strvalue = toText(v)
        except:
            strvalue = 'unicode error'
        locals_list.append('%s: %s' % (k, strvalue))
    return u'%s\n\nLOCALS:\n\n%s' % (tb_text, '\n'.join(locals_list))
Exemplo n.º 19
0
def errorTxt():
    """TODO"""
    el = sys.exc_info()
    tb_text = traceback.format_exc()
    e = el[2]
    while e.tb_next:
        e = e.tb_next

    locals_list = []
    for k, v in e.tb_frame.f_locals.items():
        try:
            from gnr.core.gnrstring import toText
            strvalue = toText(v)
        except:
            strvalue = 'unicode error'
        locals_list.append('%s: %s' % (k, strvalue))
    return u'%s\n\nLOCALS:\n\n%s' % (tb_text, '\n'.join(locals_list))
Exemplo n.º 20
0
 def writeRow(self, row):
     """TODO
     
     :param row: TODO"""
     self.current_row += 1
     for c, col in enumerate(self.columns):
         value = row.get(col)
         if isinstance(value, list):
             value = ','.join([str(x != None and x or '') for x in value])
         coltype = self.coltypes.get(col)
         if coltype in ('R', 'F', 'N'):
             self.sheet.write(self.current_row, c, value, self.float_style)
         elif coltype in ('L', 'I'):
             self.sheet.write(self.current_row, c, value, self.int_style)
         else:
             value = toText(value, self.locale)
             self.sheet.write(self.current_row, c, value)
         self.colsizes[c] = max(self.colsizes.get(c, 0), self.fitwidth(value))
Exemplo n.º 21
0
 def writeRow(self, row):
     """TODO
     
     :param row: TODO"""
     self.current_row += 1
     for c, col in enumerate(self.columns):
         value = row.get(col)
         if isinstance(value, list):
             value = ','.join([str(x != None and x or '') for x in value])
         coltype = self.coltypes.get(col)
         if coltype in ('R', 'F', 'N'):
             self.sheet.write(self.current_row, c, value, self.float_style)
         elif coltype in ('L', 'I'):
             self.sheet.write(self.current_row, c, value, self.int_style)
         else:
             value = toText(value, self.locale)
             self.sheet.write(self.current_row, c, value)
         self.colsizes[c] = max(self.colsizes.get(c, 0),
                                self.fitwidth(value))
Exemplo n.º 22
0
 def prepareTableRow(self, row, totals=False, excel=False, excel_nobr=False):
     row = dict(row)
     pkey = row.pop('pkey', None)
     i = self.counter
     if self.row_cb:
         # you can return a new row object or modify the current one: 
         # row is the actual db cursor, so maybe mutable or not
         row = self.row_cb(pkey, row, i) or row
     if not row: # if row_cb clean row object skip the whole row
         self._counter = self._counter - 1
         return ''
         
     for k, v in row.items():
         row[k] = gnrstring.toText(v, locale=self.locale, format=self.getColumnFormat(k, v),
                                   mask=self.row_maskDict.get(k)) or ' '
                                   
     row['pkey'] = pkey or ''
     row['odd_even'] = 'odd_row' * (i % 2) or 'even_row'
     return row
Exemplo n.º 23
0
    def readRow(self, row, prevperiod=False):
        for colnum, grprods in self.colgroups.items():
            if not ((grprods == "*tot*") or (row[self.grcol] in grprods)):
                continue
            blocknode = self.getOneBlock(row, self.subtotals, prevperiod=prevperiod)
            blockAttr = blocknode.getAttr()
            if not blockAttr and self.anagfields:
                self.getAnagFields(row, blockAttr)
                blockAttr["_sort_"] = self.sortKey(row, self.subtotals[:-1]) + "_".join(
                    [toText(blockAttr[k]) for k in self.sortfields]
                )

                if prevperiod:  # aggiungo una riga al precedente e, se manca, anche al corrente
                    newblockAttr = self.getOneBlock(row, self.subtotals, prevperiod=False).getAttr()
                    if not newblockAttr:
                        newblockAttr.update(blockAttr)

                grouplist = []
                for i, gr in enumerate(self.subtotals[:-1]):
                    grouplist.append(gr)
                    grAttr = self.getOneBlock(row, grouplist, prevperiod=prevperiod).getAttr()
                    grAttr["_sort_"] = self.sortKey(row, grouplist) + "_zzzzzzzzzzzzzzzzzzzz"
                    grAttr["_subtot_"] = "subtot_%i" % i

                    grAttr.update(dict([(x, row[x]) for x in grouplist[1:]]))
                    if prevperiod:
                        newgrAttr = self.getOneBlock(row, grouplist, prevperiod=False).getAttr()
                        if not newgrAttr:
                            newgrAttr.update(grAttr)

            values = self.getRowValues(row, colnum, blockAttr)

            grouplist = []
            for i, gr in enumerate(self.subtotals):
                grouplist.append(gr)
                blocknode = self.getOneBlock(row, grouplist, prevperiod=prevperiod)
                blockAttr = blocknode.getAttr()
                # if (i < (len(self.subtotals)-1)):
                #    blockAttr['_subtot_'] = 'subtot_%i' % i
                self.addToGroup(values, colnum, blockAttr)
Exemplo n.º 24
0
 def toText(self,
            obj,
            locale=None,
            format=None,
            mask=None,
            encoding=None,
            **kwargs):
     """TODO
     
     :param obj: TODO
     :param locale: the current locale (e.g: en, en_us, it)
     :param format: TODO
     :param mask: TODO
     :param encoding: the multibyte character encoding you choose"""
     locale = locale or self.locale
     encoding = locale or self.encoding
     return toText(obj,
                   locale=locale,
                   format=format,
                   mask=mask,
                   encoding=encoding,
                   **kwargs)
Exemplo n.º 25
0
    def readRow(self, row, prevperiod=False):
        for colnum, grprods in self.colgroups.items():
            if not ((grprods == '*tot*') or (row[self.grcol] in grprods)):
                continue
            blocknode = self.getOneBlock(row, self.subtotals, prevperiod=prevperiod)
            blockAttr = blocknode.getAttr()
            if not blockAttr and self.anagfields:
                self.getAnagFields(row, blockAttr)
                blockAttr['_sort_'] = self.sortKey(row, self.subtotals[:-1]) + '_'.join(
                        [toText(blockAttr[k]) for k in self.sortfields])

                if prevperiod: # aggiungo una riga al precedente e, se manca, anche al corrente
                    newblockAttr = self.getOneBlock(row, self.subtotals, prevperiod=False).getAttr()
                    if not newblockAttr:
                        newblockAttr.update(blockAttr)

                grouplist = []
                for i, gr in enumerate(self.subtotals[:-1]):
                    grouplist.append(gr)
                    grAttr = self.getOneBlock(row, grouplist, prevperiod=prevperiod).getAttr()
                    grAttr['_sort_'] = self.sortKey(row, grouplist) + '_zzzzzzzzzzzzzzzzzzzz'
                    grAttr['_subtot_'] = 'subtot_%i' % i

                    grAttr.update(dict([(x, row[x]) for x in grouplist[1:]]))
                    if prevperiod:
                        newgrAttr = self.getOneBlock(row, grouplist, prevperiod=False).getAttr()
                        if not newgrAttr:
                            newgrAttr.update(grAttr)

            values = self.getRowValues(row, colnum, blockAttr)

            grouplist = []
            for i, gr in enumerate(self.subtotals):
                grouplist.append(gr)
                blocknode = self.getOneBlock(row, grouplist, prevperiod=prevperiod)
                blockAttr = blocknode.getAttr()
                #if (i < (len(self.subtotals)-1)):
                #    blockAttr['_subtot_'] = 'subtot_%i' % i
                self.addToGroup(values, colnum, blockAttr)
Exemplo n.º 26
0
 def recordCaption(self, record, newrecord=False, rowcaption=None):
     """add???
     
     :param record: add???
     :param newrecord: boolean. add???. Default value is ``False``
     :param rowcaption: add???. Default value is ``None``
     :returns: add???
     """
     if newrecord:
         return '!!New %s' % self.name_long.replace('!!', '')
     else:
         fields, mask = self.rowcaptionDecode(rowcaption)
         if not fields:
             return ''
         fields = [f.lstrip('$') for f in fields]
         if not isinstance(record, Bag):
             fields = [self.db.colToAs(f) for f in fields]
         cols = [(c, gnrstring.toText(record[c])) for c in fields]
         if '$' in mask:
             caption = gnrstring.templateReplace(mask, dict(cols))
         else:
             caption = mask % tuple([v for k, v in cols])
         return caption
Exemplo n.º 27
0
 def writeRow(self, row):
     self.result.append('\t'.join([self.cleanCol(toText(row.get(col)), self.coltypes[col]) for col in self.columns]))
Exemplo n.º 28
0
 def writeRow(self, row, separator='\t'):
     self.result.append(
         separator.join([
             self.cleanCol(toText(row.get(col), locale=self.locale),
                           self.coltypes[col]) for col in self.columns
         ]))
Exemplo n.º 29
0
 def sortKey(self, row, grouplist):
     return '_'.join([toText(row[x]).replace('.', '_') for x in grouplist[1:]])
Exemplo n.º 30
0
 def date_converter(mode):
     datefield, formatmode = mode.split(':')
     return lambda r: toText(r[datefield], format=formatmode, locale=self.locale)
Exemplo n.º 31
0
 def toText(self, obj, locale=None, format=None, mask=None, encoding=None):
     locale = locale or self.locale
     encoding = locale or self.encoding
     return toText(obj, locale=locale, format=format, mask=mask, encoding=encoding)
     
Exemplo n.º 32
0
 def date_converter(mode):
     datefield, formatmode = mode.split(':')
     return lambda r: toText(
         r[datefield], format=formatmode, locale=self.locale)
Exemplo n.º 33
0
 def writeRow(self, row):
     self.result.append('\t'.join([self.cleanCol(toText(row.get(col),locale=self.locale), self.coltypes[col]) for col in self.columns]))
Exemplo n.º 34
0
 def sortKey(self, row, grouplist):
     return "_".join([toText(row[x]).replace(".", "_") for x in grouplist[1:]])