def page_header(self): return f_smaller( HGroup( _("Print Specification Demo"), HSpace(None), lcg.LocalizableDateTime(datetime.date.today()), ))
def localizable_export(value, **kwargs): """Try to convert a pytis value into a corresponding 'lcg.Localizable'. Arguemnts: value -- 'pytis.data.Value' instance to be converted. 'lcg.LocalizableDateTime' instances may be included in LCG element's export result and will be automatically formatted according to the target locale during LCG export. The function returns a string if the conversion is not possible (see below) or necessary (for null values). The conversion is applied only to base pytis.data.Date type and not to its descendants. The derived classes may customize the export and since we are replacing the type's export here, the customized export would be igored. Thus it is safer to limit special handling to direct pytis.data.Date instances here, althought it is unpleasant, that derived types are not localized automatically. """ if value.value() is not None: type_cls = value.type().__class__ if type_cls is pd.DateTime: return lcg.LocalizableDateTime( value.value().strftime('%Y-%m-%d %H:%M:%S'), utc=value.type().utc()) elif type_cls is pd.Date: return lcg.LocalizableDateTime(value.value().strftime('%Y-%m-%d')) elif type_cls is pd.Time: return lcg.LocalizableTime(value.value().strftime('%H:%M:%S')) elif type_cls is pd.Monetary: return lcg.Monetary(value.value(), precision=value.type().precision()) elif type_cls is pd.Float: return lcg.Decimal(value.value(), precision=value.type().precision()) elif type_cls is pd.Integer: return lcg.Decimal(value.value()) else: return value.export(**kwargs) else: return ''
def _content(self, record): par = os.path.pardir return pytis.util.lcg_node( ( lcg.fieldset(( (_("Price"), record['price'].export()), (_("Available since"), lcg.LocalizableDateTime(record['since'].value())), )), lcg.sec(_("Notes"), lcg.Parser().parse(record['notes'].value()), name='notes') if record['notes'].value() else lcg.Content(), ), title=record['product'].value(), resource_path=(os.path.normpath(os.path.join(__file__, par, par, par, par, 'css')),), resources=('pytis-demo-product.css',), )
def _localizable(self, value): # Note, matplotlib returns a datetime with UTC timezone, but we # want to avoid timezone conversion (or seeing the timezone on output # when export context timezone is not set). dt = matplotlib.dates.num2date(value).replace(tzinfo=None) return lcg.LocalizableDateTime(dt, **self._kwargs)
def page_header(self): return pytis.output.HGroup( self._row['product'].value(), pytis.output.HSpace(None), lcg.LocalizableDateTime(datetime.date.today()), )