From: Mike Bayer Date: Wed, 21 Sep 2005 02:15:03 +0000 (+0000) Subject: (no commit message) X-Git-Tag: rel_0_1_0~654 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d2593122052446cd71fe300d2ee4a2e2173db5a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git --- diff --git a/doc/build/components/formatting.myt b/doc/build/components/formatting.myt index 9fe39286b7..4be0c12cc5 100644 --- a/doc/build/components/formatting.myt +++ b/doc/build/components/formatting.myt @@ -104,25 +104,37 @@
<%python> - regexp = re.compile(r"__FORMAT:LINK{(.*?)(?:\|(.*?))?(?:\@text=(.+?))?}") + regexp = re.compile(r"__FORMAT:LINK{(?:\@path=(.+?))?(?:\@xtra=(.+?))?(?:\@text=(.+?))?(?:\@href=(.+?))?(?:\@class=(.+?))?}") def link(matchobj): path = matchobj.group(1) - text = matchobj.group(3) xtra = matchobj.group(2) - - try: - element = item.lookup(path) - if xtra is not None: - return '%s' % (element.get_link(includefile), xtra, text or xtra) - else: - return '%s' % (element.get_link(includefile), text or element.description) - except KeyError: - if xtra is not None: - return '%s' % (text or xtra) - else: - return '%s' % text or path + text = matchobj.group(3) + href = matchobj.group(4) + class_ = matchobj.group(5) - m.write(regexp.sub(link, item.content)) + if class_ is not None: + class_ = 'class="%s"' % class_ + + if href: + return '%s' % (href, class_, text or href) + else: + try: + element = item.lookup(path) + if xtra is not None: + return '%s' % (element.get_link(includefile), xtra, class_, text or xtra) + else: + return '%s' % (element.get_link(includefile), class_, text or element.description) + except KeyError: + if xtra is not None: + return '%s' % (text or xtra) + else: + return '%s' % text or path + + re2 = re.compile(r"'''PYESC(.+?)PYESC'''", re.S) + content = regexp.sub(link, item.content) + content = re2.sub(lambda m: m.group(1), content) + #m.write(item.content) + m.write(content)
@@ -286,8 +298,6 @@ <% m.content() %> - - <%method codeline trim="both"> <% m.content() %> @@ -330,7 +340,6 @@
<% content %>
- <%method link trim="both"> <%args> path = None @@ -338,35 +347,16 @@ method = None member = None text = None + href = None + class_ = None <%init> - if path is None: + if href is None and path is None: path = m.comp('doclib.myt:current').path extra = (param or method or member) -__FORMAT:LINK{<%path%><% extra and "|" + extra or "" %><% text and "@text=" + text or "" %>} - - - -<%method uniqueblock> -<%args> - blockname - uniquename - - -<%init> - context = m.attributes.setdefault('ubcontext', {}) - try: - writer = context[blockname] - except KeyError: - context[blockname] = uniquename - writer = uniquename - - -% if writer == uniquename: - <% m.content() %> -% +__FORMAT:LINK{<% path and "@path=" + path or "" %><% extra and "@xtra=" + extra or "" %><% text and "@text=" + text or "" %><% href and "@href=" + href or "" %><% class_ and "@class=" + class_ or "" %>} <%method popboxlink trim="both"> @@ -378,47 +368,32 @@ __FORMAT:LINK{<%path%><% extra and "|" + extra or "" %><% text and "@text=" + te <%init> if name is None: name = m.attributes.setdefault('popbox_name', 0) - m.attributes['popbox_name'] += 1 + name += 1 + m.attributes['popbox_name'] = name name = "popbox_" + repr(name) -javascript:togglePopbox('<% name %>', show, hide) +javascript:togglePopbox('<% name %>', '<% show %>', '<% hide %>') -<%method popbox> + +<%method popbox trim="both"> <%args> name = None + class_ = None <%init> if name is None: name = 'popbox_' + repr(m.attributes['popbox_name']) -<&| SELF:uniqueblock, blockname='popboxscript', uniquename=name &> - - -
<% m.content() %>
+ -<%method codepopper> +<%method codepopper trim="both"> <%args> link - link - <&|SELF:popbox&><% m.content() %> + <%init> + href = m.scomp('SELF:popboxlink') + + '''PYESC<& SELF:link, href=href, text=link, class_="codepoplink" &>PYESC''' + '''PYESC<&|SELF:popbox, class_="codepop" &><% m.content() %>PYESC''' \ No newline at end of file diff --git a/test/rundocs.py b/test/rundocs.py new file mode 100644 index 0000000000..0db9cdce41 --- /dev/null +++ b/test/rundocs.py @@ -0,0 +1,133 @@ +from sqlalchemy.schema import * +from sqlalchemy.mapper import * +import sqlalchemy.databases.sqlite as sqlite +engine = sqlite.engine(':memory:', {}) + +engine.echo = True + +# table metadata +users = Table('users', engine, + Column('user_id', INTEGER, primary_key = True), + Column('user_name', VARCHAR(16), nullable = False), + Column('password', VARCHAR(20), nullable = False) +) +users.build() +users.insert().execute( + dict(user_name = 'fred', password='45nfss') +) + + +# class definition +class User(object): + def __init__(self): + pass + +# obtain a Mapper +m = mapper(User, users) + +# select +user = m.select(users.c.user_name == 'fred')[0] + + +# modify +user.user_name = 'fred jones' + +# commit +objectstore.commit() + +objectstore.clear() + +addresses = Table('email_addresses', engine, + Column('address_id', INT, primary_key = True), + Column('user_id', INT, foreign_key = ForeignKey(users.c.user_id)), + Column('email_address', VARCHAR(20)), +) +addresses.build() +addresses.insert().execute( + dict(user_id = user.user_id, email_address='fred@bar.com') +) + +# second class definition +class Address(object): + def __init__(self, email_address = None): + self.email_address = email_address + +# obtain a Mapper. "private=True" means deletions of the user +# will cascade down to the child Address objects +m = mapper(User, users, properties = dict( + addresses = relation(Address, addresses, lazy=True, private=True) +)) + +# select +user = m.select(users.c.user_name == 'fred jones')[0] +print repr(user.__dict__['addresses']) +address = user.addresses[0] + +# modify +user.user_name = 'fred' +user.addresses[0].email_address = 'fredjones@foo.com' +user.addresses.append(Address('freddy@hi.org')) + +# commit +objectstore.commit() + +# going to change tables, etc., start over with a new engine +objectstore.clear() +engine = None +engine = sqlite.engine(':memory:', {}) +engine.echo = True + +# a table to store a user's preferences for a site +prefs = Table('user_prefs', engine, + Column('pref_id', INT, primary_key = True), + Column('stylename', VARCHAR(20)), + Column('save_password', BOOLEAN, nullable = False), + Column('timezone', CHAR(3), nullable = False) +) +prefs.build() +prefs.insert().execute( + dict(pref_id=1, stylename='green', save_password=1, timezone='EST') +) + +# user table gets 'preference_id' column added +users = Table('users', engine, + Column('user_id', INTEGER, primary_key = True), + Column('user_name', VARCHAR(16), nullable = False), + Column('password', VARCHAR(20), nullable = False), + Column('preference_id', INTEGER, foreign_key = ForeignKey(prefs.c.pref_id)) +) +users.drop() +users.build() +users.insert().execute( + dict(user_name = 'fred', password='45nfss', preference_id=1) +) + + +addresses = Table('email_addresses', engine, + Column('address_id', INT, primary_key = True), + Column('user_id', INT, foreign_key = ForeignKey(users.c.user_id)), + Column('email_address', VARCHAR(20)), +) +addresses.drop() +addresses.build() + +# class definition for preferences +class UserPrefs(object): + pass + +# obtain a Mapper. +m = mapper(User, users, properties = dict( + addresses = relation(Address, addresses, lazy=True, private=True), + preferences = relation(UserPrefs, prefs, lazy=False, private=True), +)) + +# select +user = m.select(users.c.user_name == 'fred')[0] +save_password = user.preferences.save_password + +# modify +user.preferences.stylename = 'bluesteel' +user.addresses.append(Address('freddy@hi.org')) + +# commit +objectstore.commit() \ No newline at end of file