Beispiel #1
0
    def _get_item_as_row(self, item_name):
        """
        Return the SQLAlchemy row for the item called ``item_name``.

        When dealing with a group source, the item is a user. And when dealing
        with a permission source, the item is a group.

        """
        # "field" usually equals to {tg_package}.model.User.user_name
        # or {tg_package}.model.Group.group_name
        field = getattr(self.children_class, self.translations['item_name'])

        # Eagerload the sections, unless they are dynamically computed by a
        # property on the "self.children_class":
        query = self.dbsession.query(self.children_class)
        try:
            query = query.options(eagerload(self.translations['sections']))
        except InvalidRequestError:
            pass

        try:
            item_as_row = query.filter(field == item_name).one()
        except NoResultFound:
            msg = 'Item (%s) "%s" does not exist in the child table'
            msg = msg % (self.translations['item_name'], item_name)
            raise SourceError(msg)
        return item_as_row
 def _get_item_as_row(self, item_name):
     q = model.meta.Session.query(model.User)
     q = q.filter(model.User.user_name == unicode(item_name))
     q = q.options(eagerload(model.User.memberships))
     try:
         return q.one()
     except NoResultFound, e:
         log.exception(e)
         raise SourceError("No such user: %s" % item_name)
Beispiel #3
0
    def _get_section_as_row(self, section_name):
        """
        Return the SQLAlchemy row for the section called ``section_name``.

        When dealing with a group source, the section is a group. And when
        dealing with a permission source, the section is a permission.

        """
        # "field" usually equals to {tg_package}.model.Group.group_name
        # or {tg_package}.model.Permission.permission_name
        field = getattr(self.parent_class, self.translations['section_name'])
        query = self.dbsession.query(self.parent_class)
        try:
            section_as_row = query.filter(field == section_name).one()
        except NoResultFound:
            msg = 'Section (%s) "%s" is not defined in the parent table'
            msg = msg % (self.translations['section_name'], section_name)
            raise SourceError(msg)
        return section_as_row
Beispiel #4
0
    def _get_item_as_row(self, item_name):
        """
        Return the SQLAlchemy row for the item called ``item_name``.

        When dealing with a group source, the item is a user. And when dealing
        with a permission source, the item is a group.

        """
        # "field" usually equals to {tg_package}.model.User.user_name
        # or {tg_package}.model.Group.group_name
        field = getattr(self.children_class, self.translations['item_name'])
        query = self.dbsession.query(self.children_class)
        try:
            item_as_row = query.filter(field == item_name).one()
        except NoResultFound:
            msg = 'Item (%s) "%s" does not exist in the child table'
            msg = msg % (self.translations['item_name'], item_name)
            raise SourceError(msg)
        return item_as_row
Beispiel #5
0
 def _include_items(self, section, items):
     raise SourceError('For including items you must edit the '
                       'INI file directly.')
Beispiel #6
0
 def _find_sections(self, hint):
     raise SourceError('This is implemented in the groups and '
                       'permissions adapters.')