def getLocale(self, request): ## FIXME: implement request.locale() tags = ACCEPT_LANGUAGE.parse(request.environ()) if tags: return Locale.parse(tags[0], sep="-") else: return defaultLocale() # server default
def getLocale(self, request): ## FIXME: implement request.locale() tags = ACCEPT_LANGUAGE.parse(request.environ()) if tags: try: return Locale.parse(tags[0], sep='-') except UnknownLocaleError, e: try: return Locale.parse(tags[0]) except UnknownLocaleError, e: logger.error('Locale parsing error: %s' % e) return defaultLocale()
def getLocale(self): """Gets the default locale for this application. By default this is the preferred locale of the user using the application. In most cases it is read from the browser defaults. @return: the locale of this application. """ if self._locale is not None: return self._locale return defaultLocale()
def addOrderToContainer(cls, container, description, quantity, price): l = defaultLocale() itemId = container.addItem() item = container.getItem(itemId) v = description item.getItemProperty(cls.ORDER_DESCRIPTION_PROPERTY_ID).setValue(v) v = quantity item.getItemProperty(cls.ORDER_QUANTITY_PROPERTY_ID).setValue(v) v = format_currency(price, currency="USD", locale=l).encode("utf-8") item.getItemProperty(cls.ORDER_UNITPRICE_PROPERTY_ID).setValue(v) v = format_currency(price * quantity, currency="USD", locale=l) v = v.encode("utf-8") item.getItemProperty(cls.ORDER_ITEMPRICE_PROPERTY_ID).setValue(v)
def addOrderToContainer(cls, container, description, quantity, price): l = defaultLocale() itemId = container.addItem() item = container.getItem(itemId) v = description item.getItemProperty(cls.ORDER_DESCRIPTION_PROPERTY_ID).setValue(v) v = quantity item.getItemProperty(cls.ORDER_QUANTITY_PROPERTY_ID).setValue(v) v = format_currency(price, currency='USD', locale=l).encode('utf-8') item.getItemProperty(cls.ORDER_UNITPRICE_PROPERTY_ID).setValue(v) v = format_currency(price * quantity, currency='USD', locale=l) v = v.encode('utf-8') item.getItemProperty(cls.ORDER_ITEMPRICE_PROPERTY_ID).setValue(v)
def __init__(self): super(TableFooterExample, self).__init__() # Create our data source dataSource = ExampleUtil.getOrderContainer() # Calculate total sum totalSum = 0.0 for i in range(len(dataSource)): item = dataSource.getItem(dataSource.getIdByIndex(i)) value = item.getItemProperty( ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID).getValue() match = re.search(self.CURRENCY_PATTERN, str(value)) if match is not None: amount = match.groups()[1] totalSum += float(amount) # Create a table to show the data in table = Table('Order table', dataSource) table.setPageLength(6) table.setWidth('100%') # Set alignments table.setColumnAlignments([ Table.ALIGN_LEFT, Table.ALIGN_RIGHT, Table.ALIGN_RIGHT, Table.ALIGN_RIGHT ]) # Set column widths table.setColumnExpandRatio(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 1) # Enable footer table.setFooterVisible(True) # Add some total sum and description to footer table.setColumnFooter(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 'Total Price') l = defaultLocale() fc = format_currency(totalSum, currency='USD', locale=l).encode('utf-8') table.setColumnFooter(ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID, fc) self.addComponent(table)
def __init__(self): super(TableClickListenersExample, self).__init__() # Create our data source dataSource = ExampleUtil.getOrderContainer() # Calculate total sum totalSum = 0.0 for i in range(len(dataSource)): item = dataSource.getItem(dataSource.getIdByIndex(i)) value = item.getItemProperty( ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID).getValue() #amount = NumberFormat.getCurrencyInstance().parse(str(value)) amount = re.search(u'([\u00A3\u0024\u20AC])(\d+(?:\.\d{2})?)', str(value)).groups()[1] totalSum += float(amount) # Create table table = Table('', ExampleUtil.getOrderContainer()) table.setColumnExpandRatio(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 1) table.setSortDisabled(True) table.setWidth('100%') table.setPageLength(6) table.setFooterVisible(True) table.setImmediate(True) # Add some total sum and description to footer table.setColumnFooter(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 'Total Price') l = defaultLocale() fc = format_currency(totalSum, currency='USD', locale=l).encode('utf-8') table.setColumnFooter(ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID, fc) # Add a header click handler table.addListener(HeaderListener(self), IHeaderClickListener) # Add a footer click handler table.addListener(FooterListener(self), IFooterClickListener) self.addComponent(table)
def __init__(self): super(TableFooterExample, self).__init__() # Create our data source dataSource = ExampleUtil.getOrderContainer() # Calculate total sum totalSum = 0.0 for i in range(len(dataSource)): item = dataSource.getItem(dataSource.getIdByIndex(i)) value = item.getItemProperty( ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID).getValue() match = re.search(self.CURRENCY_PATTERN, str(value)) if match is not None: amount = match.groups()[1] totalSum += float(amount) # Create a table to show the data in table = Table('Order table', dataSource) table.setPageLength(6) table.setWidth('100%') # Set alignments table.setColumnAlignments([Table.ALIGN_LEFT, Table.ALIGN_RIGHT, Table.ALIGN_RIGHT, Table.ALIGN_RIGHT]) # Set column widths table.setColumnExpandRatio(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 1) # Enable footer table.setFooterVisible(True) # Add some total sum and description to footer table.setColumnFooter(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 'Total Price') l = defaultLocale() fc = format_currency(totalSum, currency='USD', locale=l).encode('utf-8') table.setColumnFooter(ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID, fc) self.addComponent(table)
def __init__(self): super(TableClickListenersExample, self).__init__() # Create our data source dataSource = ExampleUtil.getOrderContainer() # Calculate total sum totalSum = 0.0 for i in range(len(dataSource)): item = dataSource.getItem(dataSource.getIdByIndex(i)) value = item.getItemProperty( ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID).getValue() match = re.search(self.CURRENCY_PATTERN, str(value)) if match is not None: amount = match.groups()[1] totalSum += float(amount) # Create table table = Table('', ExampleUtil.getOrderContainer()) table.setColumnExpandRatio(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 1) table.setSortDisabled(True) table.setWidth('100%') table.setPageLength(6) table.setFooterVisible(True) table.setImmediate(True) # Add some total sum and description to footer table.setColumnFooter(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID, 'Total Price') l = defaultLocale() fc = format_currency(totalSum, currency='USD', locale=l).encode('utf-8') table.setColumnFooter(ExampleUtil.ORDER_ITEMPRICE_PROPERTY_ID, fc) # Add a header click handler table.addListener(HeaderListener(self), IHeaderClickListener) # Add a footer click handler table.addListener(FooterListener(self), IFooterClickListener) self.addComponent(table)
return PATH_INFO(request.environ()) def getLocale(self, request): ## FIXME: implement request.locale() tags = ACCEPT_LANGUAGE.parse(request.environ()) if tags: try: return Locale.parse(tags[0], sep='-') except UnknownLocaleError, e: try: return Locale.parse(tags[0]) except UnknownLocaleError, e: logger.error('Locale parsing error: %s' % e) return defaultLocale() else: return defaultLocale() # server default def getServerName(self, request): return request.environ().get('SERVER_NAME', '') def isSecure(self, request): """Check whether the request is a HTTPS connection.""" return request.environ().get('HTTPS', '').lower() == 'on' def getInputStream(self, request): return request.rawInput() # Response def setHeader(self, response, name, value): response.setHeader(name, value)
def getLocale(self, request): ## FIXME: implement request.locale() tags = ACCEPT_LANGUAGE.parse(request.environ()) if tags: try: return Locale.parse(tags[0], sep='-') except UnknownLocaleError, e: try: return Locale.parse(tags[0]) except UnknownLocaleError, e: logger.error('Locale parsing error: %s' % e) return defaultLocale() else: return defaultLocale() # server default def getServerName(self, request): return request.environ().get('SERVER_NAME', '') def isSecure(self, request): """Check whether the request is a HTTPS connection.""" return request.environ().get('HTTPS', '').lower() == 'on' def getInputStream(self, request): return request.rawInput() # Response