Ejemplo n.º 1
0
        def filter_by_meta(self, field, value):
            """Search the metadata.

            It will be always searched from the root (you don't need to add [root]).

            :param field: - The field to search on (e.g sparq.ticketware.user_id)
            :param value: - The value to search for. It will be converted to string.
            """
            from paylogic.core.metadata import Object, Field, Value

            if not field.startswith('[root]'):
                field = '[root].' + field

            value = str(value)
            owner = self._mapper_adapter_map.keys()[0]
            query = (self.join((Value, Value.instance_id == owner.id)).join(
                (Object,
                 Object.path == '.'.join([owner.__module__, owner.__name__]))))
            query = query.filter(Value.value == value)

            prev = None
            for name in field.split('.'):
                f = aliased(Field)
                cond = f.obj_id == Object.id
                if prev is not None:
                    cond = and_(cond, f.parent_id == prev.id)
                query = query.join((f, cond)).filter(f.name == name)
                prev = f

            query = query.filter(Value.field_id == f.id)

            return query
Ejemplo n.º 2
0
    def _target_simulation(self, query, sim):
        """Only return those hops which reach the specified simulation"""
        query = query.join(self._link_orm_class.halo_to).join(
            core.SimulationObjectBase.timestep).filter(
                core.timestep.TimeStep.simulation_id == sim.id)

        return query
Ejemplo n.º 3
0
        def filter(self, owner, field, value):
            """Search the metadata. It returns a query on the owner class.

            :param owner: - The owner class model (e.g Order)
            :param field: - The field to search on (e.g sparq.ticketware.user_id)
            :param value: - The value to search for
            :param operator: - The operator to apply to the field and value. Optional; defaults to equality.
            """
            if not field.startswith('[root]'):
                field = '.'.join(['[root]', field])
            value_alias = aliased(Value)
            session = inspect(owner).session
            query = (session.query(owner.__class__).join(
                (value_alias,
                 value_alias.instance_id == get_object_id(owner))).join(
                     (Object, Object.path == format('.'.join(
                         [owner.__module__, owner.__name__])))))
            query = query.filter(Value.value == value)
            parents = field.split('.')

            prev = None
            for parent_name in parents:
                f = aliased(Field)
                cond = f.obj_id == Object.id
                if prev is not None:
                    cond = and_(cond, f.parent_id == prev.id)
                query = query.join((f, cond)).filter(f.name == parent_name)
                prev = f
            query = query.filter(value_alias.field_id == f.id)

            return query
Ejemplo n.º 4
0
    def _create_layer_query(self,
                            interface: str) -> sqlalchemy.orm.query.Query:
        """
        Create an SQLAlchemy query for Layer and for the role
        identified to by ``role_id``.
        """

        query = models.DBSession.query(main.Layer.name).filter(
            main.Layer.public.is_(True))

        if interface is not None:
            query = query.join(main.Layer.interfaces)
            query = query.filter(main.Interface.name == interface)

        query2 = get_protected_layers_query(self.request,
                                            None,
                                            what=main.LayerWMS.name)
        if interface is not None:
            query2 = query2.join(main.Layer.interfaces)
            query2 = query2.filter(main.Interface.name == interface)
        query = query.union(query2)
        query3 = get_protected_layers_query(self.request,
                                            None,
                                            what=main.LayerWMTS.name)
        if interface is not None:
            query3 = query3.join(main.Layer.interfaces)
            query3 = query3.filter(main.Interface.name == interface)
        query = query.union(query3)

        return query
Ejemplo n.º 5
0
    def _target_timestep(self, query, ts):
        """Only return those hops which reach the specified timestep"""
        if ts is None:
            query = query.filter(0 == 1)
        else:
            query = query.join(self._link_orm_class.halo_to).filter(
                core.halo.SimulationObjectBase.timestep_id == ts.id)

        return query
Ejemplo n.º 6
0
 def _order_query(self, query):
     assert isinstance(query, sqlalchemy.orm.query.Query)
     timestep_alias = None
     halo_alias = None
     if self._ordering_requires_join():
         timestep_alias = sqlalchemy.orm.aliased(core.timestep.TimeStep)
         halo_alias = sqlalchemy.orm.aliased(core.halo.SimulationObjectBase)
         query = query.join(halo_alias, self._link_orm_class.halo_to_id == halo_alias.id)\
             .join(timestep_alias)\
             .options(
               contains_eager(self._link_orm_class.halo_to.of_type(halo_alias))\
               .contains_eager(halo_alias.timestep.of_type(timestep_alias))
         )
     query = query.order_by(
         *self._order_by_clause(halo_alias, timestep_alias))
     return query
Ejemplo n.º 7
0
 def _query_ordered(self):
     query = self.query
     assert isinstance(query, sqlalchemy.orm.query.Query)
     timestep_alias = None
     halo_alias = None
     if self._ordering_requires_join():
         timestep_alias = sqlalchemy.orm.aliased(core.timestep.TimeStep)
         halo_alias = sqlalchemy.orm.aliased(core.halo.Halo)
         query = query.join(
             halo_alias, self._link_orm_class.halo_to).join(timestep_alias)
         query = query.options(contains_eager("halo_to", alias=halo_alias))
         query = query.options(
             contains_eager("halo_to", "timestep", alias=timestep_alias))
     query = query.order_by(
         *self._order_by_clause(halo_alias, timestep_alias))
     return query