election_day.models.mixins
Classes
| Defines the scope of a principal, an election, an election compound | |
| Mixin providing status indication for votes and elections. | |
| Adds a helper to return the translation of the title without depending | |
| Mixin providing created/modified timestamps for all records. | |
Functions
| 
 | Adds an attribute as hybrid_property which returns the sum of the | 
Module Contents
- class election_day.models.mixins.DomainOfInfluenceMixin[source]
- Defines the scope of a principal, an election, an election compound or a vote. - The following domains of influence are supported: - federation: The vote or election is nation wide. - canton: The vote or election takes place in one canton only. - region: The election takes place in one region of a canton only. - district: The election takes place in one district of a canton only. - municipality: The vote or election takes place in one municipality only. - none: The election takes place in certain municipalities only. 
- class election_day.models.mixins.StatusMixin[source]
- Mixin providing status indication for votes and elections. 
- class election_day.models.mixins.TitleTranslationsMixin[source]
- Adds a helper to return the translation of the title without depending on the locale of the request. 
- class election_day.models.mixins.IdFromTitlesMixin[source]
- election_day.models.mixins.summarized_property(name: str) sqlalchemy.Column[int][source]
- Adds an attribute as hybrid_property which returns the sum of the underlying results if called. - Requires the class to define two aggregation functions. - Usage: - class Model(): votes = summarized_property('votes') results = relationship('Result', ...) def aggregate_results(self, attribute): return sum(getattr(res, attribute) for res in self.results) @classmethod def aggregate_results_expression(cls, attribute): expr = select([func.sum(getattr(Result, attribute))]) expr = expr.where(Result.xxx_id == cls.id) expr = expr.label(attribute) return expr