Files
TimeTracker/app/schemas/user_schema.py
T
Dries Peeters b4486a627f fix: CI tests, code quality, and duplicate DB indexes
- Webhook models: remove duplicate index definitions so db.create_all()
  no longer raises 'index already exists' (columns already have index=True)
- ImportService: fix circular import by late-importing ClientService,
  ProjectService, TimeTrackingService in __init__
- reports: fix F823 by renaming unpack variable _ to _entry_count to avoid
  shadowing gettext _ in export_task_excel()
- Code quality: add .flake8 with extend-ignore so flake8 CI passes;
  simplify pyproject.toml isort config (drop unsupported options)
- Format: run black and isort on app/
- tests: restore minimal app fixture in test_import_export_models
2026-03-15 10:51:52 +01:00

47 lines
1.8 KiB
Python

"""
Schemas for user serialization and validation.
"""
from marshmallow import Schema, fields, validate
from app.constants import UserRole
class UserSchema(Schema):
"""Schema for user serialization"""
id = fields.Int(dump_only=True)
username = fields.Str(required=True, validate=validate.Length(max=100))
email = fields.Email(allow_none=True)
full_name = fields.Str(allow_none=True, validate=validate.Length(max=200))
role = fields.Str(validate=validate.OneOf([r.value for r in UserRole]))
is_active = fields.Bool(missing=True)
preferred_language = fields.Str(allow_none=True)
created_at = fields.DateTime(dump_only=True)
updated_at = fields.DateTime(dump_only=True)
# Nested fields (when relations are loaded)
favorite_projects = fields.Nested("ProjectSchema", many=True, dump_only=True, allow_none=True)
class UserCreateSchema(Schema):
"""Schema for creating a user"""
username = fields.Str(required=True, validate=validate.Length(min=1, max=100))
email = fields.Email(allow_none=True)
full_name = fields.Str(allow_none=True, validate=validate.Length(max=200))
role = fields.Str(missing=UserRole.USER.value, validate=validate.OneOf([r.value for r in UserRole]))
is_active = fields.Bool(missing=True)
preferred_language = fields.Str(allow_none=True)
class UserUpdateSchema(Schema):
"""Schema for updating a user"""
username = fields.Str(allow_none=True, validate=validate.Length(min=1, max=100))
email = fields.Email(allow_none=True)
full_name = fields.Str(allow_none=True, validate=validate.Length(max=200))
role = fields.Str(allow_none=True, validate=validate.OneOf([r.value for r in UserRole]))
is_active = fields.Bool(allow_none=True)
preferred_language = fields.Str(allow_none=True)