mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
add aurweb.models.user.User
+ Added aurweb.models.user.User class. This is the first example of an sqlalchemy ORM model. We can search for users via for example: `session.query(User).filter(User.ID==1).first()`, where `session` is a configured `aurweb.db.session` object. + Along with the User class, defined the AccountType class. Each User maintains a relationship to its AccountType via User.AccountType. + Added AccountType.users backref. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
e860d828b6
commit
8a47afd2ea
2 changed files with 95 additions and 0 deletions
43
aurweb/models/user.py
Normal file
43
aurweb/models/user.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
from sqlalchemy.orm import backref, mapper, relationship
|
||||
|
||||
from aurweb.models.account_type import AccountType
|
||||
from aurweb.schema import Users
|
||||
|
||||
|
||||
class User:
|
||||
""" An ORM model of a single Users record. """
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.AccountTypeID = kwargs.get("AccountTypeID")
|
||||
|
||||
account_type = kwargs.get("AccountType")
|
||||
if account_type:
|
||||
self.AccountType = account_type
|
||||
|
||||
self.Username = kwargs.get("Username")
|
||||
self.Email = kwargs.get("Email")
|
||||
self.BackupEmail = kwargs.get("BackupEmail")
|
||||
self.Passwd = kwargs.get("Passwd")
|
||||
self.Salt = kwargs.get("Salt")
|
||||
self.RealName = kwargs.get("RealName")
|
||||
self.LangPreference = kwargs.get("LangPreference")
|
||||
self.Timezone = kwargs.get("Timezone")
|
||||
self.Homepage = kwargs.get("Homepage")
|
||||
self.IRCNick = kwargs.get("IRCNick")
|
||||
self.PGPKey = kwargs.get("PGPKey")
|
||||
self.RegistrationTS = kwargs.get("RegistrationTS")
|
||||
self.CommentNotify = kwargs.get("CommentNotify")
|
||||
self.UpdateNotify = kwargs.get("UpdateNotify")
|
||||
self.OwnershipNotify = kwargs.get("OwnershipNotify")
|
||||
self.SSOAccountID = kwargs.get("SSOAccountID")
|
||||
|
||||
def __repr__(self):
|
||||
return "<User(ID='%s', AccountType='%s', Username='%s')>" % (
|
||||
self.ID, str(self.AccountType), self.Username)
|
||||
|
||||
|
||||
# Map schema.Users to User and give it some relationships.
|
||||
mapper(User, Users, properties={
|
||||
"AccountType": relationship(AccountType,
|
||||
backref=backref("users", lazy="dynamic"))
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue