diff options
author | W. Trevor King <wking@drexel.edu> | 2009-07-14 15:18:07 -0400 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-07-14 15:18:07 -0400 |
commit | e7d150fd7ca22b01defd0c615000b6bfc367aacf (patch) | |
tree | eacb8fbc153b3b15b48cc5d2ddfee9608d431c23 /interfaces/web/Bugs-Everywhere-Web/beweb/model.py | |
parent | c38907c85bbb62a2b3bb00dd05eeb588ecc6845d (diff) | |
download | bugseverywhere-e7d150fd7ca22b01defd0c615000b6bfc367aacf.tar.gz |
Reorganized directory structure, mostly to put all the interfaces in
one place and make things clearer to the uninitiated. Here's my
current understanding:
.
|-- libbe (the guts of BE)
|-- becommands (plugins for all "be *" commands)
|-- doc (documentation, currently just the man page)
|-- interfaces (non-commandline interface implementations)
| |-- web
| | |-- Bugs-Everywhere-Web (in Turbogears)
| |-- gui
| | |-- beg (in Tkinter)
| | `-- wxbe (in WX)
| |-- email
| `-- xml (xml <-> whatever conversion)
`-- misc (random odds and ends)
`-- completion (shell completion scripts)
Note that I haven't attempted to use the web or gui interfaces in a
while, so I'm not sure how well they're holding vs the core
development.
Diffstat (limited to 'interfaces/web/Bugs-Everywhere-Web/beweb/model.py')
-rw-r--r-- | interfaces/web/Bugs-Everywhere-Web/beweb/model.py | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/interfaces/web/Bugs-Everywhere-Web/beweb/model.py b/interfaces/web/Bugs-Everywhere-Web/beweb/model.py new file mode 100644 index 0000000..aa4b6b6 --- /dev/null +++ b/interfaces/web/Bugs-Everywhere-Web/beweb/model.py @@ -0,0 +1,107 @@ +from datetime import datetime + +from sqlobject import * +from turbogears.database import PackageHub +from turbogears import identity + +hub = PackageHub("beweb") +__connection__ = hub + +class Visit(SQLObject): + class sqlmeta: + table = "visit" + + visit_key = StringCol(length=40, alternateID=True, + alternateMethodName="by_visit_key") + created = DateTimeCol(default=datetime.now) + expiry = DateTimeCol() + + def lookup_visit(cls, visit_key): + try: + return cls.by_visit_key(visit_key) + except SQLObjectNotFound: + return None + lookup_visit = classmethod(lookup_visit) + +class VisitIdentity(SQLObject): + visit_key = StringCol(length=40, alternateID=True, + alternateMethodName="by_visit_key") + user_id = IntCol() + + +class Group(SQLObject): + """ + An ultra-simple group definition. + """ + + # names like "Group", "Order" and "User" are reserved words in SQL + # so we set the name to something safe for SQL + class sqlmeta: + table = "tg_group" + + group_name = UnicodeCol(length=16, alternateID=True, + alternateMethodName="by_group_name") + display_name = UnicodeCol(length=255) + created = DateTimeCol(default=datetime.now) + + # collection of all users belonging to this group + users = RelatedJoin("User", intermediateTable="user_group", + joinColumn="group_id", otherColumn="user_id") + + # collection of all permissions for this group + permissions = RelatedJoin("Permission", joinColumn="group_id", + intermediateTable="group_permission", + otherColumn="permission_id") + + +class User(SQLObject): + """ + Reasonably basic User definition. Probably would want additional attributes. + """ + # names like "Group", "Order" and "User" are reserved words in SQL + # so we set the name to something safe for SQL + class sqlmeta: + table = "tg_user" + + child_name = UnicodeCol(length=255) + user_name = UnicodeCol(length=16, alternateID=True, + alternateMethodName="by_user_name") + email_address = UnicodeCol(length=255, alternateID=True, + alternateMethodName="by_email_address") + display_name = UnicodeCol(length=255) + password = UnicodeCol(length=40) + created = DateTimeCol(default=datetime.now) + + # groups this user belongs to + groups = RelatedJoin("Group", intermediateTable="user_group", + joinColumn="user_id", otherColumn="group_id") + + def _get_permissions(self): + perms = set() + for g in self.groups: + perms = perms | set(g.permissions) + return perms + + def _set_password(self, cleartext_password): + "Runs cleartext_password through the hash algorithm before saving." + hash = identity.encrypt_password(cleartext_password) + self._SO_set_password(hash) + + def set_password_raw(self, password): + "Saves the password as-is to the database." + self._SO_set_password(password) + + + +class Permission(SQLObject): + permission_name = UnicodeCol(length=16, alternateID=True, + alternateMethodName="by_permission_name") + description = UnicodeCol(length=255) + + groups = RelatedJoin("Group", + intermediateTable="group_permission", + joinColumn="permission_id", + otherColumn="group_id") + +def people_map(): + return dict((u.user_name, u.display_name) for u in User.select()) |