fix(typing): resolucion integral de advertencias de tipado, extraccion de payload con get_request_payload y limpieza de modelos
This commit is contained in:
@@ -21,15 +21,7 @@ class AuditLog(db.Model):
|
||||
# Relación con usuario
|
||||
user = db.relationship('User', foreign_keys=[user_id], backref=db.backref('audit_records', lazy='dynamic'))
|
||||
|
||||
def __init__(self, user_id=None, user_email=None, action=None, module=None, entity_id=None, details=None, ip_address=None, **kwargs):
|
||||
super().__init__()
|
||||
self.user_id = user_id
|
||||
self.user_email = user_email
|
||||
self.action = action
|
||||
self.module = module
|
||||
self.entity_id = entity_id
|
||||
self.details = details
|
||||
self.ip_address = ip_address
|
||||
def __init__(self, **kwargs):
|
||||
for k, v in kwargs.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ class GeneticAlgorithm:
|
||||
"""Run genetic algorithm with high concurrency to find optimal reservation schedule"""
|
||||
import concurrent.futures
|
||||
|
||||
classrooms_dict = {c.id: c for c in available_classrooms}
|
||||
classrooms_dict: Dict[int, Classroom] = {int(c.id): c for c in available_classrooms}
|
||||
requests_dict = {r.commission_id: r for r in requests}
|
||||
|
||||
# Initialize population
|
||||
@@ -263,7 +263,7 @@ class GeneticAlgorithm:
|
||||
|
||||
gene = Gene(
|
||||
commission_id=request.commission_id,
|
||||
classroom_id=classroom.id,
|
||||
classroom_id=int(classroom.id),
|
||||
start_time=start_time,
|
||||
end_time=end_time,
|
||||
expected_attendees=request.expected_attendees,
|
||||
@@ -309,7 +309,7 @@ class GeneticAlgorithm:
|
||||
# Change classroom
|
||||
suitable_classrooms = [c for c in classrooms if c.capacity >= gene_to_mutate.expected_attendees]
|
||||
if suitable_classrooms:
|
||||
gene_to_mutate.classroom_id = random.choice(suitable_classrooms).id
|
||||
gene_to_mutate.classroom_id = int(random.choice(suitable_classrooms).id)
|
||||
|
||||
elif mutation_type == 'time':
|
||||
# Slightly adjust time
|
||||
|
||||
@@ -58,7 +58,7 @@ class MilestoneGrade(db.Model):
|
||||
"""Determina si la nota está aprobada (>= 4.00 y no ausente)."""
|
||||
if self.is_absent or self.score is None:
|
||||
return False
|
||||
return self.score >= 4.0
|
||||
return bool(float(self.score) >= 4.0)
|
||||
|
||||
@property
|
||||
def display_score(self) -> str:
|
||||
@@ -66,7 +66,8 @@ class MilestoneGrade(db.Model):
|
||||
if self.is_absent:
|
||||
return 'Ausente'
|
||||
if self.score is not None:
|
||||
return f'{self.score:.1f}' if self.score % 1 != 0 else f'{int(self.score)}'
|
||||
val = float(self.score)
|
||||
return f'{val:.1f}' if val % 1 != 0 else f'{int(val)}'
|
||||
return '-'
|
||||
|
||||
def to_dict(self):
|
||||
|
||||
@@ -100,7 +100,7 @@ class Role(db.Model):
|
||||
|
||||
# Relationships
|
||||
permissions = db.relationship('Permission', backref='role', lazy='joined', cascade='all, delete-orphan')
|
||||
users: Any = db.relationship('User', backref='role_obj', lazy='select')
|
||||
users = db.relationship('User', backref='role_obj', lazy='select')
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@@ -167,14 +167,7 @@ class Permission(db.Model):
|
||||
db.UniqueConstraint('role_id', 'module', name='uq_role_module'),
|
||||
)
|
||||
|
||||
def __init__(self, role=None, role_id=None, module=None, access_level='none', **kwargs):
|
||||
super().__init__()
|
||||
if role is not None:
|
||||
self.role = role
|
||||
if role_id is not None:
|
||||
self.role_id = role_id
|
||||
self.module = module
|
||||
self.access_level = access_level
|
||||
def __init__(self, **kwargs):
|
||||
for k, v in kwargs.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
|
||||
@@ -256,12 +256,7 @@ class CommissionTeacher(db.Model):
|
||||
|
||||
__table_args__ = (db.UniqueConstraint('commission_id', 'user_id'),)
|
||||
|
||||
def __init__(self, commission_id=None, user_id=None, role='Titular', is_primary=False, **kwargs):
|
||||
super().__init__()
|
||||
self.commission_id = commission_id
|
||||
self.user_id = user_id
|
||||
self.role = role
|
||||
self.is_primary = is_primary
|
||||
def __init__(self, **kwargs):
|
||||
for k, v in kwargs.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
|
||||
@@ -35,16 +35,16 @@ class MoodleSyncTask(db.Model):
|
||||
@property
|
||||
def payload(self):
|
||||
try:
|
||||
return json.loads(self._payload) if self._payload else {}
|
||||
return json.loads(str(self._payload)) if self._payload else {}
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
@payload.setter
|
||||
def payload(self, val):
|
||||
if isinstance(val, (dict, list)):
|
||||
self._payload = json.dumps(val)
|
||||
setattr(self, '_payload', json.dumps(val))
|
||||
else:
|
||||
self._payload = str(val or '{}')
|
||||
setattr(self, '_payload', str(val or '{}'))
|
||||
|
||||
def get_payload_dict(self):
|
||||
return self.payload
|
||||
|
||||
@@ -54,11 +54,11 @@ class User(db.Model):
|
||||
|
||||
def set_password(self, password):
|
||||
"""Set password hash"""
|
||||
self.password_hash = generate_password_hash(password, method='pbkdf2:sha256')
|
||||
setattr(self, 'password_hash', generate_password_hash(password, method='pbkdf2:sha256'))
|
||||
|
||||
def check_password(self, password):
|
||||
"""Check password"""
|
||||
return check_password_hash(self.password_hash, password)
|
||||
return check_password_hash(str(self.password_hash or ''), password)
|
||||
|
||||
def is_admin(self):
|
||||
"""Check if user is admin"""
|
||||
@@ -146,7 +146,7 @@ class User(db.Model):
|
||||
|
||||
def update_last_login(self):
|
||||
"""Update last login timestamp"""
|
||||
self.last_login = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
setattr(self, 'last_login', datetime.now(timezone.utc).replace(tzinfo=None))
|
||||
db.session.commit()
|
||||
|
||||
def to_dict(self):
|
||||
|
||||
Reference in New Issue
Block a user