QuickWiki / quickwiki / model / __init__.py

import re
import sets

from docutils.core import publish_parts
from pylons import config
from sqlalchemy import Column, MetaData, Table, types
from sqlalchemy.orm import mapper
from sqlalchemy.orm import scoped_session, sessionmaker

import quickwiki.lib.helpers as h

# Global session manager for SQLAlchemy. Session() returns the session
# object appropriate for the current web request.
Session = scoped_session(sessionmaker(autoflush=True, transactional=True,
                                      bind=config['pylons.g'].sa_engine))

# Global metadata. If you have multiple databases with overlapping
# table names, you'll need a metadata for each database.
metadata = MetaData()

wikiwords = re.compile(r"\b([A-Z]\w+[A-Z]+\w+)")

pages_table = Table('pages', metadata,
    Column('title', types.String(40), primary_key=True),
    Column('content', types.String(), default='')
)

class Page(object):
    content = None

    def __str__(self):
        return self.title

    def get_wiki_content(self):
        content = publish_parts(self.content, writer_name="html")["html_body"]
        titles = sets.Set(wikiwords.findall(content))
        for title in titles:
            title_url = h.url_for(controller='page', action='index',
                                  title=title)
            content = content.replace(title, h.link_to(title, title_url))
        return content

mapper(Page, pages_table)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.