add license

This commit is contained in:
Alejandro Vazquez
2026-03-26 10:14:40 -03:00
commit 48bace5167
29 changed files with 2802 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
from app import db
from datetime import datetime
class Classroom(db.Model):
__tablename__ = 'classrooms'
id = db.Column(db.Integer, primary_key=True)
code = db.Column(db.String(20), unique=True, nullable=False, index=True)
name = db.Column(db.String(100), nullable=False)
building = db.Column(db.String(50), nullable=False)
floor = db.Column(db.Integer, nullable=False)
capacity = db.Column(db.Integer, nullable=False)
description = db.Column(db.Text)
campus_location = db.Column(db.String(50), default='Main Campus')
is_active = db.Column(db.Boolean, default=True, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Relationships
reservations = db.relationship('Reservation', backref='classroom', lazy=True, cascade='all, delete-orphan')
# Resources relationship (教室资源)
resources = db.relationship('ClassroomResource', backref='classroom', lazy=True, cascade='all, delete-orphan')
def to_dict(self):
"""Convert classroom to dictionary"""
return {
'id': self.id,
'code': self.code,
'name': self.name,
'building': self.building,
'floor': self.floor,
'capacity': self.capacity,
'description': self.description,
'campus_location': self.campus_location,
'is_active': self.is_active,
'created_at': self.created_at.isoformat() if self.created_at else None,
'updated_at': self.updated_at.isoformat() if self.updated_at else None,
'resources': [resource.to_dict() for resource in self.resources]
}
def get_full_location(self):
"""Get full classroom location"""
return f"{self.building} - Floor {self.floor}"
def __repr__(self):
return f'<Classroom {self.code}>'
class ClassroomResource(db.Model):
__tablename__ = 'classroom_resources'
id = db.Column(db.Integer, primary_key=True)
classroom_id = db.Column(db.Integer, db.ForeignKey('classrooms.id'), nullable=False)
resource_type = db.Column(db.String(50), nullable=False) # PROJECTOR, WHITEBOARD, COMPUTER, etc.
brand = db.Column(db.String(100))
model = db.Column(db.String(100))
specifications = db.Column(db.Text)
quantity = db.Column(db.Integer, default=1)
is_functional = db.Column(db.Boolean, default=True)
last_maintenance = db.Column(db.DateTime)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
def to_dict(self):
"""Convert resource to dictionary"""
return {
'id': self.id,
'classroom_id': self.classroom_id,
'resource_type': self.resource_type,
'brand': self.brand,
'model': self.model,
'specifications': self.specifications,
'quantity': self.quantity,
'is_functional': self.is_functional,
'last_maintenance': self.last_maintenance.isoformat() if self.last_maintenance else None,
'created_at': self.created_at.isoformat() if self.created_at else None
}
def __repr__(self):
return f'<Resource {self.resource_type} for Classroom {self.classroom_id}>'