ScoDoc/app/models/formsemestre_descr.py

72 lines
2.2 KiB
Python

##############################################################################
# ScoDoc
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
# See LICENSE
##############################################################################
"""Description d'un formsemestre pour applications tierces.
Ces informations sont éditables dans ScoDoc et publiés sur l'API
pour affichage dans l'application tierce.
"""
from app import db
from app import models
class FormSemestreDescription(models.ScoDocModel):
"""Informations décrivant un "semestre" (session) de formation
pour un apprenant.
"""
__tablename__ = "notes_formsemestre_description"
id = db.Column(db.Integer, primary_key=True)
# Storing image data directly in the database:
image = db.Column(db.LargeBinary(), nullable=True)
description = db.Column(
db.Text(), nullable=False, default="", server_default=""
) # HTML allowed
responsable = db.Column(db.Text(), nullable=False, default="", server_default="")
lieu = db.Column(db.Text(), nullable=False, default="", server_default="")
horaire = db.Column(db.Text(), nullable=False, default="", server_default="")
formsemestre_id = db.Column(
db.Integer,
db.ForeignKey("notes_formsemestre.id", ondelete="CASCADE"),
nullable=False,
)
formsemestre = db.relationship(
"FormSemestre", back_populates="description", uselist=False
)
def __init__(
self,
image=None,
description="",
responsable="",
lieu="",
horaire="",
):
self.description = description
self.horaire = horaire
self.image = image
self.lieu = lieu
self.responsable = responsable
def __repr__(self):
return f"<FormSemestreDescription {self.id} {self.formsemestre}>"
def clone(self, not_copying=()) -> "FormSemestreDescription":
"""clone instance"""
return super().clone(not_copying=not_copying + ("formsemestre_id",))
def to_dict(self):
return {
"formsemestre_id": self.formsemestre_id,
"description": self.description,
"responsable": self.responsable,
"lieu": self.lieu,
"horaire": self.horaire,
}