Beispiel #1
0
 def delete(self):
     session = DBSession()
     newsid = self.request.matchdict.get('newsid')
     newsitem = session.query(News).filter_by(news_id=newsid).one()
     if 'form.submitted' in self.request.params:
         session = DBSession()
         newsitem = session.query(News).filter_by(news_id=newsid)
         newsitem.delete()
         session.flush()
         return HTTPFound(location=self.request.route_url('newslist', message="Newsitem %s has been deleted" % newsid))
     delete_url = self.request.route_url('news_delete', newsid=newsid)
     return dict(news=newsitem, delete_url=delete_url)
Beispiel #2
0
 def add(self):
     if 'form.submitted' in self.request.params:
         session = DBSession()
         title = self.request.params['title']
         body = self.request.params['body']
         news = News(title, body)
         session.add(news)
         session.flush()
         return HTTPFound(location=self.request.route_url('newsdetail', newsid=news.news_id))
         
     save_url = self.request.route_url('news_add')
     news = News('', '')
     return dict(news=news, save_url=save_url)
Beispiel #3
0
    def edit(self):
        session = DBSession()
        newsid = self.request.matchdict.get('newsid')
        news = session.query(News).filter_by(news_id=newsid).one()
        if 'form.submitted' in self.request.params:
            title = self.request.params['title']
            body = self.request.params['body']
            news.title = title
            news.body = body
            session.add(news)
            session.flush()
            return HTTPFound(location=self.request.route_url('newsdetail', newsid=news.news_id))

        save_url = self.request.route_url('newsedit', newsid=news.news_id)
        return dict(news=news, save_url=save_url)