add aurweb.models.session.Session ORM database object

+ Added aurweb.util module.
    - Added make_random_string function.
+ Added aurweb.db.make_random_value function.
    - Takes a model and a column and introspects them to figure out the
      proper column length to create a random string for; then creates
      a unique string for that column.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2020-12-25 20:55:43 -08:00
parent adc9fccb7d
commit 1922e5380d
4 changed files with 129 additions and 1 deletions

25
aurweb/models/session.py Normal file
View file

@ -0,0 +1,25 @@
from sqlalchemy import Column, Integer
from sqlalchemy.orm import backref, mapper, relationship
from aurweb.db import make_random_value
from aurweb.models.user import User
from aurweb.schema import Sessions
class Session:
UsersID = Column(Integer, nullable=True)
def __init__(self, **kwargs):
self.UsersID = kwargs.get("UsersID")
self.SessionID = kwargs.get("SessionID")
self.LastUpdateTS = kwargs.get("LastUpdateTS")
mapper(Session, Sessions, primary_key=[Sessions.c.SessionID], properties={
"User": relationship(User, backref=backref("session",
uselist=False))
})
def generate_unique_sid():
return make_random_value(Session, Session.SessionID)