def getPage(self, pagename): from sqlalchemy.exc import InvalidRequestError try: page = DBSession.query(Page).filter_by(pagename=pagename).one() return page except InvalidRequestError: raise redirect("notfound", pagename=pagename)
def save(self, pagename, title, data, author, tags): page = Page() page.pagename = pagename page.title = title page.data = data page.date = time.strftime("%c") page.author = DBSession.query(User).filter_by(user_name=author).first().user_id page.tags = tags return page
def setUp(self): """Setup test fixture for each model test method.""" try: new_attrs = {} new_attrs.update(self.attrs) new_attrs.update(self.do_get_dependencies()) self.obj = self.klass(**new_attrs) DBSession.add(self.obj) DBSession.flush() return self.obj except: DBSession.rollback() raise
def getAuthor(self): username = str(DBSession.query(User).filter_by(user_id=self.author).one().display_name) return username
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()
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()
def searchPages(self, tag): pages = DBSession.query(Page).filter(Page.tags.contains(tag)).order_by(asc(Page.date)) return pages
def getAllPages(self): pages = DBSession.query(Page).order_by(desc(Page.date)) return pages
def getAllNamePages(self): pages = [page.pagename for page in DBSession.query(Page).order_by(asc(Page.date))] return pages
def notfound(self, pagename): page = Page(pagename=pagename, data="") DBSession.add(page) return dict(wikipage=page)
def save(self, pagename, data, title, submit): page = DBSession.query(Page).filter_by(pagename=pagename).one() page.data = data page.title = title page.date = time.strftime("%c") redirect("/page/" + pagename)
def save_new(self, pagename, title, data, tags,submit): author = request.identity['repoze.who.userid'] pagename = title.replace(' ','') page = pageController.save(pagename, title, data, author, tags) DBSession.add(page) redirect("/page/" + pagename)
def test_query_obj(self): """Model objects can be queried""" obj = DBSession.query(self.klass).one() for key, value in self.attrs.items(): eq_(getattr(obj, key), value)
def tearDown(self): """Tear down test fixture for each model test method.""" DBSession.rollback()