add TUVoteInfo SQLAlchemy ORM model

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-06-11 20:36:32 -07:00
parent 65ff0e76da
commit 809939ab03
2 changed files with 185 additions and 0 deletions

View file

@ -0,0 +1,74 @@
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import backref, relationship
import aurweb.models.user
from aurweb.models.declarative import Base
class TUVoteInfo(Base):
__tablename__ = "TU_VoteInfo"
ID = Column(Integer, primary_key=True)
SubmitterID = Column(
Integer, ForeignKey("Users.ID", ondelete="CASCADE"),
nullable=False)
Submitter = relationship(
"User", backref=backref("tu_voteinfo_set", lazy="dynamic"),
foreign_keys=[SubmitterID])
__mapper_args__ = {"primary_key": [ID]}
def __init__(self,
Agenda: str = None,
User: str = None,
Submitted: int = None,
End: int = None,
Quorum: float = None,
Submitter: aurweb.models.user.User = None,
**kwargs):
super().__init__(**kwargs)
self.Agenda = Agenda
if self.Agenda is None:
raise IntegrityError(
statement="Column Agenda cannot be null.",
orig="TU_VoteInfo.Agenda",
params=("NULL"))
self.User = User
if self.User is None:
raise IntegrityError(
statement="Column User cannot be null.",
orig="TU_VoteInfo.User",
params=("NULL"))
self.Submitted = Submitted
if self.Submitted is None:
raise IntegrityError(
statement="Column Submitted cannot be null.",
orig="TU_VoteInfo.Submitted",
params=("NULL"))
self.End = End
if self.End is None:
raise IntegrityError(
statement="Column End cannot be null.",
orig="TU_VoteInfo.End",
params=("NULL"))
if Quorum is None:
raise IntegrityError(
statement="Column Quorum cannot be null.",
orig="TU_VoteInfo.Quorum",
params=("NULL"))
self.Quorum = str(Quorum)
self.Submitter = Submitter
if not self.Submitter:
raise IntegrityError(
statement="Foreign key SubmitterID cannot be null.",
orig="TU_VoteInfo.SubmitterID",
params=("NULL"))