Change table class to guild class. Change to just store sql table information.
This commit is contained in:
@@ -0,0 +1,90 @@
|
|||||||
|
"""File for Group class."""
|
||||||
|
|
||||||
|
|
||||||
|
class Group:
|
||||||
|
"""Stores a group's information. Used just to pass sql query information around."""
|
||||||
|
|
||||||
|
def __init__(self, group_info: tuple) -> None:
|
||||||
|
"""
|
||||||
|
Default constructor for group class. Populates class from sql query results. Tuple order is important.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name (str): group's name
|
||||||
|
"""
|
||||||
|
self._id: int = group_info[0]
|
||||||
|
self._name: str = group_info[1]
|
||||||
|
self._channel_id: int = group_info[2]
|
||||||
|
self._guild_id: int = group_info[3]
|
||||||
|
self._message_id: int = group_info[4]
|
||||||
|
self._pad_length: int = group_info[5]
|
||||||
|
self._size = group_info[6]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def id(self) -> int:
|
||||||
|
"""
|
||||||
|
Getter for id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: id
|
||||||
|
"""
|
||||||
|
return self._id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
"""
|
||||||
|
Getter for name.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: name
|
||||||
|
"""
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def channel_id(self) -> int:
|
||||||
|
"""
|
||||||
|
Getter for channel id.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: channel id
|
||||||
|
"""
|
||||||
|
return self._channel_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def guild_id(self) -> int:
|
||||||
|
"""
|
||||||
|
Getter for guild id.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: guild id
|
||||||
|
"""
|
||||||
|
return self._guild_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def message_id(self) -> int:
|
||||||
|
"""
|
||||||
|
Getter for message id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: message id
|
||||||
|
"""
|
||||||
|
return self._message_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pad_length(self) -> int:
|
||||||
|
"""
|
||||||
|
Getter for pad length.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: pad length
|
||||||
|
"""
|
||||||
|
return self._pad_length
|
||||||
|
|
||||||
|
@property
|
||||||
|
def size(self) -> int:
|
||||||
|
"""
|
||||||
|
Getter for size of group.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: Size of group
|
||||||
|
"""
|
||||||
|
return self._size
|
||||||
@@ -1,174 +0,0 @@
|
|||||||
"""File for Table class."""
|
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
from classes.category import Category # pylint: disable=import-error
|
|
||||||
|
|
||||||
|
|
||||||
class Table:
|
|
||||||
"""Stores a table's information a list of categories."""
|
|
||||||
|
|
||||||
def __init__(self, name: str) -> None:
|
|
||||||
"""
|
|
||||||
Default constructor for Table class.
|
|
||||||
Creates object and fills out class variables with defaults.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
name (str): Table's name
|
|
||||||
"""
|
|
||||||
self._name: str = name
|
|
||||||
self._message_id: int = 0
|
|
||||||
self._categories_map: dict = {}
|
|
||||||
self._size = 3
|
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
"""
|
|
||||||
Returns Table class as a string for printing.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: Table class as a string
|
|
||||||
"""
|
|
||||||
return self.to_str()
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_dict(cls, table_name: str, data: dict):
|
|
||||||
"""
|
|
||||||
Creates a Table class from the passed data.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
table_name (str): Table name
|
|
||||||
data (dict): Rest of Table data in dictionary format
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Table: Populated Table object
|
|
||||||
"""
|
|
||||||
table = cls(table_name)
|
|
||||||
|
|
||||||
table.message_id = data["message_id"]
|
|
||||||
table.size = data["table_size"]
|
|
||||||
|
|
||||||
for cat_name, cat in data["categories"].items():
|
|
||||||
category = Category.from_dict(cat_name, cat)
|
|
||||||
table.add_category(category)
|
|
||||||
|
|
||||||
return table
|
|
||||||
|
|
||||||
@property
|
|
||||||
def categories(self) -> "list[Category]":
|
|
||||||
"""
|
|
||||||
Getter for Categories list.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list[Category]: List of Categories in this Table
|
|
||||||
"""
|
|
||||||
return self._categories_map.values()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def message_id(self) -> int:
|
|
||||||
"""
|
|
||||||
Getter for message id
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
int: message id
|
|
||||||
"""
|
|
||||||
return self._message_id
|
|
||||||
|
|
||||||
@message_id.setter
|
|
||||||
def message_id(self, m_id: int) -> None:
|
|
||||||
"""
|
|
||||||
Setter for message id.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
m_id (int): message id
|
|
||||||
"""
|
|
||||||
self._message_id = m_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""
|
|
||||||
Getter for name.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: name
|
|
||||||
"""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def size(self) -> int:
|
|
||||||
"""
|
|
||||||
Getter for size of table.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
int: Size of table
|
|
||||||
"""
|
|
||||||
return self._size
|
|
||||||
|
|
||||||
@size.setter
|
|
||||||
def size(self, size: int) -> None:
|
|
||||||
"""
|
|
||||||
Setter for size of table.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
size (int): New size of table
|
|
||||||
"""
|
|
||||||
self._size = size
|
|
||||||
|
|
||||||
def add_category(self, category: Category) -> None:
|
|
||||||
"""
|
|
||||||
Adds a Category to categories map. Shouldn't exist already.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
category (Category): New Category to add
|
|
||||||
"""
|
|
||||||
if category.name not in self._categories_map:
|
|
||||||
self._categories_map[category.name] = category
|
|
||||||
|
|
||||||
def get_categories(self) -> dict:
|
|
||||||
"""
|
|
||||||
Getter for dict of category names and categories.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict: Dictionary consisting of Category names and Category objects.
|
|
||||||
"""
|
|
||||||
# I don't know if this is const data. Don't want to allow data to be written as a result of this function.
|
|
||||||
return self._categories_map
|
|
||||||
|
|
||||||
def get_category(self, category_name: str) -> Category:
|
|
||||||
"""
|
|
||||||
Getter for specific category. Returns None if not found.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
category_name (str): name of category to return
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Category: Category corresponding to name. None if not found.
|
|
||||||
"""
|
|
||||||
if category_name in self._categories_map:
|
|
||||||
return self._categories_map[category_name]
|
|
||||||
return None
|
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
|
||||||
"""
|
|
||||||
Saves Table as a python dictionary.
|
|
||||||
Does not include table name. It should be the key of above data structure.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict: Table class in dictionary format
|
|
||||||
"""
|
|
||||||
data = {}
|
|
||||||
data["message_id"] = self.message_id
|
|
||||||
data["table_size"] = self.size
|
|
||||||
data["categories"] = {}
|
|
||||||
for category in self.categories:
|
|
||||||
data["categories"][category.name] = category.to_dict()
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
def to_str(self) -> str:
|
|
||||||
"""
|
|
||||||
Returns Table object as a string.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: string of json representation of Table
|
|
||||||
"""
|
|
||||||
return json.dumps(self.to_dict(), indent=4)
|
|
||||||
Reference in New Issue
Block a user