Skip to content

Instantly share code, notes, and snippets.

@amcgregor
Created February 18, 2010 20:48
Show Gist options
  • Save amcgregor/308050 to your computer and use it in GitHub Desktop.
Save amcgregor/308050 to your computer and use it in GitHub Desktop.
The Article controller from the WebCore Wiki example.
class Article(web.core.RESTMethod):
def __init__(self, name):
self.name = name
self.record = db.session.query(db.Article).get(name)
super(Article, self).__init__()
def get(self, raw=False):
record = self.record
if raw:
web.core.response.content_type = 'text/x-web-textile'
return record.content if record else ""
return 'megawiki.templates.wiki', dict(
name = self.name,
record = record,
content = record.rendered if record else "<i>No content.</i>"
)
def post(self, content):
if not self.record:
self.record = db.Article(name=self.name)
db.session.add(self.record)
self.record.content = content
self.record.modified = datetime.datetime.now()
return self.record.rendered
def delete(self):
if not self.record:
raise web.core.http.HTTPSeeOther(location='/')
db.session.delete(self.record)
raise web.core.http.HTTPSeeOther(location='/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment