Feat: User Relationships and Session Members.
This commit is contained in:
@@ -38,7 +38,7 @@ class Base():
|
||||
FLAG_CITY: ClassVar[str] = 'city'
|
||||
FLAG_CODE: ClassVar[str] = 'code'
|
||||
FLAG_COUNTY: ClassVar[str] = 'county'
|
||||
FLAG_CREATED_BY: ClassVar[str] = 'created_by'
|
||||
FLAG_CREATED_BY_USER_ID: ClassVar[str] = 'created_by_user_id'
|
||||
FLAG_CREATED_ON: ClassVar[str] = 'created_on'
|
||||
FLAG_CURRENCY: ClassVar[str] = 'currency'
|
||||
FLAG_CURRENCY_COST: ClassVar[str] = 'currency_cost'
|
||||
@@ -74,6 +74,8 @@ class Base():
|
||||
FLAG_SURNAME: ClassVar[str] = 'surname'
|
||||
FLAG_SYMBOL: ClassVar[str] = 'symbol'
|
||||
FLAG_TEXT_COLOUR: ClassVar[str] = 'text_colour'
|
||||
FLAG_UPDATED_LAST_BY_USER_ID: ClassVar[str] = 'updated_last_by_user_id'
|
||||
FLAG_UPDATED_LAST_ON: ClassVar[str] = 'updated_last_on'
|
||||
FLAG_URL: ClassVar[str] = 'url'
|
||||
FLAG_USER: ClassVar[str] = 'authorisedUser' # 'user' already used
|
||||
FLAG_VALUE: ClassVar[str] = 'value'
|
||||
|
||||
@@ -52,8 +52,8 @@ class SQL_Error(SQLAlchemy_ABC, Base):
|
||||
@classmethod
|
||||
def from_db_error(cls, record):
|
||||
_m = f'{cls.__qualname__}.from_db_error'
|
||||
Helper_App.console_log(_m)
|
||||
Helper_App.console_log(f'record: {record}')
|
||||
# Helper_App.console_log(_m)
|
||||
# Helper_App.console_log(f'record: {record}')
|
||||
error = cls()
|
||||
error.error_id = record[0]
|
||||
error.guid = record[1]
|
||||
@@ -68,14 +68,14 @@ class SQL_Error(SQLAlchemy_ABC, Base):
|
||||
@classmethod
|
||||
def from_exception(cls, exception: Exception, is_breaking: bool = True):
|
||||
_m = f'{cls.__qualname__}.from_exception'
|
||||
Helper_App.console_log(_m)
|
||||
# Helper_App.console_log(_m)
|
||||
error = cls()
|
||||
error.error_id = -1
|
||||
error.id_type = -1
|
||||
error.code_type = type(exception).__name__
|
||||
error.name_type = type(exception).__name__
|
||||
error.msg = str(exception)
|
||||
Helper_App.console_log(f'Error: {error}')
|
||||
# Helper_App.console_log(f'Error: {error}')
|
||||
return error
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -114,24 +114,34 @@ class Parameters_MTG_Deck(Get_Many_Parameters_Base):
|
||||
deck_names: str
|
||||
commander_bracket_ids: str
|
||||
include_commander_option: bool
|
||||
created_by_user_ids: str
|
||||
get_all_game: bool
|
||||
get_inactive_game: bool
|
||||
game_ids: str
|
||||
filter_by_game_session_not_player: bool
|
||||
require_all_id_filters_met: bool
|
||||
require_any_id_filters_met: bool
|
||||
require_all_non_id_filters_met: bool
|
||||
require_any_non_id_filters_met: bool
|
||||
|
||||
@classmethod
|
||||
def get_default(cls):
|
||||
def get_default(cls, user_id):
|
||||
return cls(
|
||||
get_all_deck = True
|
||||
get_all_deck = False
|
||||
, get_inactive_deck = False
|
||||
, deck_ids = ''
|
||||
, deck_names = ''
|
||||
, commander_bracket_ids = ''
|
||||
, include_commander_option = True
|
||||
, require_all_id_filters_met = True
|
||||
, created_by_user_ids = str(user_id)
|
||||
, get_all_game = False
|
||||
, get_inactive_game = False
|
||||
, game_ids = ''
|
||||
, filter_by_game_session_not_player = False
|
||||
, require_all_id_filters_met = False
|
||||
, require_any_id_filters_met = True
|
||||
, require_all_non_id_filters_met = False
|
||||
, require_any_non_id_filters_met = True
|
||||
, require_any_non_id_filters_met = False
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -143,6 +153,11 @@ class Parameters_MTG_Deck(Get_Many_Parameters_Base):
|
||||
, deck_names = json.get('a_deck_names', '')
|
||||
, commander_bracket_ids = json.get('a_commander_bracket_ids', '')
|
||||
, include_commander_option = json.get('a_include_commander_option', True)
|
||||
, created_by_user_ids = json.get('a_created_by_user_ids', '')
|
||||
, get_all_game = json.get('a_get_all_game', False)
|
||||
, get_inactive_game = json.get('a_get_inactive_game', False)
|
||||
, game_ids = json.get('a_game_ids', '')
|
||||
, filter_by_game_session_not_player = json.get('a_filter_by_game_session_not_player', True)
|
||||
, require_all_id_filters_met = json.get('a_require_all_id_filters_met', True)
|
||||
, require_any_id_filters_met = json.get('a_require_any_id_filters_met', True)
|
||||
, require_all_non_id_filters_met = json.get('a_require_all_non_id_filters_met', False)
|
||||
@@ -157,6 +172,11 @@ class Parameters_MTG_Deck(Get_Many_Parameters_Base):
|
||||
, 'a_deck_names': self.deck_names
|
||||
, 'a_commander_bracket_ids': self.commander_bracket_ids
|
||||
, 'a_include_commander_option': self.include_commander_option
|
||||
, 'a_created_by_user_ids': self.created_by_user_ids
|
||||
, 'a_get_all_game': self.get_all_game
|
||||
, 'a_get_inactive_game': self.get_inactive_game
|
||||
, 'a_game_ids': self.game_ids
|
||||
, 'a_filter_by_game_session_not_player': self.filter_by_game_session_not_player
|
||||
, 'a_require_all_id_filters_met': self.require_all_id_filters_met
|
||||
, 'a_require_any_id_filters_met': self.require_any_id_filters_met
|
||||
, 'a_require_all_non_id_filters_met': self.require_all_non_id_filters_met
|
||||
@@ -172,6 +192,11 @@ class Parameters_MTG_Deck(Get_Many_Parameters_Base):
|
||||
, 'a_deck_names': Text
|
||||
, 'a_commander_bracket_ids': Text
|
||||
, 'a_include_commander_option': Boolean
|
||||
, 'a_created_by_user_ids': Text
|
||||
, 'a_get_all_game': Boolean
|
||||
, 'a_get_inactive_game': Boolean
|
||||
, 'a_game_ids': Text
|
||||
, 'a_filter_by_game_session_not_player': Boolean
|
||||
, 'a_require_all_id_filters_met': Boolean
|
||||
, 'a_require_any_id_filters_met': Boolean
|
||||
, 'a_require_all_non_id_filters_met': Boolean
|
||||
|
||||
@@ -14,6 +14,7 @@ import lib.argument_validation as av
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from datetime import datetime
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
from sqlalchemy import bindparam
|
||||
@@ -74,6 +75,8 @@ class MTG_Game(SQLAlchemy_ABC, Base):
|
||||
game.active = av.input_bool(query_row[9], cls.FLAG_ACTIVE, _m)
|
||||
game.created_on = query_row[10]
|
||||
game.created_by_user_id = query_row[11]
|
||||
game.updated_last_on = query_row[12]
|
||||
game.updated_last_by_user_id = query_row[13]
|
||||
return game
|
||||
|
||||
@classmethod
|
||||
@@ -91,8 +94,16 @@ class MTG_Game(SQLAlchemy_ABC, Base):
|
||||
game.starting_life = json.get(cls.FLAG_STARTING_LIFE, 40)
|
||||
game.end_on = json.get(cls.FLAG_END_ON, None)
|
||||
game.active = av.input_bool(json.get(cls.FLAG_ACTIVE, True), cls.FLAG_ACTIVE, _m)
|
||||
game.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
||||
_created_on = json.get(Base.FLAG_CREATED_ON, None)
|
||||
if isinstance(_created_on, str):
|
||||
_created_on = datetime.strptime(_created_on, '%a, %d %b %Y %H:%M:%S %Z')
|
||||
game.created_on = _created_on
|
||||
game.created_by_user_id = json.get(Base.ATTR_USER_ID, None)
|
||||
_updated_last_on = json.get(Base.FLAG_UPDATED_LAST_ON, None)
|
||||
if isinstance(_updated_last_on, str):
|
||||
_updated_last_on = datetime.strptime(_updated_last_on, '%a, %d %b %Y %H:%M:%S %Z')
|
||||
game.updated_last_on = _updated_last_on
|
||||
game.updated_last_by_user_id = json.get(Base.FLAG_UPDATED_LAST_BY_USER_ID, None)
|
||||
return game
|
||||
|
||||
def to_json(self):
|
||||
@@ -109,7 +120,9 @@ class MTG_Game(SQLAlchemy_ABC, Base):
|
||||
, self.FLAG_END_ON: self.end_on
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
, self.FLAG_CREATED_ON: self.created_on
|
||||
, Base.ATTR_USER_ID: self.created_by_user_id
|
||||
, self.FLAG_CREATED_BY_USER_ID: self.created_by_user_id
|
||||
, self.FLAG_UPDATED_LAST_ON: self.updated_last_on
|
||||
, self.FLAG_UPDATED_LAST_BY_USER_ID: self.updated_last_by_user_id
|
||||
}
|
||||
return as_json
|
||||
|
||||
@@ -127,7 +140,9 @@ class MTG_Game(SQLAlchemy_ABC, Base):
|
||||
{self.FLAG_STARTING_LIFE}: {self.starting_life}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
{self.FLAG_CREATED_ON}: {self.created_on}
|
||||
{Base.ATTR_USER_ID}: {self.created_by_user_id}
|
||||
{self.FLAG_CREATED_BY_USER_ID}: {self.created_by_user_id}
|
||||
{self.FLAG_UPDATED_LAST_ON}: {self.updated_last_on}
|
||||
{self.FLAG_UPDATED_LAST_BY_USER_ID}: {self.updated_last_by_user_id}
|
||||
)
|
||||
'''
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ Feature: MTG Game Player Business Object
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
from business_objects.tcg.mtg_deck import MTG_Deck
|
||||
from business_objects.tcg.mtg_game import MTG_Game
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
@@ -22,8 +24,6 @@ from sqlalchemy.types import Text, Boolean
|
||||
|
||||
class MTG_Game_Player(SQLAlchemy_ABC, Base):
|
||||
ATTR_PLAYER_ID: ClassVar[str] = 'player_id'
|
||||
ATTR_GAME_ID: ClassVar[str] = 'game_id'
|
||||
ATTR_DECK_ID: ClassVar[str] = 'deck_id'
|
||||
FLAG_PLAYER: ClassVar[str] = 'player'
|
||||
FLAG_NOTES: ClassVar[str] = 'notes'
|
||||
FLAG_DISPLAY_ORDER: ClassVar[str] = 'display_order'
|
||||
@@ -74,9 +74,9 @@ class MTG_Game_Player(SQLAlchemy_ABC, Base):
|
||||
player = cls()
|
||||
if json is None: return player
|
||||
player.player_id = json.get(cls.ATTR_PLAYER_ID, -1)
|
||||
player.game_id = json.get(cls.ATTR_GAME_ID, None)
|
||||
player.game_id = json.get(MTG_Game.ATTR_GAME_ID, None)
|
||||
player.user_id = json.get(Base.ATTR_USER_ID, None)
|
||||
player.deck_id = json.get(cls.ATTR_DECK_ID, None)
|
||||
player.deck_id = json.get(MTG_Deck.ATTR_DECK_ID, None)
|
||||
player.name = json.get(cls.FLAG_NAME, None)
|
||||
player.notes = json.get(cls.FLAG_NOTES, None)
|
||||
player.display_order = json.get(cls.FLAG_DISPLAY_ORDER, 0)
|
||||
@@ -89,9 +89,9 @@ class MTG_Game_Player(SQLAlchemy_ABC, Base):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_PLAYER_ID: self.player_id
|
||||
, self.ATTR_GAME_ID: self.game_id
|
||||
, MTG_Game.ATTR_GAME_ID: self.game_id
|
||||
, Base.ATTR_USER_ID: self.user_id
|
||||
, self.ATTR_DECK_ID: self.deck_id
|
||||
, MTG_Deck.ATTR_DECK_ID: self.deck_id
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_NOTES: self.notes
|
||||
, self.FLAG_DISPLAY_ORDER: self.display_order
|
||||
@@ -104,9 +104,9 @@ class MTG_Game_Player(SQLAlchemy_ABC, Base):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.ATTR_PLAYER_ID}: {self.player_id}
|
||||
{self.ATTR_GAME_ID}: {self.game_id}
|
||||
{MTG_Game.ATTR_GAME_ID}: {self.game_id}
|
||||
{Base.ATTR_USER_ID}: {self.user_id}
|
||||
{self.ATTR_DECK_ID}: {self.deck_id}
|
||||
{MTG_Deck.ATTR_DECK_ID}: {self.deck_id}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_NOTES}: {self.notes}
|
||||
{self.FLAG_DISPLAY_ORDER}: {self.display_order}
|
||||
|
||||
194
business_objects/tcg/mtg_game_session_member.py
Normal file
194
business_objects/tcg/mtg_game_session_member.py
Normal file
@@ -0,0 +1,194 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: MTG Game Session Member Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
from business_objects.tcg.mtg_game import MTG_Game
|
||||
from business_objects.tcg.user import User
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
from sqlalchemy import Uuid
|
||||
from sqlalchemy.types import Text, Boolean
|
||||
# import uuid
|
||||
|
||||
class MTG_Game_Session_Member(SQLAlchemy_ABC, Base):
|
||||
ATTR_SESSION_MEMBER_ID: ClassVar[str] = 'member_id'
|
||||
FLAG_IS_PERMITTED: ClassVar[str] = 'is_permitted'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_SESSION_MEMBER_ID
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'tcg_mtg_game_session_member'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
member_id = db.Column(db.Integer, primary_key=True)
|
||||
game_id = db.Column(db.Integer)
|
||||
user_id = db.Column(db.Integer)
|
||||
is_permitted = db.Column(db.Boolean)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
created_by_user_id = db.Column(db.Integer)
|
||||
updated_last_on = db.Column(db.DateTime)
|
||||
updated_last_by_user_id = db.Column(db.Integer)
|
||||
change_set_id = db.Column(db.Integer)
|
||||
|
||||
def __init__(self):
|
||||
self.member_id = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_db_mtg_game_player(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_mtg_game_player'
|
||||
player = cls()
|
||||
player.member_id = query_row[0]
|
||||
player.game_id = query_row[1]
|
||||
player.user_id = query_row[2]
|
||||
player.is_permitted = query_row[3]
|
||||
player.active = av.input_bool(query_row[4], cls.FLAG_ACTIVE, _m)
|
||||
player.created_on = query_row[5]
|
||||
player.created_by_user_id = query_row[6]
|
||||
return player
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = f'{cls.__qualname__}.from_json'
|
||||
player = cls()
|
||||
if json is None: return player
|
||||
player.member_id = json.get(cls.ATTR_SESSION_MEMBER_ID, -1)
|
||||
player.game_id = json.get(MTG_Game.ATTR_GAME_ID, None)
|
||||
player.user_id = json.get(Base.ATTR_USER_ID, None)
|
||||
player.is_permitted = json.get(cls.FLAG_IS_PERMITTED, None)
|
||||
player.active = av.input_bool(json.get(cls.FLAG_ACTIVE, True), cls.FLAG_ACTIVE, _m)
|
||||
player.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
||||
player.created_by_user_id = json.get(Base.ATTR_USER_ID, None)
|
||||
return player
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_SESSION_MEMBER_ID: self.member_id
|
||||
, MTG_Game.ATTR_GAME_ID: self.game_id
|
||||
, Base.ATTR_USER_ID: self.user_id
|
||||
, self.FLAG_IS_PERMITTED: self.is_permitted
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
, self.FLAG_CREATED_ON: self.created_on
|
||||
}
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.ATTR_SESSION_MEMBER_ID}: {self.member_id}
|
||||
{MTG_Game.ATTR_GAME_ID}: {self.game_id}
|
||||
{Base.ATTR_USER_ID}: {self.user_id}
|
||||
{self.FLAG_IS_PERMITTED}: {self.is_permitted}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
{self.FLAG_CREATED_ON}: {self.created_on}
|
||||
)
|
||||
'''
|
||||
|
||||
class MTG_Game_Session_Member_Temp(db.Model, Base):
|
||||
__tablename__ = 'tcg_mtg_game_session_member_temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
temp_id = db.Column(db.Integer, primary_key=True)
|
||||
member_id = db.Column(db.Integer)
|
||||
game_id = db.Column(db.Integer)
|
||||
user_id = db.Column(db.Integer)
|
||||
is_permitted = db.Column(db.Boolean)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
guid = db.Column(Uuid) #, default = uuid.uuid4)
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_session_member(cls, member, guid):
|
||||
_m = 'MTG_Game_Session_Member_Temp.from_session_member'
|
||||
temp = cls()
|
||||
temp.member_id = member.member_id
|
||||
temp.game_id = member.game_id
|
||||
temp.user_id = member.user_id
|
||||
temp.is_permitted = member.is_permitted
|
||||
temp.active = member.active
|
||||
temp.created_on = member.created_on
|
||||
temp.guid = guid
|
||||
return temp
|
||||
|
||||
|
||||
class Parameters_MTG_Game_Session_Member(Get_Many_Parameters_Base):
|
||||
get_inactive_session_member: bool
|
||||
get_all_game: bool
|
||||
get_inactive_game: bool
|
||||
game_ids: str
|
||||
get_all_user: bool
|
||||
get_inactive_user: bool
|
||||
user_ids: str
|
||||
require_all_id_filters_met: bool
|
||||
require_any_id_filters_met: bool
|
||||
|
||||
@classmethod
|
||||
def get_default(cls, user_id_session):
|
||||
return cls(
|
||||
get_inactive_session_member = False
|
||||
, get_all_game = True
|
||||
, get_inactive_game = False
|
||||
, game_ids = ''
|
||||
, get_all_user = True
|
||||
, get_inactive_user = False
|
||||
, user_ids = str(user_id_session)
|
||||
, require_all_id_filters_met = True
|
||||
, require_any_id_filters_met = True
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
return cls(
|
||||
get_inactive_session_member = json.get('a_get_inactive_session_member', False)
|
||||
, get_all_game = json.get('a_get_all_game', False)
|
||||
, get_inactive_game = json.get('a_get_inactive_game', False)
|
||||
, game_ids = json.get('a_game_ids', '')
|
||||
, get_all_user = json.get('a_get_all_user', False)
|
||||
, get_inactive_user = json.get('a_get_inactive_user', False)
|
||||
, user_ids = json.get('a_user_ids', '')
|
||||
, require_all_id_filters_met = json.get('a_require_all_id_filters_met', True)
|
||||
, require_any_id_filters_met = json.get('a_require_any_id_filters_met', True)
|
||||
)
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'a_get_inactive_session_member': self.get_inactive_session_member
|
||||
, 'a_get_all_game': self.get_all_game
|
||||
, 'a_get_inactive_game': self.get_inactive_game
|
||||
, 'a_game_ids': self.game_ids
|
||||
, 'a_get_all_user': self.get_all_user
|
||||
, 'a_get_inactive_user': self.get_inactive_user
|
||||
, 'a_user_ids': self.user_ids
|
||||
, 'a_require_all_id_filters_met': self.require_all_id_filters_met
|
||||
, 'a_require_any_id_filters_met': self.require_any_id_filters_met
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def get_type_hints():
|
||||
return {
|
||||
'a_get_inactive_session_member': Boolean
|
||||
, 'a_get_all_game': Boolean
|
||||
, 'a_get_inactive_game': Boolean
|
||||
, 'a_game_ids': Text
|
||||
, 'a_get_all_user': Boolean
|
||||
, 'a_get_inactive_user': Boolean
|
||||
, 'a_user_ids': Text
|
||||
, 'a_require_all_id_filters_met': Boolean
|
||||
, 'a_require_any_id_filters_met': Boolean
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class User(SQLAlchemy_ABC, Base):
|
||||
updated_last_by_user_id, change_set_id
|
||||
"""
|
||||
_m = f'{cls.__qualname__}.from_db_user'
|
||||
Helper_App.console_log(f'user record: {query_row}')
|
||||
# Helper_App.console_log(f'user record: {query_row}')
|
||||
user = cls()
|
||||
user.user_id = query_row[0]
|
||||
user.user_auth0_id = query_row[1]
|
||||
@@ -72,7 +72,7 @@ class User(SQLAlchemy_ABC, Base):
|
||||
_m = f'{cls.__qualname__}.from_json'
|
||||
user = cls()
|
||||
if json is None: return user
|
||||
Helper_App.console_log(f'{_m}/n{json}')
|
||||
# Helper_App.console_log(f'{_m}/n{json}')
|
||||
user.user_id = json[cls.ATTR_USER_ID]
|
||||
user.user_auth0_id = json[cls.ATTR_USER_AUTH0_ID]
|
||||
user.firstname = json[cls.FLAG_FIRSTNAME]
|
||||
@@ -85,12 +85,12 @@ class User(SQLAlchemy_ABC, Base):
|
||||
@classmethod
|
||||
def from_json_auth0(cls, json):
|
||||
_m = f'{cls.__qualname__}.from_json_auth0'
|
||||
Helper_App.console_log(_m)
|
||||
Helper_App.console_log(f'JSON: {json}')
|
||||
# Helper_App.console_log(_m)
|
||||
# Helper_App.console_log(f'JSON: {json}')
|
||||
user = cls()
|
||||
if json is None: return user
|
||||
user_info = json['userinfo']
|
||||
Helper_App.console_log(f'user_info: {user_info}')
|
||||
# Helper_App.console_log(f'user_info: {user_info}')
|
||||
user.user_id = None
|
||||
user.user_auth0_id = user_info['sub']
|
||||
user.firstname = None
|
||||
|
||||
197
business_objects/tcg/user_relationship.py
Normal file
197
business_objects/tcg/user_relationship.py
Normal file
@@ -0,0 +1,197 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: User Relationship Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
from sqlalchemy import Uuid
|
||||
from sqlalchemy.types import Text, Boolean
|
||||
# import uuid
|
||||
|
||||
class User_Relationship(SQLAlchemy_ABC, Base):
|
||||
ATTR_RELATIONSHIP_ID: ClassVar[str] = 'relationship_id'
|
||||
FLAG_FOLLOWER_USER_ID: ClassVar[str] = 'follower_user_id'
|
||||
FLAG_FOLLOWING_USER_ID: ClassVar[str] = 'following_user_id'
|
||||
FLAG_IS_FOLLOWING: ClassVar[str] = 'is_following'
|
||||
FLAG_IS_BLOCKED: ClassVar[str] = 'is_blocked'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_RELATIONSHIP_ID
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = ATTR_RELATIONSHIP_ID
|
||||
|
||||
__tablename__ = 'tcg_user_relationship'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
relationship_id = db.Column(db.Integer, primary_key=True)
|
||||
follower_user_id = db.Column(db.Integer)
|
||||
following_user_id = db.Column(db.Integer)
|
||||
is_following = db.Column(db.Boolean)
|
||||
is_blocked = db.Column(db.Boolean)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
created_by_user_id = db.Column(db.Integer)
|
||||
updated_last_on = db.Column(db.DateTime)
|
||||
updated_last_by_user_id = db.Column(db.Integer)
|
||||
change_set_id = db.Column(db.Integer)
|
||||
|
||||
def __init__(self):
|
||||
self.relationship_id = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_db_user_relationship(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_user_relationship'
|
||||
player = cls()
|
||||
player.relationship_id = query_row[0]
|
||||
player.follower_user_id = query_row[1]
|
||||
player.following_user_id = query_row[2]
|
||||
player.is_following = query_row[3]
|
||||
player.is_blocked = query_row[4]
|
||||
player.active = av.input_bool(query_row[5], cls.FLAG_ACTIVE, _m)
|
||||
player.created_on = query_row[6]
|
||||
player.created_by_user_id = query_row[7]
|
||||
return player
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = f'{cls.__qualname__}.from_json'
|
||||
player = cls()
|
||||
if json is None: return player
|
||||
player.relationship_id = json.get(cls.ATTR_RELATIONSHIP_ID, -1)
|
||||
player.follower_user_id = json.get(cls.FLAG_FOLLOWER_USER_ID, None)
|
||||
player.following_user_id = json.get(cls.FLAG_FOLLOWING_USER_ID, None)
|
||||
player.is_following = json.get(cls.FLAG_IS_FOLLOWING, None)
|
||||
player.is_blocked = json.get(cls.FLAG_IS_BLOCKED, None)
|
||||
player.active = av.input_bool(json.get(cls.FLAG_ACTIVE, True), cls.FLAG_ACTIVE, _m)
|
||||
player.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
||||
player.created_by_user_id = json.get(Base.ATTR_USER_ID, None)
|
||||
return player
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_RELATIONSHIP_ID: self.relationship_id
|
||||
, self.FLAG_FOLLOWER_USER_ID: self.follower_user_id
|
||||
, self.FLAG_FOLLOWING_USER_ID: self.following_user_id
|
||||
, self.FLAG_IS_FOLLOWING: self.is_following
|
||||
, self.FLAG_IS_BLOCKED: self.is_blocked
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
, self.FLAG_CREATED_ON: self.created_on
|
||||
}
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.ATTR_RELATIONSHIP_ID}: {self.relationship_id}
|
||||
{self.FLAG_FOLLOWER_USER_ID}: {self.follower_user_id}
|
||||
{self.FLAG_FOLLOWING_USER_ID}: {self.following_user_id}
|
||||
{self.FLAG_IS_FOLLOWING}: {self.is_following}
|
||||
{self.FLAG_IS_BLOCKED}: {self.is_blocked}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
{self.FLAG_CREATED_ON}: {self.created_on}
|
||||
)
|
||||
'''
|
||||
|
||||
class User_Relationship_Temp(db.Model, Base):
|
||||
__tablename__ = 'tcg_user_relationship_temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
temp_id = db.Column(db.Integer, primary_key=True)
|
||||
relationship_id = db.Column(db.Integer)
|
||||
follower_user_id = db.Column(db.Integer)
|
||||
following_user_id = db.Column(db.Integer)
|
||||
is_following = db.Column(db.Boolean)
|
||||
is_blocked = db.Column(db.Boolean)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
guid = db.Column(Uuid) #, default = uuid.uuid4)
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_user_relationship(cls, relationship, guid):
|
||||
_m = 'User_Relationship_Temp.from_user_relationship'
|
||||
temp = cls()
|
||||
temp.relationship_id = relationship.relationship_id
|
||||
temp.follower_user_id = relationship.follower_user_id
|
||||
temp.following_user_id = relationship.following_user_id
|
||||
temp.is_following = relationship.is_following
|
||||
temp.is_blocked = relationship.is_blocked
|
||||
temp.active = relationship.active
|
||||
temp.created_on = relationship.created_on
|
||||
temp.guid = guid
|
||||
return temp
|
||||
|
||||
|
||||
class Parameters_User_Relationship(Get_Many_Parameters_Base):
|
||||
get_inactive_user_relationship: bool
|
||||
get_all_user_follower: bool
|
||||
follower_user_ids: str
|
||||
get_all_user_following: bool
|
||||
following_user_ids: str
|
||||
get_inactive_user: bool
|
||||
require_all_id_filters_met: bool
|
||||
require_any_id_filters_met: bool
|
||||
|
||||
@classmethod
|
||||
def get_default(cls, user_id_session):
|
||||
return cls(
|
||||
get_inactive_user_relationship = True
|
||||
, get_all_user_follower = False
|
||||
, follower_user_ids = ''
|
||||
, get_all_user_following = True
|
||||
, following_user_ids = ''
|
||||
, get_inactive_user = False
|
||||
, require_all_id_filters_met = True
|
||||
, require_any_id_filters_met = True
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
return cls(
|
||||
get_inactive_user_relationship = json.get('a_get_inactive_user_relationship', False)
|
||||
, get_all_user_follower = json.get('a_get_all_user_follower', False)
|
||||
, follower_user_ids = json.get('a_follower_user_ids', '')
|
||||
, get_all_user_following = json.get('a_get_all_user_following', False)
|
||||
, following_user_ids = json.get('a_following_user_ids', '')
|
||||
, get_inactive_user = json.get('a_get_inactive_user', False)
|
||||
, require_all_id_filters_met = json.get('a_require_all_id_filters_met', True)
|
||||
, require_any_id_filters_met = json.get('a_require_any_id_filters_met', True)
|
||||
)
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'a_get_inactive_user_relationship': self.get_inactive_user_relationship
|
||||
, 'a_get_all_user_follower': self.get_all_user_follower
|
||||
, 'a_follower_user_ids': self.follower_user_ids
|
||||
, 'a_get_all_user_following': self.get_all_user_following
|
||||
, 'a_following_user_ids': self.following_user_ids
|
||||
, 'a_get_inactive_user': self.get_inactive_user
|
||||
, 'a_require_all_id_filters_met': self.require_all_id_filters_met
|
||||
, 'a_require_any_id_filters_met': self.require_any_id_filters_met
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def get_type_hints():
|
||||
return {
|
||||
'a_get_inactive_user_relationship': Boolean
|
||||
, 'a_get_all_user_follower': Boolean
|
||||
, 'a_follower_user_ids': Text
|
||||
, 'a_get_all_user_following': Boolean
|
||||
, 'a_following_user_ids': Text
|
||||
, 'a_get_inactive_user': Boolean
|
||||
, 'a_require_all_id_filters_met': Boolean
|
||||
, 'a_require_any_id_filters_met': Boolean
|
||||
}
|
||||
Reference in New Issue
Block a user