class Role: """Role, allow to group some authorization for an user""" name = String(primary_key=True, nullable=False) label = String(nullable=False) children = Many2Many(model='Model.Pyramid.Role', many2many="parents") users = Many2Many(model=Pyramid.User, many2many="roles") roles_name = Function(fget="get_all_roles_name") def get_all_roles_name(self): """Return all the name of the roles self and dependencies """ names = [self.name] for child in self.children: if child.name in names: continue # pragma: no cover names.extend(child.roles_name) return list(set(names)) @classmethod def before_update_orm_event(cls, mapper, connection, target): """Check if the role has not any cyclical dependencies """ try: target.get_all_roles_name() except RecursionError: raise RecursionRoleError()
class Test2: id = Integer(primary_key=True) childs = Many2Many( model='Model.Test2', many2many='parents' )
class Person: name = String(primary_key=True) addresses = Many2Many(model=Model.Address, join_table="other_join_table", join_model=Model.PersonAddress, many2many="persons")
class Customer: id = Integer(primary_key=True) name = String(nullable=False) tags = Many2Many(model=Declarations.Model.Tag) def __repr__(self): return ('<Customer(name={self.name!r}, ' 'tags={self.tags!r})>').format(self=self)
class Test: id = Integer(primary_key=True) childs = Many2Many( model='Model.Test', m2m_remote_columns='id2', many2many='parents' )
class Test2: id = Integer(primary_key=True) test = Many2Many(model=Model.Test, join_table="join_test_and_test2", remote_columns=['id', 'id2'], m2m_remote_columns=['t2_id', 't2_id2'], local_columns='id', m2m_local_columns='t1_id', many2many="test2")
class Person: name = String(primary_key=True) addresses = Many2Many(model=Model.Address, join_table="personaddress", remote_columns="id", local_columns="name", m2m_remote_columns='a_id', m2m_local_columns='p_name', many2many="persons")
class Test: id = Integer(primary_key=True) childs = Many2Many( model='Model.Test', many2many='parents', join_table="testlink", m2m_remote_columns='t_right', )
class TestM2M2: idmodel2 = Int(primary_key=True) rel_m2m = Many2Many(label="Rel", model=Model.TestM2M1, join_table='reltable', remote_columns='idmodel1', m2m_remote_columns='idmodel1', local_columns='idmodel2', m2m_local_columns='idmodel2', many2many='rel_m2m_inv')
class Test: id = Integer(primary_key=True) childs = Many2Many( model='Model.Test', many2many='parents', join_model=Model.TestLink, m2m_local_columns='left_id', m2m_remote_columns='right_id', )
class Order(Mixin.TeamOwner): id = Integer(primary_key=True) name = String() customer = Many2One(model=Model.Customer, one2many="orders") tags = Many2Many( model=Model.Tag, join_table="join_order_tag", remote_columns="id", local_columns="id", m2m_remote_columns="tag_id", m2m_local_columns="order_id", many2many="orders", )
class Event: id = Integer(primary_key=True) name = String(nullable=False) guests = Many2Many( model=Model.Guest, join_model=Model.EventGuest, order_by="ModelEventGuest.position", collection_class=ordering_list("position"), ) def __repr__(self): return "<Event(name={self.name!r}, guests={self.guests!r})>".format( self=self)
class Person: name = String(primary_key=True) addresses = Many2Many( model=Model.Address, many2many=( "persons", dict( order_by="ModelPerson.name", collection_class=ordering_list("name"), ), ), order_by="ModelAddress.city", collection_class=ordering_list("city"), )
class Group(Model.REA.Entity): """ Introduce a group as a structural element of the REA application model. An REA entity group represents a set of REA entities that have something in common. The group entity is related to its members by a grouping rela- tionship. Members of the group can be any entity in the REA model: re- sources, events, agents, commitments, claims, contracts, types, or other groups. # Model-Driven Design Using Business Patterns # Authors: Hruby, Pavel # ISBN-10 3-540-30154-2 Springer Berlin Heidelberg New York # ISBN-13 978-3-540-30154-7 Springer Berlin Heidelberg New York """ id = Integer(primary_key=True, foreign_key=Model.REA.Entity.use('id')) name = String() entities = Many2Many(model=Model.REA.Entity)
class Test2: id = Integer(primary_key=True) tests = Many2Many(model=Model.Test, many2many="tests2")
class JourneyWish(Mixin.UuidColumn, Mixin.TrackModel, Mixin.WorkFlow): """This model has Model.JourneyWish as a namespace. It is intented for storing journey wishes that represents travels intentions. For instance, an intention may be caracterized by start date, with an a time frame delimited by earlier and latest departure times, departure and arrival stations, passengers, maximum price, etc... Implemented fields are the following : * Departure station : Many2One relationship with Model.Station * Arrival station : Many2One relationship with Model.Station * Start date : DateTime representing earlier time after which train may leave the departure station * End date : DateTime representing latest time after which train may leave departure station. * Passengers : Many2Many relationship to Model.Passenger * Transportation mean : String, containing type of transport required by user (train, coach, etc...) * Active : boolean that stores if wish has to be processed * Activation date : Date, represent the moment when the wish could start being processed""" user = Many2One( label="User", model=Model.User, nullable=False, one2many="wishes" ) departure = Many2One( label="Departure Station", model=Model.Station, nullable=True, one2many="departures", ) arrival = Many2One( label="Arrival Station", model=Model.Station, nullable=True, one2many="arrivals", ) from_date = DateTime(label="Earlier Departure Date", nullable=True) end_date = DateTime(label="Latest Departure Date", nullable=True) activation_date = Date(label="Activation Date", nullable=True) passengers = Many2Many( model=Model.Passenger, join_table="join_passengers_by_wishes", remote_columns="uuid", local_columns="uuid", m2m_remote_columns="p_uuid", m2m_local_columns="w_uuid", many2many="wishes", ) transportation_mean = String( label="Transportation Mean", default="any", nullable=True ) active = Boolean(label="Active Wish", nullable=True) @classmethod def get_workflow_definition(cls): """This method is aimed at defining workflow used for model Model.JourneyWish""" return { "draft": { "default": True, "allowed_to": ["running", "pending"], "apply_change": "deactivate", }, "running": { "allowed_to": ["cancelled", "expired"], "apply_change": "activate", }, "pending": { "allowed_to": ["cancelled", "expired", "running"], "apply_change": "deactivate", }, "expired": {"apply_change": "deactivate"}, "cancelled": {"apply_change": "deactivate"}, } def activate(self, from_state): if from_state == "draft" and not self.activation_date: self.activation_date = date.today() self.active = True def deactivate(self, from_state): self.active = False def check_state(self): """This method is aimed at being used in order to automatically set workflow state, depending on record attributes.""" if self.state == "pending": # If wish is pending, check is activation_date is set if self.activation_date and self.activation_date <= date.today(): self.state_to("running") elif self.state == "running": # If wish is already running, check that from_date is not in the # past try: now = datetime.now().astimezone() except ValueError: # Python3.5 and below do not support astimezone on 'naive' # dates provided by datetime.now() now = datetime.now(timezone.utc).astimezone() if self.from_date and self.from_date < now: self.state_to("expired")
class Person: name = String(primary_key=True) addresses = Many2Many(model='Model.Address')
class Person: name = String(primary_key=True) invoiced_addresses = Many2Many(model=Model.Address) delivery_addresses = Many2Many(model=Model.Address)
class MixinM2M: addresses = Many2Many(model=Model.Address)
class Person: name = String(primary_key=True) addresses = Many2Many(model=Model.Address, remote_columns="id2")
class Person: name = String(primary_key=True) addresses = Many2Many( m2m_remote_columns=['test_id'], model=Model.Address)
class Test2: id = Integer(primary_key=True) name = String() test = Many2Many(model=Model.Test, many2many='test2')
def test_forbid_many2one_with_many2many(self): with pytest.raises(FieldException): Contextual(field=Many2Many(model='Model.System.Blok'), identity='foo')
class Address: id = Integer(primary_key=True) persons = Many2Many( model=Model.Person, join_table='join_person_and_address_for_addresses')
class Test2: id = Integer(primary_key=True) id2 = String(primary_key=True) test = Many2Many(model=Model.Test, many2many="test2")
class Exemple2: id = Integer(primary_key=True) exemple = Many2Many(model='Model.Exemple', many2many='exemple2')