Пример #1
0
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()
Пример #2
0
            class Test2:

                id = Integer(primary_key=True)
                childs = Many2Many(
                    model='Model.Test2',
                    many2many='parents'
                )
Пример #3
0
            class Person:

                name = String(primary_key=True)
                addresses = Many2Many(model=Model.Address,
                                      join_table="other_join_table",
                                      join_model=Model.PersonAddress,
                                      many2many="persons")
Пример #4
0
    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)
Пример #5
0
            class Test:

                id = Integer(primary_key=True)
                childs = Many2Many(
                    model='Model.Test',
                    m2m_remote_columns='id2',
                    many2many='parents'
                )
Пример #6
0
 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")
Пример #7
0
            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")
Пример #8
0
            class Test:

                id = Integer(primary_key=True)
                childs = Many2Many(
                    model='Model.Test',
                    many2many='parents',
                    join_table="testlink",
                    m2m_remote_columns='t_right',
                )
Пример #9
0
 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')
Пример #10
0
            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',
                )
Пример #11
0
 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"),
    )
Пример #14
0
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)
Пример #15
0
 class Test2:
     id = Integer(primary_key=True)
     tests = Many2Many(model=Model.Test, many2many="tests2")
Пример #16
0
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")
Пример #17
0
    class Person:

        name = String(primary_key=True)
        addresses = Many2Many(model='Model.Address')
Пример #18
0
            class Person:

                name = String(primary_key=True)
                invoiced_addresses = Many2Many(model=Model.Address)
                delivery_addresses = Many2Many(model=Model.Address)
Пример #19
0
 class MixinM2M:
     addresses = Many2Many(model=Model.Address)
Пример #20
0
    class Person:

        name = String(primary_key=True)
        addresses = Many2Many(model=Model.Address, remote_columns="id2")
Пример #21
0
            class Person:

                name = String(primary_key=True)
                addresses = Many2Many(
                    m2m_remote_columns=['test_id'],
                    model=Model.Address)
Пример #22
0
 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')
Пример #24
0
    class Address:

        id = Integer(primary_key=True)
        persons = Many2Many(
            model=Model.Person,
            join_table='join_person_and_address_for_addresses')
Пример #25
0
 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')