Package: horae.core
IntroductionThehorae.corepackage provides several core functionality used by thehorae.*packages which there are:Formatters for:PricesSizesDates and timesHoursGlobal configuration defining:Title and description of the applicationWork daysThe currencyGeneric interfaces for objects having a textual or integer IDUtility managing integer IDsUtility creating textual IDsBase implementation of a container holding objects having a textual
or integer IDUsageFormattersPricesThe price formatter formats the given value using the current locale and adds
the configured currency. The formatter is registered as an adapter implementinghorae.core.interfaces.ICurrencyFormatterand adapting anycontextand
therequest. The following example shows the usage of the formatter in a
view:import grok
from zope.component import getMultiAdapter

from horae.core import interfaces

class SampleView(grok.View):

    def currency_formatted_price(self):
        formatter = getMultiAdapter((self.context, self.request),
                                    interface=interfaces.ICurrencyFormatter)
        return formatter.format(1050.25)SizesThe size formatter formats the given value (in bytes) as a number appending the
appropriate unit (B, KB, MB, GB). The formatter is registered as an adapter
implementinghorae.core.interfaces.ISizeFormatterand adapting therequest.
The following example shows the usage of the formatter in a view:class SampleView(grok.View):

    def size_formatted_price(self):
        return interfaces.ISizeFormatter(self.request).format(2048)Dates and timesThe date and time formatters are simple functions part of thehorae.core.utilsmodule. There are two functions available:formatDateTime(value, request,format=('dateTime','short'),html=True)Formats the datetimevalueusing the locale provided by therequestand theformatprovided. HTML output may be disabled by thehtmlargument.formatDateTimeRange(start, end, request,format=('dateTime','short'),html=True)Formats the datetime range (start,end) using the locale provided
by therequestand theformatprovided. HTML output may be disabled
by thehtmlargument.HoursAs with the date and time formatters the hours formatter is a simple function of thehorae.core.utilsmodule:formatHours(value, request)Formats thevalueas a decimal using the locale provided by therequest.IDs and base container implementationhorae.coredefines two interfaces for objects having an ID:horae.core.interfaces.ITextIdAn object having a text IDhorae.core.interfaces.IIntIdAn object having an integer IDText IDs may be generated by the text ID manager which is a global utility implementinghorae.core.interfaces.ITextIdManager. The utility has two methods:normalize(name)Returns a normalized string usable in URLs based on thenameprovidedidFromName(container, name)Returns a valid ID for a new object to be added to thecontainerfrom thenameprovidedInteger IDs are managed by the int ID manager which is a local utility implementinghorae.core.interfaces.IIntIdManager. The utility provides a method to get the next
ID for a given key:nextId(self, key)Returns the next ID for the givenkeyContainerThe base container implementation resides in thehorae.core.containermodule and
consists of aContainerclass implementinghorae.core.interfaces.IContainer.
The container is mainly there to simplify the process of adding new objects implementing
one of the aforementioned ID interfaces. Theadd_object(obj)method checks if the
given object has an attribute namedidand whether it isNone. If no ID is available
one is generated. If the object implementshorae.core.interfaces.ITextIdthe ID is
generated by using the text ID manager otherwise by the int ID manager. A simple usage
would look like this:import grok

from horae.core import interfaces, container

class SampleContainer(container):

    def id_key(self):
        return 'sample_key'

class SampleIntIdContent(grok.Model):
    grok.implements(interfaces.IIntId)

class SampleTextIdContent(grok.Model):
    grok.implements(interfaces.ITextId)An example usage of the above sample classes would look like this:>>> container = SampleContainer()
>>> intcontent1 = SampleIntIdContent()
>>> container.add_object(intcontent1)
1
>>> intcontent1.id
1
>>> intcontent2 = SampleIntIdContent()
>>> container.add_object(intcontent2)
2
>>> intcontent2.id
2
>>> textcontent1 = SampleTextContent()
>>> textcontent1.name = u'Test name of the content'
>>> container.add_object(textcontent1)
'test_name_of_the_content'
>>> textcontent1.id
'test_name_of_the_content'
>>> textcontent2 = SampleTextContent()
>>> textcontent2.name = u'Test name of the content'
>>> container.add_object(textcontent2)
'test_name_of_the_content-2'
>>> textcontent2.id
'test_name_of_the_content-2'DependenciesHoraehorae.cacheThird partygrokzope.app.localesz3c.taskqueueChangelog1.0a1 (2012-01-16)Initial release