From a0912a4db261ad17e0127034b413388ea59d574e Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 2 Apr 2019 12:32:13 +0200 Subject: [PATCH] Begin work on Diario --- royalnet/commands/diario.py | 11 ++++++++++ royalnet/database/__init__.py | 3 +-- royalnet/database/tables/__init__.py | 3 ++- royalnet/database/tables/diario.py | 30 ++++++++++++++++++++++++++++ royalnet/database/tables/telegram.py | 2 +- 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 royalnet/commands/diario.py create mode 100644 royalnet/database/tables/diario.py diff --git a/royalnet/commands/diario.py b/royalnet/commands/diario.py new file mode 100644 index 00000000..c2537fc8 --- /dev/null +++ b/royalnet/commands/diario.py @@ -0,0 +1,11 @@ +from ..utils import Command, CommandArgs, Call + + +class DiarioCommand(Command): + + command_name = "diario" + command_title = "Aggiungi una citazione al Diario." + + async def common(self, call: Call, args: CommandArgs): + # TODO + raise NotImplementedError("TODO") diff --git a/royalnet/database/__init__.py b/royalnet/database/__init__.py index 50e0bcf4..9c7956f4 100644 --- a/royalnet/database/__init__.py +++ b/royalnet/database/__init__.py @@ -1,4 +1,3 @@ from .alchemy import Alchemy -from .tables import Royal -__all__ = ["Alchemy", "Royal"] +__all__ = ["Alchemy"] diff --git a/royalnet/database/tables/__init__.py b/royalnet/database/tables/__init__.py index 7ec77e9c..15a9634c 100644 --- a/royalnet/database/tables/__init__.py +++ b/royalnet/database/tables/__init__.py @@ -1,4 +1,5 @@ from .royals import Royal from .telegram import Telegram +from .diario import Diario -__all__ = ["Royal", "Telegram"] +__all__ = ["Royal", "Telegram", "Diario"] diff --git a/royalnet/database/tables/diario.py b/royalnet/database/tables/diario.py new file mode 100644 index 00000000..ba80fce8 --- /dev/null +++ b/royalnet/database/tables/diario.py @@ -0,0 +1,30 @@ +from sqlalchemy import Column, \ + Integer, \ + Text, \ + Boolean, \ + DateTime, \ + ForeignKey +from sqlalchemy.orm import relationship +from .royals import Royal + + +class Diario: + __tablename__ = "diario" + + diario_id = Column(Integer, primary_key=True) + + creator_id = Column(Integer, ForeignKey("royals.id")) + quoted_id = Column(Integer, ForeignKey("royals.id")) + timestamp = Column(DateTime, nullable=False) + quote = Column(Text, nullable=False) + context = Column(Text) + spoiler = Column(Boolean, default=False) + + creator = relationship("Royal", foreign_keys=creator_id, backref="diario_created") + quoted = relationship("Royal", foreign_keys=quoted_id, backref="diario_quoted") + + def __repr__(self): + return f"" + + def __str__(self): + return f"diario:{self.diario_id}" diff --git a/royalnet/database/tables/telegram.py b/royalnet/database/tables/telegram.py index 624584fa..e11c9f5f 100644 --- a/royalnet/database/tables/telegram.py +++ b/royalnet/database/tables/telegram.py @@ -18,7 +18,7 @@ class Telegram: tg_username = Column(String) tg_avatar = Column(LargeBinary) - royal = relationship("Royal") + royal = relationship("Royal", backref="telegram") def __repr__(self): return f""