Corrected autofill function return structures.
This commit is contained in:
+10
-9
@@ -16,7 +16,7 @@ from utilities.sql_alchemy_connection import Category, CategoryGroup, Guild, Sco
|
||||
MAX_LINE_LENGTH = 142
|
||||
|
||||
|
||||
def autofill_categories(guild_id: int, group_name: str, category_begin: str) -> "list[str]":
|
||||
def autofill_categories(guild_id: int, group_name: str, category_begin: str) -> "dict[str, str]":
|
||||
"""
|
||||
Returns all category names that start with category_begin.
|
||||
If category_begin is empty, returns list of all category names.
|
||||
@@ -27,7 +27,7 @@ def autofill_categories(guild_id: int, group_name: str, category_begin: str) ->
|
||||
category_begin (str): The beginning of a category name to search with. Can be empty.
|
||||
|
||||
Returns:
|
||||
list[str]: List of all category names that start with category_begin.
|
||||
dict[str, str]: List of all category names that start with category_begin.
|
||||
"""
|
||||
|
||||
# search database for all category names
|
||||
@@ -39,7 +39,7 @@ def autofill_categories(guild_id: int, group_name: str, category_begin: str) ->
|
||||
)
|
||||
cat_group_alias = aliased(CategoryGroup, subq)
|
||||
stmt = select(Category).where(Category.GroupId == cat_group_alias.GroupId)
|
||||
categories_dict: dict = {cat.CategoryName: cat.CategoryId for cat in session.scalars(stmt)}
|
||||
categories_dict: dict = {cat.CategoryName: str(cat.CategoryId) for cat in session.scalars(stmt)}
|
||||
|
||||
# if string empty, return all category names
|
||||
if not category_begin:
|
||||
@@ -48,14 +48,14 @@ def autofill_categories(guild_id: int, group_name: str, category_begin: str) ->
|
||||
# else find all categories that start with category_begin
|
||||
# TODO is it better to have sql handle the starts with or python?
|
||||
categories: dict = {
|
||||
cat.CategoryName: cat.CategoryId
|
||||
for cat in categories_dict.items()
|
||||
if category_begin.lower() in cat.CategoryName.lower()
|
||||
cat_name: cat_id
|
||||
for cat_name, cat_id in categories_dict.items()
|
||||
if category_begin.lower() in cat_name.CategoryName.lower()
|
||||
}
|
||||
return categories
|
||||
|
||||
|
||||
def autofill_groups(guild_id: int, group_begin: str) -> dict:
|
||||
def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
||||
"""
|
||||
Returns all group names that start with group_begin. If group_begin is empty, returns list of all group names.
|
||||
|
||||
@@ -64,13 +64,14 @@ def autofill_groups(guild_id: int, group_begin: str) -> dict:
|
||||
group_begin (str): The beginning of a group name to search with. Can be empty.
|
||||
|
||||
Returns:
|
||||
dict: Dict of group names and ids where group name start with group_begin. Key is name, value is id.
|
||||
dict[str, str]: Dict of group names and ids where group name start with group_begin. Key is name, value is id.
|
||||
"""
|
||||
|
||||
# Select all groups in guild.
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == guild_id)
|
||||
|
||||
group_dict: dict = {group.GroupName: group.GroupId for group in session.scalars(stmt)}
|
||||
# dict has to have key values of same type for discord.
|
||||
group_dict: dict = {group.GroupName: str(group.GroupId) for group in session.scalars(stmt)}
|
||||
|
||||
# if string empty, return all group names
|
||||
if not group_begin:
|
||||
|
||||
Reference in New Issue
Block a user