wip
This commit is contained in:
@@ -12,7 +12,7 @@ __all__ = ["Contact"]
|
||||
class Contact(StatusForeignKey, Versioned, Base):
|
||||
"""Contact"""
|
||||
|
||||
name: Mapped[str] = mapped_column(String(80), unique=True)
|
||||
code: Mapped[str] = mapped_column(String(80), unique=True)
|
||||
address: Mapped[str | None] = mapped_column(String(253))
|
||||
notes: Mapped[str | None] = mapped_column(Text)
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ __all__ = ["Country", "LocationCode", "Location"]
|
||||
|
||||
class Country(StatusForeignKey, Versioned, Base):
|
||||
|
||||
iso: Mapped[str] = mapped_column(String(2), unique=True)
|
||||
code: Mapped[str] = mapped_column(String(2), unique=True)
|
||||
name: Mapped[str] = mapped_column(String(80))
|
||||
notes: Mapped[str | None] = mapped_column(Text)
|
||||
|
||||
@@ -32,14 +32,14 @@ class CountryForeignKey:
|
||||
@event.listens_for(Country.__table__, "after_create")
|
||||
def initialize_country(target, connection, **kwargs):
|
||||
with Session(connection) as session:
|
||||
qsys = session.scalar(select(User).where(User.username == "QSYS"))
|
||||
qsys = session.scalar(select(User).where(User.code == "QSYS"))
|
||||
for kwargs in (
|
||||
dict(iso="DE", name="Germany", status_id='A'),
|
||||
dict(iso="IT", name="Italy", status_id='A'),
|
||||
dict(iso="US", name="United States"),
|
||||
dict(iso="CA", name="Canada"),
|
||||
dict(iso="MX", name="Mexico"),
|
||||
dict(iso="ES", name="Spain", status_id='A'),
|
||||
dict(code="DE", name="Germany", status_id='A'),
|
||||
dict(code="IT", name="Italy", status_id='A'),
|
||||
dict(code="US", name="United States"),
|
||||
dict(code="CA", name="Canada"),
|
||||
dict(code="MX", name="Mexico"),
|
||||
dict(code="ES", name="Spain", status_id='A'),
|
||||
):
|
||||
kwargs['_user__'] = qsys
|
||||
session.add(Country(**kwargs))
|
||||
@@ -68,12 +68,12 @@ class LocationCodeForeignKey:
|
||||
class Location(LocationCodeForeignKey, ContactForeignKey, StatusForeignKey, Versioned, Base):
|
||||
"""Location"""
|
||||
|
||||
location: Mapped[str] = mapped_column(String(30))
|
||||
code: Mapped[str] = mapped_column(String(30))
|
||||
description: Mapped[str] = mapped_column(String(256))
|
||||
notes: Mapped[str | None] = mapped_column(Text)
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint('location_code_id', location),
|
||||
UniqueConstraint('location_code_id', code),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class PrinterModelForeignKey:
|
||||
class Printer(PrinterModelForeignKey, LocationForeignKey, ContactForeignKey, StatusForeignKey, Versioned, Base):
|
||||
"""Printer"""
|
||||
|
||||
name: Mapped[str] = mapped_column(String(63), unique=True)
|
||||
code: Mapped[str] = mapped_column(String(63), unique=True)
|
||||
description: Mapped[str] = mapped_column(String(256))
|
||||
notes: Mapped[str | None] = mapped_column(Text)
|
||||
dns_name: Mapped[str | None] = mapped_column(String(253))
|
||||
|
||||
@@ -68,29 +68,29 @@ class Versioned:
|
||||
class User(StatusForeignKey, Versioned, Base):
|
||||
"""User"""
|
||||
|
||||
username: Mapped[str] = mapped_column(String(253), unique=True)
|
||||
code: Mapped[str] = mapped_column(String(253), unique=True)
|
||||
name: Mapped[str] = mapped_column(String(253))
|
||||
password: Mapped[str | None] = mapped_column(String(255))
|
||||
ldap_name: Mapped[str | None] = mapped_column(String(255))
|
||||
notes: Mapped[str | None] = mapped_column(Text)
|
||||
|
||||
def __repr__(self):
|
||||
return f'User(id={self.id!r}, username={self.username!r} name={self.name!r}, notes={self.notes!r})'
|
||||
return f'User(id={self.id!r}, code={self.code!r} name={self.name!r}, notes={self.notes!r})'
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@event.listens_for(User.__table__, "after_create")
|
||||
def initialize_user(target, connection, **kwargs):
|
||||
from routers.user import get_password_hash
|
||||
with Session(connection) as session:
|
||||
qsys = User(username="QSYS", name="System User", notes="internal processing", status_id='X')
|
||||
qsys = User(code="QSYS", name="System User", notes="internal processing", status_id='X')
|
||||
session.add(qsys)
|
||||
session.commit()
|
||||
qsys = session.scalar(select(User).where(User.username == "QSYS"))
|
||||
qsys = session.scalar(select(User).where(User.code == "QSYS"))
|
||||
qsys._user__id=qsys.id
|
||||
session.commit()
|
||||
for kwargs in (
|
||||
dict(username="CTM", name="Control-M", password=get_password_hash("secret"), notes="user for automation"),
|
||||
dict(username="exde37c8", name="Bernhard Radermacher",
|
||||
dict(code="CTM", name="Control-M", password=get_password_hash("secret"), notes="user for automation"),
|
||||
dict(code="exde37c8", name="Bernhard Radermacher",
|
||||
password=get_password_hash("secret"),
|
||||
ldap_name="a0061806@kiongroup.com",
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user