Package bodhi :: Package identity :: Module tables
[hide private]
[frames] | no frames]

Source Code for Module bodhi.identity.tables

 1  # $Id: $ 
 2   
 3  from sqlobject import * 
 4  from datetime import datetime 
 5  from turbogears import identity 
 6  from turbogears.database import PackageHub 
 7   
 8  hub = PackageHub("bodhi") 
 9  __connection__ = hub 
10   
11  ## 
12  ## Identity tables 
13  ## 
14   
15 -class Visit(SQLObject):
16 visit_key = StringCol(length=40, alternateID=True, 17 alternateMethodName="by_visit_key") 18 created = DateTimeCol(default=datetime.now) 19 expiry = DateTimeCol() 20
21 - def lookup_visit(cls, visit_key):
22 try: 23 return cls.by_visit_key(visit_key) 24 except SQLObjectNotFound: 25 return None
26 lookup_visit = classmethod(lookup_visit)
27
28 -class VisitIdentity(SQLObject):
29 visit_key = StringCol(length=40, alternateID=True, 30 alternateMethodName="by_visit_key") 31 user_id = IntCol()
32
33 -class Group(SQLObject):
34 - class sqlmeta:
35 table = "tg_group"
36 37 group_name = UnicodeCol(length=16, alternateID=True, 38 alternateMethodName="by_group_name") 39 display_name = UnicodeCol(length=255) 40 created = DateTimeCol(default=datetime.now) 41 users = RelatedJoin("User", intermediateTable="user_group", 42 joinColumn="group_id", otherColumn="user_id") 43 permissions = RelatedJoin("Permission", joinColumn="group_id", 44 intermediateTable="group_permission", 45 otherColumn="permission_id")
46
47 -class User(SQLObject):
48 - class sqlmeta:
49 table = "tg_user"
50 51 user_name = UnicodeCol(length=30, alternateID=True, 52 alternateMethodName="by_user_name") 53 display_name = UnicodeCol(length=30, default=None) 54 password = UnicodeCol(length=40, default=None) 55 groups = RelatedJoin("Group", intermediateTable="user_group", 56 joinColumn="user_id", otherColumn="group_id") 57 created = DateTimeCol(default=datetime.now) 58
59 - def _get_permissions(self):
60 perms = set() 61 for g in self.groups: 62 perms = perms | set(g.permissions) 63 return perms
64
65 - def _set_password(self, cleartext_password):
66 "Runs cleartext_password through the hash algorithm before saving." 67 hash = identity.encrypt_password(cleartext_password) 68 self._SO_set_password(hash)
69
70 - def set_password_raw(self, password):
71 "Saves the password as-is to the database." 72 self._SO_set_password(password)
73
74 -class Permission(SQLObject):
75 permission_name = UnicodeCol(length=16, alternateID=True, 76 alternateMethodName="by_permission_name") 77 description = UnicodeCol(length=255) 78 79 groups = RelatedJoin("Group", 80 intermediateTable="group_permission", 81 joinColumn="permission_id", 82 otherColumn="group_id")
83