def delete(self): titles = request.POST.getall('title') pages = self.page_q.filter(Page.title.in_(titles)) for page in pages: Session.delete(page) Session.commit() for title in titles: flash('Deleted %s.' %title) redirect_to('pages')
def save(self, title): page = self.page_q.filter_by(title=title).first() if not page: page = Page(title) page.content = escape(request.POST.getone('content')) Session.add(page) Session.commit() flash('Successfully saved %s!' % title) redirect_to('show_page', title=title)
def save(self, title): c.title = title page = self.page_q.filter_by(title=title).first() if not page: page = Page(title=title) # In a real application, you should validate and sanitize # submitted data throughly! escape is a minimal example here page.content = escape(request.POST.getone('content')) Session.add(page) Session.commit() flash('Successfully saved %s!' % title) redirect(url('show_page', title=title))
def setup_app(command, conf, vars): """Place any commands to setup {{package}} here""" # Don't reload the app if it was loaded under the testing environment if not pylons.test.pylonsapp: load_environment(conf.global_conf, conf.local_conf) # Create the tables if they don't already exist log.info("Creating tables...") Base.metadata.create_all(bind=Session.bind) log.info("Successfully set up.") log.info("Adding front page data...") page = model.Page(title=u'FrontPage', content=u'**Welcome** to the QuickWiki front page!') Session.add(page) Session.commit() log.info("Successfully set up.")
def init_model(engine): """Call me before using any of the tables or classes in the model""" Session.configure(bind=engine)
def __before__(self): self.page_q = Session.query(Page)
def __before__(self): if request.environ.get('repoze.who.identity') == None: abort(401) self.page_q = Session.query(Page)