Mercurial > genshi > mirror
annotate examples/turbogears/genshitest/model.py @ 814:a5c74a9b9782 trunk
Remove unneeded conversion of empty attribute values into a single-item list of an empty `TEXT` event.
author | cmlenz |
---|---|
date | Mon, 09 Mar 2009 14:04:21 +0000 |
parents | 84168828b074 |
children |
rev | line source |
---|---|
110
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
1 from datetime import datetime |
4
49364e784c47
Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff
changeset
|
2 |
110
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
3 from sqlobject import * |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
4 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
5 from turbogears import identity |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
6 from turbogears.database import PackageHub |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
7 |
230 | 8 hub = PackageHub("genshitest") |
110
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
9 __connection__ = hub |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
10 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
11 # class YourDataClass(SQLObject): |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
12 # pass |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
13 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
14 class Visit(SQLObject): |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
15 class sqlmeta: |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
16 table="visit" |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
17 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
18 visit_key= StringCol( length=40, alternateID=True, |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
19 alternateMethodName="by_visit_key" ) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
20 created= DateTimeCol( default=datetime.now ) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
21 expiry= DateTimeCol() |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
22 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
23 def lookup_visit( cls, visit_key ): |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
24 try: |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
25 return cls.by_visit_key( visit_key ) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
26 except SQLObjectNotFound: |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
27 return None |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
28 lookup_visit= classmethod(lookup_visit) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
29 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
30 class VisitIdentity(SQLObject): |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
31 visit_key = StringCol(length=40, alternateID=True, |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
32 alternateMethodName="by_visit_key") |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
33 user_id = IntCol() |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
34 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
35 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
36 class Group(SQLObject): |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
37 """ |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
38 An ultra-simple group definition. |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
39 """ |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
40 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
41 # names like "Group", "Order" and "User" are reserved words in SQL |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
42 # so we set the name to something safe for SQL |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
43 class sqlmeta: |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
44 table="tg_group" |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
45 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
46 group_name = UnicodeCol(length=16, alternateID=True, |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
47 alternateMethodName="by_group_name") |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
48 display_name = UnicodeCol(length=255) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
49 created = DateTimeCol(default=datetime.now) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
50 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
51 # collection of all users belonging to this group |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
52 users = RelatedJoin("User", intermediateTable="user_group", |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
53 joinColumn="group_id", otherColumn="user_id") |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
54 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
55 # collection of all permissions for this group |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
56 permissions = RelatedJoin("Permission", joinColumn="group_id", |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
57 intermediateTable="group_permission", |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
58 otherColumn="permission_id") |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
59 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
60 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
61 class User(SQLObject): |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
62 """ |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
63 Reasonably basic User definition. Probably would want additional attributes. |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
64 """ |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
65 # names like "Group", "Order" and "User" are reserved words in SQL |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
66 # so we set the name to something safe for SQL |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
67 class sqlmeta: |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
68 table="tg_user" |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
69 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
70 user_name = UnicodeCol(length=16, alternateID=True, |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
71 alternateMethodName="by_user_name") |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
72 email_address = UnicodeCol(length=255, alternateID=True, |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
73 alternateMethodName="by_email_address") |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
74 display_name = UnicodeCol(length=255) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
75 password = UnicodeCol(length=40) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
76 created = DateTimeCol(default=datetime.now) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
77 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
78 # groups this user belongs to |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
79 groups = RelatedJoin("Group", intermediateTable="user_group", |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
80 joinColumn="user_id", otherColumn="group_id") |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
81 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
82 def _get_permissions(self): |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
83 perms = set() |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
84 for g in self.groups: |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
85 perms = perms | set(g.permissions) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
86 return perms |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
87 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
88 def _set_password(self, cleartext_password): |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
89 "Runs cleartext_password through the hash algorithm before saving." |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
90 hash = identity.encrypt_password(cleartext_password) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
91 self._SO_set_password(hash) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
92 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
93 def set_password_raw(self, password): |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
94 "Saves the password as-is to the database." |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
95 self._SO_set_password(password) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
96 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
97 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
98 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
99 class Permission(SQLObject): |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
100 permission_name = UnicodeCol(length=16, alternateID=True, |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
101 alternateMethodName="by_permission_name") |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
102 description = UnicodeCol(length=255) |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
103 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
104 groups = RelatedJoin("Group", |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
105 intermediateTable="group_permission", |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
106 joinColumn="permission_id", |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
107 otherColumn="group_id") |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
108 |
64ff134868c4
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
109 |