Moving things to use the common_route_params and unified functions for SQL enable and SQL LIMIT OFFSET
This commit is contained in:
@@ -4,7 +4,7 @@ import datetime, pytz, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from app.db_sql import redis_lookup_id_random, sql_insert, sql_insert_or_update, sql_select, sql_update
|
||||
from app.db_sql import redis_lookup_id_random, sql_enable_part, sql_insert, sql_insert_or_update, sql_limit_offset_part, sql_select, sql_update
|
||||
from app.lib_general import log, logging, logger_reset, send_email
|
||||
|
||||
# from app.methods.address_methods import load_address_obj
|
||||
@@ -24,11 +24,12 @@ from app.models.person_models import Person_Base
|
||||
def load_person_obj(
|
||||
person_id: int|str,
|
||||
auth_key: str = None,
|
||||
limit: int = 1000,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
model_as_dict: bool = False,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
inc_address: bool = False, # Under contact
|
||||
inc_contact: bool = False,
|
||||
inc_event_list: bool = False,
|
||||
@@ -56,7 +57,7 @@ def load_person_obj(
|
||||
inc_user: bool = False,
|
||||
inc_user_role_list: bool = False,
|
||||
) -> Person_Base|dict|bool:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
|
||||
@@ -349,10 +350,11 @@ def get_person_rec_list(
|
||||
for_obj_type: str,
|
||||
for_obj_id: str,
|
||||
email: str = None,
|
||||
limit: int = 1000,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
limit: int = 1000,
|
||||
offset: int = 0,
|
||||
) -> list|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type): pass
|
||||
@@ -366,22 +368,8 @@ def get_person_rec_list(
|
||||
if email:
|
||||
sql_where_email = 'AND (user.email = :email OR contact.email = :email)'
|
||||
|
||||
# if enabled in ['enabled', 'disabled', 'all']:
|
||||
# if enabled == 'enabled':
|
||||
# data['enable'] = True
|
||||
# sql_enabled = f'AND `person`.enable = :enable'
|
||||
# elif enabled == 'disabled':
|
||||
# data['enable'] = False
|
||||
# sql_enabled = f'AND `person`.enable = :enable'
|
||||
# elif enabled == 'all':
|
||||
# sql_enabled = ''
|
||||
sql_enabled = ''
|
||||
|
||||
if limit:
|
||||
data['limit'] = limit
|
||||
sql_limit = f'LIMIT :limit'
|
||||
else:
|
||||
sql_limit = ''
|
||||
sql_enabled, data['enable'] = sql_enable_part(table_name='person', enabled=enabled) # Reasonably safe return str and bool
|
||||
sql_limit = sql_limit_offset_part(limit=limit, offset=offset) # Reasonably safe return str
|
||||
|
||||
if not email:
|
||||
sql = f"""
|
||||
|
||||
Reference in New Issue
Block a user