proposals and refactoring

This commit is contained in:
2022-06-19 20:54:39 +03:00
parent 30c51ecac1
commit 11f81d46ce
9 changed files with 545 additions and 370 deletions

View File

@@ -6,9 +6,13 @@ from orm.notification import Notification
from orm.shout import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay,\
ShoutRatingStorage, ShoutViewStorage
from orm.base import Base, engine, local_session
from orm.comment import Comment, CommentRating
from orm.comment import Comment, CommentRating #, CommentRatingStorage
from orm.proposal import Proposal, ProposalRating #, ProposalRatingStorage
__all__ = ["User", "Role", "Community", "Operation", "Permission", "Shout", "Topic", "TopicSubscription", "Notification", "ShoutRating", "Comment", "CommentRating", "UserRating"]
__all__ = ["User", "Role", "Community", "Operation", \
"Permission", "Shout", "Topic", "TopicSubscription", \
"Notification", "ShoutRating", "Comment", "CommentRating", \
"UserRating", "Proposal", "ProposalRating"]
Base.metadata.create_all(engine)
Operation.init_table()
@@ -19,6 +23,8 @@ Role.init_table()
with local_session() as session:
ShoutRatingStorage.init(session)
# CommentRatingStorage.init(session)
# ProposalRatingStorage.init(session)
ShoutViewStorage.init(session)
RoleStorage.init(session)
UserStorage.init(session)

View File

@@ -1,23 +1,33 @@
from typing import List
from datetime import datetime
from sqlalchemy import Column, Integer, String, ForeignKey, Datetime
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
from sqlalchemy.orm import relationship
from orm import Permission
from orm.base import Base
class Proposal(Base):
__tablename__ = 'proposal'
class ProposalRating(Base):
__tablename__ = "comment_rating"
shout: int = Column(Integer, ForeignKey("shout.id"), nullable=False, comment="Shout")
range: str = Column(String, nullable=True, comment="Range in format <start index>:<end>")
body: str = Column(String, nullable=False, comment="Body")
createdBy: int = Column(Integer, ForeignKey("user.id"), nullable=False, comment="Author")
createdAt: str = Column(datetime, nullable=False, comment="Created at")
updatedAt: str = Column(datetime, nullable=True, comment="Updated at")
acceptedAt: str = Column(datetime, nullable=True, comment="Accepted at")
acceptedBy: str = Column(datetime, nullable=True, comment="Accepted by")
deletedAt: str = Column(datetime, nullable=True, comment="Deleted at")
declinedAt: str = Column(datetime, nullable=True, comment="Declined at)
declinedBy: str = Column(datetime, nullable=True, comment="Declined by")
# TODO: debug, logix
id = None
proposal_id = Column(ForeignKey('proposal.id'), primary_key = True)
createdBy = Column(ForeignKey('user.slug'), primary_key = True)
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Timestamp")
value = Column(Integer)
class Proposal(Base):
__tablename__ = 'proposal'
shout: str = Column(String, ForeignKey("shout.slug"), nullable=False, comment="Shout")
range: str = Column(String, nullable=True, comment="Range in format <start index>:<end>")
body: str = Column(String, nullable=False, comment="Body")
createdBy: int = Column(Integer, ForeignKey("user.id"), nullable=False, comment="Author")
createdAt: str = Column(DateTime, nullable=False, comment="Created at")
updatedAt: str = Column(DateTime, nullable=True, comment="Updated at")
acceptedAt: str = Column(DateTime, nullable=True, comment="Accepted at")
acceptedBy: str = Column(Integer, ForeignKey("user.id"), nullable=True, comment="Accepted by")
declinedAt: str = Column(DateTime, nullable=True, comment="Declined at")
declinedBy: str = Column(Integer, ForeignKey("user.id"), nullable=True, comment="Declined by")
ratings = relationship(ProposalRating, foreign_keys=ProposalRating.proposal_id)
deletedAt: str = Column(DateTime, nullable=True, comment="Deleted at")
# TODO: debug, logix