mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-05-19 04:40:32 -05:00
b4486a627f
- 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
66 lines
2.4 KiB
Python
66 lines
2.4 KiB
Python
"""Project template model for reusable project configurations"""
|
|
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
|
|
from app import db
|
|
|
|
|
|
class ProjectTemplate(db.Model):
|
|
"""Template for creating projects with pre-configured settings"""
|
|
|
|
__tablename__ = "project_templates"
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
name = db.Column(db.String(200), nullable=False, index=True)
|
|
description = db.Column(db.Text, nullable=True)
|
|
|
|
# Template configuration (JSON)
|
|
# Contains: client_id (optional), description, billable, hourly_rate,
|
|
# billing_ref, code, estimated_hours, budget_amount, budget_threshold_percent
|
|
config = db.Column(db.JSON, nullable=False, default=dict)
|
|
|
|
# Template tasks (JSON array of task configurations)
|
|
# Each task: {name, description, priority, status, estimated_hours}
|
|
tasks = db.Column(db.JSON, nullable=True, default=list)
|
|
|
|
# Template categories/tags
|
|
category = db.Column(db.String(100), nullable=True, index=True)
|
|
tags = db.Column(db.JSON, nullable=True, default=list)
|
|
|
|
# Visibility
|
|
is_public = db.Column(db.Boolean, default=False, nullable=False, index=True)
|
|
created_by = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False, index=True)
|
|
|
|
# Usage statistics
|
|
usage_count = db.Column(db.Integer, default=0, nullable=False)
|
|
last_used_at = db.Column(db.DateTime, nullable=True)
|
|
|
|
# Metadata
|
|
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
# Relationships
|
|
creator = db.relationship("User", backref="project_templates")
|
|
|
|
def __repr__(self):
|
|
return f"<ProjectTemplate {self.name}>"
|
|
|
|
def to_dict(self):
|
|
"""Convert template to dictionary"""
|
|
return {
|
|
"id": self.id,
|
|
"name": self.name,
|
|
"description": self.description,
|
|
"config": self.config or {},
|
|
"tasks": self.tasks or [],
|
|
"category": self.category,
|
|
"tags": self.tags or [],
|
|
"is_public": self.is_public,
|
|
"created_by": self.created_by,
|
|
"usage_count": self.usage_count,
|
|
"last_used_at": self.last_used_at.isoformat() if self.last_used_at else None,
|
|
"created_at": self.created_at.isoformat(),
|
|
"updated_at": self.updated_at.isoformat(),
|
|
}
|