From d00aadd82f97ac402ab0557b8f5b37f984314caa Mon Sep 17 00:00:00 2001 From: Romain J Date: Wed, 9 Oct 2019 00:14:43 +0200 Subject: [PATCH] refactor(command/database|sondage): update poll model --- cogs/poll.py | 2 +- cogs/utils/database.py | 2 +- cogs/utils/models/poll.py | 26 ++++++++++++++++---------- prefixes.json | 6 +++--- requirements.txt | 3 ++- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/cogs/poll.py b/cogs/poll.py index 3314189..45002b1 100644 --- a/cogs/poll.py +++ b/cogs/poll.py @@ -88,7 +88,7 @@ class Polls(commands.Cog): icon_url=content.get('author').get('icon_url') ) chart_url = URL(chart_base_url + json.dumps(chart_options)) - e.set_thumbnail(url=chart_url) + e.set_thumbnail(url=str(chart_url)) for field in content.get('fields'): e.add_field( name=field.get('name'), diff --git a/cogs/utils/database.py b/cogs/utils/database.py index 3e8d2bc..bb13ff4 100644 --- a/cogs/utils/database.py +++ b/cogs/utils/database.py @@ -4,7 +4,7 @@ from sqlalchemy.orm import sessionmaker, session class Database: def __init__(self, config): - self.engine = create_engine(config.postgresql) + self.engine = create_engine(config.postgresql, echo=True) Session = sessionmaker() Session.configure(bind=self.engine) diff --git a/cogs/utils/models/poll.py b/cogs/utils/models/poll.py index ae6e4ce..d365ec3 100644 --- a/cogs/utils/models/poll.py +++ b/cogs/utils/models/poll.py @@ -1,5 +1,6 @@ from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy import Column, Integer, Boolean, BigInteger, JSON +from sqlalchemy import Column, Integer, Text, BigInteger, JSON, ForeignKey +from sqlalchemy.orm import relationship Base = declarative_base() @@ -7,15 +8,20 @@ Base = declarative_base() class Poll(Base): __tablename__ = 'polls' - id = Column(Integer, primary_key=True) + id = Column(Integer, primary_key=True, autoincrement=True) channel_id = Column(BigInteger) message_id = Column(BigInteger) - content = Column(JSON) - is_anonymous = Column(Boolean) - responses = Column(JSON, nullable=True) - def __repr__(self): - return "" % \ - (self.id, self.channel_id, self.message_id, self.content, - self.is_anonymous, self.responses) + content = Column(JSON) + + choice = relationship("Responses") + + +class Responses(Base): + __tablename__ = 'responses' + + id = Column(Integer, primary_key=True, autoincrement=True) + user = Column(Text) + + poll_id = Column(Integer, ForeignKey('polls.id')) + choice = Column(Integer) diff --git a/prefixes.json b/prefixes.json index f682140..a929ba7 100644 --- a/prefixes.json +++ b/prefixes.json @@ -1,11 +1,11 @@ { "280805240977227776": [ - "b!-" + "b!" ], "303633056944881686": [ - "b!-" + "b!" ], "336642139381301249": [ - "b!-" + "b!" ] } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 1fa6dca..c02c3bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ gitpython requests psutil bcrypt -tcp_latency \ No newline at end of file +tcp_latency +yarl \ No newline at end of file