Core modules¶
ex – exception definitions¶
Exception classes used in summer framework. Some are suitable for inheritance.
-
exception
summer.ex.
ApplicationException
(message: str = None, **kwargs)[source]¶ Bases:
Exception
Base class for exceptions. Suited for custom subclassing.
-
__init__
(message: str = None, **kwargs)[source]¶ Creates
ApplicationException
instance.Parameters: - message (str) – message to be printed
- kwargs – keyword arguments are printed as are, suitable for providing some context (current values of important variables and such.
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
exception
summer.ex.
SummerException
(message: str = None, **kwargs)[source]¶ Bases:
summer.ex.ApplicationException
Base summer framework exception.
-
exception
summer.ex.
SummerConfigurationException
(message: str = None, **kwargs)[source]¶ Bases:
summer.ex.SummerException
Raised when summer configuration is broken.
-
exception
summer.ex.
NoObjectFoundException
(message: str = None, **kwargs)[source]¶ Bases:
summer.ex.SummerException
Raised when required object is not found in context.
domain – domain model¶
Basic support for domain classes, including persistent domain classes.
-
class
summer.domain.
Domain
[source]¶ Bases:
summer.utils.Printable
Suitable class for generic domain objects.
-
class
summer.domain.
Filter
(page: int = 1, max_results: int = -1)[source]¶ Bases:
summer.domain.Domain
Base class for filters – ie. classes that support paging through a collection. Used for example in
summer.dao.EntityDao.find()
page
sets the page of the result set, starting at 1 (ie. first page)max_results
sets the page limit (entities per page)
Use
Filter.get_offset()
to obtain the first record of the result set. UseFilter.get_max_results()
to obtain the last record of the result set.-
__init__
(page: int = 1, max_results: int = -1)[source]¶ Parameters: - page (int) – page in collection
- max_results (int) –
-
static
get_default
()[source]¶ Returns: default filter instance, set for single page without limit per page (will show all the results) Return type: Filter
-
get_offset
() → int[source]¶ Computes the order of the first record, ie. the offset.
Returns: offset Return type: int
-
class
summer.domain.
Entity
[source]¶ Bases:
summer.domain.Domain
Suitable base class for SqlAlchemy persistent classes; defines the integer
id
attribute.
-
class
summer.domain.
CodeEntity
[source]¶ Bases:
summer.domain.Entity
Suitable base class for SqlAlchemy persistent classes that have a unique string code attribute (ie. usually catalogs). This
code
attribute should be considered as a string representation of an object, its natural id, not necessarily human friendly value.
context – summer object container¶
Module context
defines an application context (Context
class)– a container for (business) objects, that should be available
throughout the application, application layer or module.
-
class
summer.context.
Context
(session_provider: summer.sf.SessionProvider = None, ldap_connection_provider: summer.lsf.LdapConnectionProvider = None, l10n: summer.l10n.Localization = None)[source]¶ Bases:
object
Context is intelligent container for your business objects, it is a core of summer framework.
It is responsible for:
- summer framework initialization
- instantiating your business classes with their interdependencies
- aop configuration
Emulates mapping type, so you can access business objects by their name if required.
Usually in medium sized applications, you define single global context somewhere in main entry point of your program. Preferred approach is to define top level module attribute, see accompanying examples.
Initialization of context is thread safe.
-
__init__
(session_provider: summer.sf.SessionProvider = None, ldap_connection_provider: summer.lsf.LdapConnectionProvider = None, l10n: summer.l10n.Localization = None)[source]¶ Creates and initializes context instance. See
init()
for more information.Parameters: - path_to_module (str) – path to module, usually pass
__file__
built-in. It will look for config files up to several directories levels up. - customcfg (str) – name of custom config file
- summercfg (str) – name of summer config file
- path_to_module (str) – path to module, usually pass
-
__del__
()[source]¶ Calls
shutdown()
to properly shutdown the context.
-
session_factory
¶ Each context may have up to one instance of session factory – access to your database connections.
Returns: session factory instance. Return type: sf.SessionFactory
-
ldap_session_factory
¶ Each context may have up to one instance of LDAP session factory – access to your LDAP connections.
Returns: LDAP session factory instance. Return type: lsf.LdapSessionFactory
-
l10n
¶ Each context may have up to one instance of
l10n.Localization
. You usually do not need to access it.Returns: localization instance. Return type: l10n.Localization
-
init
()[source]¶ Main context initialization method.
Context initialization is executed from constructor; it is separated into several steps:
- call
core_init()
(not indended to be overriden) which parses config files and creates core objects managing key resources (sql database, ldap server, localization) - call
orm_init()
(intended to be overriden) which initializes ORM - call
context_init()
(intended to be overriden) – a place to define your business beans
- call
-
orm_init
()[source]¶ Should be overriden by subclasses to initialize ORM managed tables and class mappings.
You should define your custom table definitions based on
summer.sf.AbstractTableDefinitions
and mappings based onsummer.sf.AbstractClassMappings
.Usually you have just those lines there:
self.session_factory.table_definitions = MyTableDefinitions() self.session_factory.set_class_mappings = MyClassMappings()
-
context_init
()[source]¶ Should be overriden by subclasses to initialize custom objects in context.
This is the last stage of context initialization, this method gets called after
are called. You can safely access those properties:
session_factory
–summer.sf.SessionFactory
instance, which provides thread-safe access tosqlalchemy.session
– any data aware object (ie. each DAO at least) should probably have access to it – at least those derived fromdao.Dao
reference it.ldap_session_factory
summer.lsf.LdapSessionFactory
instance, which provides thread-safe access tosummer.lsf.LdapSessionFactory.Local
instance – a simple wrapper around actualldap3.Connection
l10n
–summer.l10n.Localization
instance, not very interesting in itself, but summer’s localization module installs the famous_()
gettext function into global namespace (as normal gettext module does) and configures your localization based on whatever you have provided
-
__weakref__
¶ list of weak references to the object (if defined)
l10n – localization¶
Based on Python’s gettext
module.
-
class
summer.l10n.
Localization
(domain: str, l10n_dir: str, languages: list)[source]¶ Bases:
object
Provides localization (l10n) services.
If instance is provided to
summer.context.Context
, context will load all the defined languages and will installgettext._()
function into global namespace.-
__init__
(domain: str, l10n_dir: str, languages: list)[source]¶ Creates
Localization
instance.Parameters: - domain – gettext domain
- l10n_dir – directory path for gettext compiled data
- languages – list of supported languages
-
__weakref__
¶ list of weak references to the object (if defined)
-