Exemplo n.º 1
0
    def get(cls, text):
        """
        Get an object from the cache or the database using the key `text`.
        If the object doesn't exists, it'll be stores in the cache and in
        the database.
        """
        cls.check(text)

        if cls.fk_cache.has_key(text):
            return cls.fk_cache[text]

        query = DBSession.query(cls)
        query._autoflush = False
        try:
            data = query.filter(cls.text == text).one()
        except NoResultFound:
            data = cls()
            data.text = text
            DBSession.add(data)

        cls.fk_cache[text] = data

        return data
Exemplo n.º 2
0
 def by_email_address(cls, email):
     """Return the user object whose email address is ``email``."""
     return DBSession.query(cls).filter_by(email_address=email).first()
Exemplo n.º 3
0
 def by_user_name(cls, username):
     """Return the user object whose user name is ``username``."""
     return DBSession.query(cls).filter_by(user_name=username).first()
Exemplo n.º 4
0
 def test_query_obj(self):
     """Model objects can be queried"""
     obj = DBSession.query(self.klass).one()
     for key, value in self.attrs.iteritems():
         assert_equals(getattr(obj, key), value)