From 9bc92d7087dfeee41a6360fa5aa7eb36ed64551a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 3 Oct 2019 22:17:36 +0200 Subject: [PATCH 1/2] Implement aliases --- royalnet/bots/generic.py | 36 ++++++++++++++------ royalnet/commands/command.py | 2 +- royalnet/commands/royalgames/dnditem.py | 2 ++ royalnet/commands/royalgames/dndspell.py | 2 ++ royalnet/commands/royalgames/mm.py | 2 ++ royalnet/commands/royalgames/mp3.py | 2 ++ royalnet/commands/royalgames/pause.py | 2 +- royalnet/commands/royalgames/play.py | 2 ++ royalnet/commands/royalgames/playmode.py | 2 ++ royalnet/commands/royalgames/queue.py | 2 ++ royalnet/commands/royalgames/rage.py | 4 ++- royalnet/commands/royalgames/reminder.py | 2 ++ royalnet/commands/royalgames/ship.py | 2 ++ royalnet/commands/royalgames/skip.py | 2 ++ royalnet/commands/royalgames/smecds.py | 2 ++ royalnet/commands/royalgames/summon.py | 2 ++ royalnet/commands/royalgames/trivia.py | 2 ++ royalnet/commands/royalgames/videochannel.py | 2 ++ royalnet/commands/royalgames/zawarudo.py | 2 ++ royalnet/version.py | 2 +- 20 files changed, 61 insertions(+), 15 deletions(-) diff --git a/royalnet/bots/generic.py b/royalnet/bots/generic.py index 2c6163a2..10f2b77f 100644 --- a/royalnet/bots/generic.py +++ b/royalnet/bots/generic.py @@ -24,19 +24,30 @@ class GenericBot: def _init_commands(self) -> None: """Generate the ``commands`` dictionary required to handle incoming messages, and the ``network_handlers`` dictionary required to handle incoming requests. """ - log.debug(f"Now binding commands") + log.info(f"Registering commands...") self._Interface = self._interface_factory() self._Data = self._data_factory() self.commands = {} self.network_handlers: typing.Dict[str, typing.Type[NetworkHandler]] = {} for SelectedCommand in self.uninitialized_commands: - log.debug(f"Binding {SelectedCommand.name}...") interface = self._Interface() try: - self.commands[f"{interface.prefix}{SelectedCommand.name}"] = SelectedCommand(interface) + command = SelectedCommand(interface) except Exception as e: - log.error(f"{e.__class__.__name__} during the initialization of {SelectedCommand.name}, skipping...") - log.debug(f"Successfully bound commands") + log.error(f"{e.__class__.__qualname__} during the registration of {SelectedCommand.__qualname__}") + # Override the main command name, but warn if it's overriding something + if f"{interface.prefix}{SelectedCommand.name}" in self.commands: + log.warning(f"Overriding (already defined): {SelectedCommand.__qualname__} -> {interface.prefix}{SelectedCommand.name}") + else: + log.debug(f"Registering: {SelectedCommand.__qualname__} -> {interface.prefix}{SelectedCommand.name}") + self.commands[f"{interface.prefix}{SelectedCommand.name}"] = command + # Register aliases, but don't override anything + for alias in SelectedCommand.aliases: + if f"{interface.prefix}{alias}" not in self.commands: + log.debug(f"Aliasing: {SelectedCommand.__qualname__} -> {interface.prefix}{alias}") + self.commands[f"{interface.prefix}{alias}"] = self.commands[f"{interface.prefix}{SelectedCommand.name}"] + else: + log.info(f"Ignoring (already defined): {SelectedCommand.__qualname__} -> {interface.prefix}{alias}") def _interface_factory(self) -> typing.Type[CommandInterface]: # noinspection PyAbstractClass,PyMethodParameters @@ -121,20 +132,23 @@ class GenericBot: """Create an :py:class:`royalnet.database.Alchemy` with the tables required by the commands. Then, find the chain that links the ``master_table`` to the ``identity_table``. """ if self.uninitialized_database_config: - log.debug(f"Initializing database") + log.info(f"Database: enabled") required_tables = {self.uninitialized_database_config.master_table, self.uninitialized_database_config.identity_table} for command in self.uninitialized_commands: required_tables = required_tables.union(command.require_alchemy_tables) - log.debug(f"Found {len(required_tables)} required tables") + log.debug(f"Required tables: {', '.join([item.__qualname__ for item in required_tables])}") self.alchemy = Alchemy(self.uninitialized_database_config.database_uri, required_tables) self.master_table = self.alchemy.__getattribute__(self.uninitialized_database_config.master_table.__name__) + log.debug(f"Master table: {self.master_table.__qualname__}") self.identity_table = self.alchemy.__getattribute__(self.uninitialized_database_config.identity_table.__name__) + log.debug(f"Identity table: {self.identity_table.__qualname__}") self.identity_column = self.identity_table.__getattribute__(self.identity_table, self.uninitialized_database_config.identity_column_name) + log.debug(f"Identity column: {self.identity_column.__class__.__qualname__}") self.identity_chain = relationshiplinkchain(self.master_table, self.identity_table) - log.debug(f"Identity chain is {self.identity_chain}") + log.debug(f"Identity chain: {' -> '.join([str(item) for item in self.identity_chain])}") else: - log.debug(f"Database is not enabled, setting everything to None") + log.debug(f"Database: disabled") self.alchemy = None self.master_table = None self.identity_table = None @@ -142,13 +156,13 @@ class GenericBot: def _init_sentry(self): if self.uninitialized_sentry_dsn: - log.debug("Sentry integration enabled") + log.info("Sentry: enabled") self.sentry = sentry_sdk.init(self.uninitialized_sentry_dsn, integrations=[AioHttpIntegration(), SqlalchemyIntegration(), LoggingIntegration(event_level=None)]) else: - log.debug("Sentry integration disabled") + log.info("Sentry: disabled") def _init_loop(self): if self.uninitialized_loop is None: diff --git a/royalnet/commands/command.py b/royalnet/commands/command.py index 9b275787..23249109 100644 --- a/royalnet/commands/command.py +++ b/royalnet/commands/command.py @@ -10,7 +10,7 @@ class Command: """The main name of the command. To have ``/example`` on Telegram, the name should be ``example``.""" - aliases: typing.List[str] = NotImplemented + aliases: typing.List[str] = [] """A list of possible aliases for a command. To have ``/e`` as alias for ``/example``, one should set aliases to ``["e"]``.""" diff --git a/royalnet/commands/royalgames/dnditem.py b/royalnet/commands/royalgames/dnditem.py index 1ce43933..de3b7050 100644 --- a/royalnet/commands/royalgames/dnditem.py +++ b/royalnet/commands/royalgames/dnditem.py @@ -11,6 +11,8 @@ from ...utils import parse_5etools_entry class DnditemCommand(Command): name: str = "dnditem" + aliases = ["item"] + description: str = "Ottieni informazioni su un oggetto di D&D5e." syntax = "(nomeoggetto)" diff --git a/royalnet/commands/royalgames/dndspell.py b/royalnet/commands/royalgames/dndspell.py index cd5d9e73..63c7a992 100644 --- a/royalnet/commands/royalgames/dndspell.py +++ b/royalnet/commands/royalgames/dndspell.py @@ -11,6 +11,8 @@ from ...utils import parse_5etools_entry, ordinalformat, andformat class DndspellCommand(Command): name: str = "dndspell" + aliases = ["spell"] + description: str = "Ottieni informazioni su una magia di D&D5e." syntax = "(nomemagia)" diff --git a/royalnet/commands/royalgames/mm.py b/royalnet/commands/royalgames/mm.py index f3b130c2..379a2fb1 100644 --- a/royalnet/commands/royalgames/mm.py +++ b/royalnet/commands/royalgames/mm.py @@ -20,6 +20,8 @@ class MmCommand(Command): Requires the MM_CHANNEL_ID envvar to be set.""" name: str = "mm" + aliases = ["matchmaking", "matchmake"] + description: str = "Trova giocatori per una partita a qualcosa." syntax: str = "[ (data) ] (nomegioco)\n[descrizione]" diff --git a/royalnet/commands/royalgames/mp3.py b/royalnet/commands/royalgames/mp3.py index e3734e59..8532aa98 100644 --- a/royalnet/commands/royalgames/mp3.py +++ b/royalnet/commands/royalgames/mp3.py @@ -11,6 +11,8 @@ from ...audio import YtdlMp3 class Mp3Command(Command): name: str = "mp3" + aliases = ["dlmusic"] + description: str = "Scarica un video con youtube-dl e invialo in chat." syntax = "(ytdlstring)" diff --git a/royalnet/commands/royalgames/pause.py b/royalnet/commands/royalgames/pause.py index 00f42d29..55f5a5e4 100644 --- a/royalnet/commands/royalgames/pause.py +++ b/royalnet/commands/royalgames/pause.py @@ -6,7 +6,7 @@ from ..commandargs import CommandArgs from ..commanddata import CommandData from ...utils import NetworkHandler from ...network import Request, ResponseSuccess -from ...error import NoneFoundError +from ...error import NoneFoundError, TooManyFoundError if typing.TYPE_CHECKING: from ...bots import DiscordBot diff --git a/royalnet/commands/royalgames/play.py b/royalnet/commands/royalgames/play.py index a20d705a..f072e158 100644 --- a/royalnet/commands/royalgames/play.py +++ b/royalnet/commands/royalgames/play.py @@ -56,6 +56,8 @@ class PlayNH(NetworkHandler): class PlayCommand(Command): name: str = "play" + aliases = ["p"] + description: str = "Aggiunge una canzone alla coda della chat vocale." syntax = "[ [guild] ] (url)" diff --git a/royalnet/commands/royalgames/playmode.py b/royalnet/commands/royalgames/playmode.py index 989d7d95..18c84f09 100644 --- a/royalnet/commands/royalgames/playmode.py +++ b/royalnet/commands/royalgames/playmode.py @@ -45,6 +45,8 @@ class PlaymodeNH(NetworkHandler): class PlaymodeCommand(Command): name: str = "playmode" + aliases = ["pm", "mode"] + description: str = "Cambia modalità di riproduzione per la chat vocale." syntax = "[ [guild] ] (mode)" diff --git a/royalnet/commands/royalgames/queue.py b/royalnet/commands/royalgames/queue.py index 04865bad..052da55c 100644 --- a/royalnet/commands/royalgames/queue.py +++ b/royalnet/commands/royalgames/queue.py @@ -50,6 +50,8 @@ class QueueNH(NetworkHandler): class QueueCommand(Command): name: str = "queue" + aliases = ["q"] + description: str = "Visualizza la coda di riproduzione attuale." syntax = "[ [guild] ]" diff --git a/royalnet/commands/royalgames/rage.py b/royalnet/commands/royalgames/rage.py index 1112efa5..9a8c85cd 100644 --- a/royalnet/commands/royalgames/rage.py +++ b/royalnet/commands/royalgames/rage.py @@ -6,7 +6,9 @@ from ..commanddata import CommandData class RageCommand(Command): - name: str = "ship" + name: str = "rage" + + aliases = ["balurage", "madden"] description: str = "Arrabbiati per qualcosa, come una software house californiana." diff --git a/royalnet/commands/royalgames/reminder.py b/royalnet/commands/royalgames/reminder.py index c7148b13..04a87526 100644 --- a/royalnet/commands/royalgames/reminder.py +++ b/royalnet/commands/royalgames/reminder.py @@ -17,6 +17,8 @@ from ...error import * class ReminderCommand(Command): name: str = "reminder" + aliases = ["calendar"] + description: str = "Ti ricorda di fare qualcosa dopo un po' di tempo." syntax: str = "[ (data) ] (messaggio)" diff --git a/royalnet/commands/royalgames/ship.py b/royalnet/commands/royalgames/ship.py index 7fb354e1..5111ae5d 100644 --- a/royalnet/commands/royalgames/ship.py +++ b/royalnet/commands/royalgames/ship.py @@ -9,6 +9,8 @@ from ...utils import safeformat class ShipCommand(Command): name: str = "ship" + aliases = ["⛵️"] + description: str = "Crea una ship tra due nomi." syntax = "(nomeuno) (nomedue)" diff --git a/royalnet/commands/royalgames/skip.py b/royalnet/commands/royalgames/skip.py index 74201e42..c0edf252 100644 --- a/royalnet/commands/royalgames/skip.py +++ b/royalnet/commands/royalgames/skip.py @@ -39,6 +39,8 @@ class SkipNH(NetworkHandler): class SkipCommand(Command): name: str = "skip" + aliases = ["s", "next", "n"] + description: str = "Salta la canzone attualmente in riproduzione in chat vocale." syntax: str = "[ [guild] ]" diff --git a/royalnet/commands/royalgames/smecds.py b/royalnet/commands/royalgames/smecds.py index 16da1ff7..b52f6341 100644 --- a/royalnet/commands/royalgames/smecds.py +++ b/royalnet/commands/royalgames/smecds.py @@ -9,6 +9,8 @@ from ...utils import safeformat class SmecdsCommand(Command): name: str = "smecds" + aliases = ["secondomeecolpadellostagista"] + description: str = "Secondo me, è colpa dello stagista..." syntax = "" diff --git a/royalnet/commands/royalgames/summon.py b/royalnet/commands/royalgames/summon.py index 99ed8733..9d9cfe91 100644 --- a/royalnet/commands/royalgames/summon.py +++ b/royalnet/commands/royalgames/summon.py @@ -28,6 +28,8 @@ class SummonNH(NetworkHandler): class SummonCommand(Command): name: str = "summon" + aliases = ["cv"] + description: str = "Evoca il bot in un canale vocale." syntax: str = "[nomecanale]" diff --git a/royalnet/commands/royalgames/trivia.py b/royalnet/commands/royalgames/trivia.py index b6385af2..7b9ec640 100644 --- a/royalnet/commands/royalgames/trivia.py +++ b/royalnet/commands/royalgames/trivia.py @@ -16,6 +16,8 @@ from ...database.tables import TriviaScore class TriviaCommand(Command): name: str = "trivia" + aliases = ["t"] + description: str = "Manda una domanda dell'OpenTDB in chat." require_alchemy_tables = {TriviaScore} diff --git a/royalnet/commands/royalgames/videochannel.py b/royalnet/commands/royalgames/videochannel.py index 3d153675..8bce18fe 100644 --- a/royalnet/commands/royalgames/videochannel.py +++ b/royalnet/commands/royalgames/videochannel.py @@ -9,6 +9,8 @@ from ...error import * class VideochannelCommand(Command): name: str = "videochannel" + aliases = ["golive", "live", "video"] + description: str = "Converti il canale vocale in un canale video." syntax = "[channelname]" diff --git a/royalnet/commands/royalgames/zawarudo.py b/royalnet/commands/royalgames/zawarudo.py index 3918ab93..cd04eec9 100644 --- a/royalnet/commands/royalgames/zawarudo.py +++ b/royalnet/commands/royalgames/zawarudo.py @@ -76,6 +76,8 @@ class ZawarudoNH(NetworkHandler): class ZawarudoCommand(Command): name: str = "zawarudo" + aliases = ["theworld", "world"] + description: str = "Ferma il tempo!" syntax = "[ [guild] ] [1-9]" diff --git a/royalnet/version.py b/royalnet/version.py index 8d92dcaa..b5e155c5 100644 --- a/royalnet/version.py +++ b/royalnet/version.py @@ -1 +1 @@ -semantic = "5.0a62" +semantic = "5.0a63" From 22f5deb294d617610eeb8848697537a29ef3a7e8 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 9 Oct 2019 00:53:34 +0200 Subject: [PATCH 2/2] Fix 500 on some pages --- royalnet/database/tables/__init__.py | 2 +- royalnet/database/tables/activekvgroups.py | 2 +- royalnet/database/tables/aliases.py | 2 +- royalnet/database/tables/bios.py | 2 +- royalnet/database/tables/diario.py | 2 +- royalnet/database/tables/discord.py | 2 +- royalnet/database/tables/medalawards.py | 2 +- royalnet/database/tables/mmdecisions.py | 2 +- royalnet/database/tables/mmevents.py | 2 +- royalnet/database/tables/mmresponse.py | 2 +- royalnet/database/tables/reminders.py | 2 +- royalnet/database/tables/telegram.py | 2 +- royalnet/database/tables/triviascores.py | 2 +- royalnet/database/tables/{royals.py => users.py} | 0 royalnet/database/tables/wikirevisions.py | 2 +- royalnet/web/royalprints/login/__init__.py | 2 +- royalnet/web/royalprints/newaccount/__init__.py | 2 +- royalnet/web/royalprints/profile/__init__.py | 6 +++--- 18 files changed, 19 insertions(+), 19 deletions(-) rename royalnet/database/tables/{royals.py => users.py} (100%) diff --git a/royalnet/database/tables/__init__.py b/royalnet/database/tables/__init__.py index de1a083d..9b6953d2 100644 --- a/royalnet/database/tables/__init__.py +++ b/royalnet/database/tables/__init__.py @@ -1,4 +1,4 @@ -from .royals import User +from .users import User from .telegram import Telegram from .diario import Diario from .aliases import Alias diff --git a/royalnet/database/tables/activekvgroups.py b/royalnet/database/tables/activekvgroups.py index 429003c2..168d8284 100644 --- a/royalnet/database/tables/activekvgroups.py +++ b/royalnet/database/tables/activekvgroups.py @@ -5,7 +5,7 @@ from sqlalchemy import Column, \ from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declared_attr # noinspection PyUnresolvedReferences -from .royals import User +from .users import User # noinspection PyUnresolvedReferences from .keygroups import Keygroup diff --git a/royalnet/database/tables/aliases.py b/royalnet/database/tables/aliases.py index afccf47f..77815149 100644 --- a/royalnet/database/tables/aliases.py +++ b/royalnet/database/tables/aliases.py @@ -5,7 +5,7 @@ from sqlalchemy import Column, \ from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declared_attr # noinspection PyUnresolvedReferences -from .royals import User +from .users import User class Alias: diff --git a/royalnet/database/tables/bios.py b/royalnet/database/tables/bios.py index 64ac8506..2703095b 100644 --- a/royalnet/database/tables/bios.py +++ b/royalnet/database/tables/bios.py @@ -4,7 +4,7 @@ from sqlalchemy import Column, \ ForeignKey from sqlalchemy.orm import relationship, backref from sqlalchemy.ext.declarative import declared_attr -from .royals import User +from .users import User class Bio: diff --git a/royalnet/database/tables/diario.py b/royalnet/database/tables/diario.py index 060489fd..dc10fd83 100644 --- a/royalnet/database/tables/diario.py +++ b/royalnet/database/tables/diario.py @@ -9,7 +9,7 @@ from sqlalchemy import Column, \ from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declared_attr # noinspection PyUnresolvedReferences -from .royals import User +from .users import User class Diario: diff --git a/royalnet/database/tables/discord.py b/royalnet/database/tables/discord.py index da2d25f9..2de86e7a 100644 --- a/royalnet/database/tables/discord.py +++ b/royalnet/database/tables/discord.py @@ -6,7 +6,7 @@ from sqlalchemy import Column, \ from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declared_attr # noinspection PyUnresolvedReferences -from .royals import User +from .users import User class Discord: diff --git a/royalnet/database/tables/medalawards.py b/royalnet/database/tables/medalawards.py index 6e54abfd..6426705d 100644 --- a/royalnet/database/tables/medalawards.py +++ b/royalnet/database/tables/medalawards.py @@ -4,7 +4,7 @@ from sqlalchemy import Column, \ ForeignKey from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.orm import relationship -from .royals import User +from .users import User from .medals import Medal diff --git a/royalnet/database/tables/mmdecisions.py b/royalnet/database/tables/mmdecisions.py index 3e2bdc8c..b67f32b7 100644 --- a/royalnet/database/tables/mmdecisions.py +++ b/royalnet/database/tables/mmdecisions.py @@ -4,7 +4,7 @@ from sqlalchemy import Column, \ ForeignKey from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declared_attr -from .royals import User +from .users import User from .mmevents import MMEvent diff --git a/royalnet/database/tables/mmevents.py b/royalnet/database/tables/mmevents.py index 774f9242..7d414a3b 100644 --- a/royalnet/database/tables/mmevents.py +++ b/royalnet/database/tables/mmevents.py @@ -9,7 +9,7 @@ from sqlalchemy import Column, \ BigInteger from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declared_attr -from .royals import User +from .users import User if typing.TYPE_CHECKING: from .mmdecisions import MMDecision from .mmresponse import MMResponse diff --git a/royalnet/database/tables/mmresponse.py b/royalnet/database/tables/mmresponse.py index a6643586..dc119be8 100644 --- a/royalnet/database/tables/mmresponse.py +++ b/royalnet/database/tables/mmresponse.py @@ -4,7 +4,7 @@ from sqlalchemy import Column, \ ForeignKey from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declared_attr -from .royals import User +from .users import User from .mmevents import MMEvent diff --git a/royalnet/database/tables/reminders.py b/royalnet/database/tables/reminders.py index 31a36db3..4a983776 100644 --- a/royalnet/database/tables/reminders.py +++ b/royalnet/database/tables/reminders.py @@ -7,7 +7,7 @@ from sqlalchemy import Column, \ from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declared_attr # noinspection PyUnresolvedReferences -from .royals import User +from .users import User class Reminder: diff --git a/royalnet/database/tables/telegram.py b/royalnet/database/tables/telegram.py index 5f922659..d3798f6e 100644 --- a/royalnet/database/tables/telegram.py +++ b/royalnet/database/tables/telegram.py @@ -6,7 +6,7 @@ from sqlalchemy import Column, \ from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declared_attr # noinspection PyUnresolvedReferences -from .royals import User +from .users import User class Telegram: diff --git a/royalnet/database/tables/triviascores.py b/royalnet/database/tables/triviascores.py index 35f00129..f9a761b5 100644 --- a/royalnet/database/tables/triviascores.py +++ b/royalnet/database/tables/triviascores.py @@ -3,7 +3,7 @@ from sqlalchemy import Column, \ ForeignKey from sqlalchemy.orm import relationship, backref from sqlalchemy.ext.declarative import declared_attr -from .royals import User +from .users import User class TriviaScore: diff --git a/royalnet/database/tables/royals.py b/royalnet/database/tables/users.py similarity index 100% rename from royalnet/database/tables/royals.py rename to royalnet/database/tables/users.py diff --git a/royalnet/database/tables/wikirevisions.py b/royalnet/database/tables/wikirevisions.py index 8713876e..fd21b55c 100644 --- a/royalnet/database/tables/wikirevisions.py +++ b/royalnet/database/tables/wikirevisions.py @@ -9,7 +9,7 @@ from sqlalchemy.ext.declarative import declared_attr # noinspection PyUnresolvedReferences from .wikipages import WikiPage # noinspection PyUnresolvedReferences -from .royals import User +from .users import User class WikiRevision: diff --git a/royalnet/web/royalprints/login/__init__.py b/royalnet/web/royalprints/login/__init__.py index a270361a..ab09dfd8 100644 --- a/royalnet/web/royalprints/login/__init__.py +++ b/royalnet/web/royalprints/login/__init__.py @@ -25,7 +25,7 @@ def login_done(): fd = f.request.form if "username" not in fd: return error(400, "Nessun username inserito.") - royal_user = alchemy_session.query(alchemy.Royal).filter_by(username=fd["username"]).one_or_none() + royal_user = alchemy_session.query(alchemy.User).filter_by(username=fd["username"]).one_or_none() if royal_user is None: return error(404, "L'username inserito non corrisponde a nessun account registrato.") if "password" not in fd: diff --git a/royalnet/web/royalprints/newaccount/__init__.py b/royalnet/web/royalprints/newaccount/__init__.py index e7b08cc6..1d1a7eda 100644 --- a/royalnet/web/royalprints/newaccount/__init__.py +++ b/royalnet/web/royalprints/newaccount/__init__.py @@ -23,7 +23,7 @@ def login_index(): return error(400, "Non è stato inserito nessun username.") if "password" not in fd: return error(400, "Non è stata inserita nessuna password.") - royal = alchemy_session.query(alchemy.Royal).filter_by(username=fd["username"]).one_or_none() + royal = alchemy_session.query(alchemy.User).filter_by(username=fd["username"]).one_or_none() if royal is not None: return error(403, "Esiste già un utente con quell'username.") alias = alchemy_session.query(alchemy.Alias).filter_by(alias=fd["username"]).one_or_none() diff --git a/royalnet/web/royalprints/profile/__init__.py b/royalnet/web/royalprints/profile/__init__.py index 7ff02eed..08a3858a 100644 --- a/royalnet/web/royalprints/profile/__init__.py +++ b/royalnet/web/royalprints/profile/__init__.py @@ -18,14 +18,14 @@ rp = Royalprint("profile", __name__, url_prefix="/profile", template_folder=tmpl @rp.route("/") def profile_index(): alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"] - royals = alchemy_session.query(alchemy.Royal).order_by(alchemy.Royal.username).all() + royals = alchemy_session.query(alchemy.User).order_by(alchemy.User.username).all() return f.render_template("profile_index.html", royals=royals) @rp.route("/") def profile_page(username): alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"] - royal = alchemy_session.query(alchemy.Royal).filter_by(username=username).one_or_none() + royal = alchemy_session.query(alchemy.User).filter_by(username=username).one_or_none() if royal is None: return error(404, "Non esiste nessun utente con l'username richiesto.") if royal.bio is not None and royal.bio.contents != "": @@ -43,7 +43,7 @@ def profile_editbio(username): if "royal" not in f.session: return error(403, "Devi aver effettuato il login per modificare una bio.") alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"] - royal = alchemy_session.query(alchemy.Royal).filter_by(username=username).one_or_none() + royal = alchemy_session.query(alchemy.User).filter_by(username=username).one_or_none() if not (f.session["royal"]["uid"] == royal.uid or f.session["royal"]["role"] == "Admin"): return error(403, "Non sei autorizzato a modificare questa pagina bio.")