class UserGroupsModel(TimestampMixinModel, db.Model): # type: ignore """Table de classement des utilisateurs dans des groupes""" __tablename__ = "cor_users_groups" __table_args__ = {"schema": "gnc_core"} id_user_right = db.Column(db.Integer, primary_key=True) id_user = db.Column(db.Integer, db.ForeignKey(UserModel.id_user), nullable=False) id_group = db.Column(db.Integer, db.ForeignKey(GroupsModel.id_group), nullable=False)
class ProgramsModel(TimestampMixinModel, db.Model): """Table des Programmes de GeoNature-citizen""" __tablename__ = "t_programs" __table_args__ = {"schema": "gnc_core"} id_program = db.Column(db.Integer, primary_key=True) unique_id_program = db.Column(UUID(as_uuid=True), default=uuid.uuid4, unique=True, nullable=False) id_project = db.Column(db.Integer, db.ForeignKey(ProjectModel.id_project), nullable=False) title = db.Column(db.String(50), nullable=False) short_desc = db.Column(db.String(200), nullable=False) long_desc = db.Column(db.Text(), nullable=False) form_message = db.Column(db.String(500)) image = db.Column(db.String(250)) logo = db.Column(db.String(250)) id_module = db.Column( db.Integer, ForeignKey(TModules.id_module), nullable=False, default=1, ) module = relationship("TModules") taxonomy_list = db.Column(db.Integer, nullable=True) is_active = db.Column(db.Boolean(), server_default=expression.true(), default=True) id_geom = db.Column(db.Integer, db.ForeignKey(GeometryModel.id_geom), nullable=False) id_form = db.Column(db.Integer, db.ForeignKey(CustomFormModel.id_form), nullable=True) custom_form = relationship("CustomFormModel") geometry = relationship("GeometryModel") project = relationship("ProjectModel") def get_geofeature(self, recursif=True, columns=None): geometry = to_shape(self.geometry.geom) feature = Feature( id=self.id_program, geometry=geometry, properties=self.as_dict(True, exclude=["t_obstax"]), ) return feature def __repr__(self): return self.title
class LiMunicipalities(db.Model): # type: ignore __tablename__ = "li_municipalities" __table_args__ = {"schema": "ref_geo"} id_municipality = db.Column(db.Unicode, primary_key=True, unique=True) nom_com = db.Column(db.Unicode) id_area = db.Column( db.Integer, db.ForeignKey("ref_geo.l_areas.id_area"), unique=True ) insee_com = db.Column(db.Integer)
class ObservationMediaModel( TimestampMixinModel, db.Model # type: ignore ): """Table de correspondances des médias (photos) avec les observations""" __tablename__ = "cor_obstax_media" __table_args__ = {"schema": "gnc_obstax"} id_match = db.Column(db.Integer, primary_key=True, unique=True) id_data_source = db.Column( db.Integer, db.ForeignKey(ObservationModel.id_observation, ondelete="CASCADE"), nullable=False, ) id_media = db.Column( db.Integer, db.ForeignKey(MediaModel.id_media, ondelete="CASCADE"), nullable=False, )
class UserRightsModel(TimestampMixinModel, db.Model): # type: ignore """Table de gestion des droits des utilisateurs de GeoNature-citizen""" __tablename__ = "t_users_rights" __table_args__ = {"schema": "gnc_core"} id_user_right = db.Column(db.Integer, primary_key=True) id_user = db.Column(db.Integer, db.ForeignKey(UserModel.id_user), nullable=False) id_module = db.Column(db.Integer, db.ForeignKey(ModulesModel.id_module), nullable=True) id_module = db.Column(db.Integer, db.ForeignKey(ProgramsModel.id_program), nullable=True) right = db.Column(db.String(150), nullable=False) create = db.Column(db.Boolean(), default=False) read = db.Column(db.Boolean(), default=False) update = db.Column(db.Boolean(), default=False) delete = db.Column(db.Boolean(), default=False)
class LAreas(db.Model): # type: ignore __tablename__ = "l_areas" __table_args__ = {"schema": "ref_geo"} id_area = db.Column(db.Integer, primary_key=True) id_type = db.Column( db.Integer, db.ForeignKey("ref_geo.bib_areas_types.id_type") ) area_name = db.Column(db.Unicode) area_code = db.Column(db.Unicode) source = db.Column(db.Unicode) enable = db.Column(db.Boolean) geom = db.Column(Geometry("GEOMETRY", 4326)) def get_geofeature(self, recursive=True): return self.as_geofeature("geom", "id_area", recursive)
class ObservationModel( ObserverMixinModel, TimestampMixinModel, db.Model # type: ignore ): """Table des observations""" __tablename__ = "t_obstax" __table_args__ = {"schema": "gnc_obstax"} id_observation = db.Column(db.Integer, primary_key=True, unique=True) uuid_sinp = db.Column(UUID(as_uuid=True), nullable=False, unique=True) id_program = db.Column(db.Integer, db.ForeignKey(ProgramsModel.id_program), nullable=False) cd_nom = db.Column( db.Integer, db.ForeignKey(Taxref.cd_nom), # todo: removal breaks recog rewards nullable=False, ) date = db.Column(db.Date, nullable=False) count = db.Column(db.Integer) comment = db.Column(db.String(300)) municipality = db.Column(db.Integer, db.ForeignKey(LAreas.id_area)) geom = db.Column(Geometry("POINT", 4326))
def id_role(self): return db.Column( db.Integer, db.ForeignKey(UserModel.id_user, ondelete="SET NULL"), nullable=True, )