From 13b954d5804b53be96941997a5bc94cc16cbeffd Mon Sep 17 00:00:00 2001 From: Youcef AOUAD Date: Wed, 22 May 2024 16:13:18 +0200 Subject: [PATCH] work 3 --- src/Model/OutputKpAdists/OutputKpAdists.py | 44 +++++++++++++++ .../OutputKpAdists/OutputKpListAdists.py | 56 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 src/Model/OutputKpAdists/OutputKpListAdists.py diff --git a/src/Model/OutputKpAdists/OutputKpAdists.py b/src/Model/OutputKpAdists/OutputKpAdists.py index c2633757..bb3cc185 100644 --- a/src/Model/OutputKpAdists/OutputKpAdists.py +++ b/src/Model/OutputKpAdists/OutputKpAdists.py @@ -51,6 +51,34 @@ class OutputKpAdists(SQLSubModel): LateralContribution._id_cnt = max( LateralContribution._id_cnt + 1, self.id) + @property + def reach(self): + return self._reach + + @reach.setter + def reach(self, reach_id): + self._reach = reach_id + self._status.modified() + + @property + def kp(self): + return self._kp + + @kp.setter + def kp(self, profile_id): + self._kp = profile_id + self._status.modified() + + @property + def title(self): + return self._title + + @title.setter + def title(self, title): + self._title = title + self._status.modified() + + @classmethod def _db_create(cls, execute): execute(""" @@ -98,6 +126,22 @@ class OutputKpAdists(SQLSubModel): return new + def _db_save(self, execute, data=None): + + sql = ( + "INSERT INTO " + + "OutputKpAdists(id, reach, kp, title " + + "VALUES (" + + f"{self.id}, {self._reach}, " + + f"{self._kp}, '{self._db_format(self._title)}" + + ")" + ) + + execute(sql) + + return True + + diff --git a/src/Model/OutputKpAdists/OutputKpListAdists.py b/src/Model/OutputKpAdists/OutputKpListAdists.py new file mode 100644 index 00000000..331f0837 --- /dev/null +++ b/src/Model/OutputKpAdists/OutputKpListAdists.py @@ -0,0 +1,56 @@ +# OutputKpListAdists.py -- Pamhyr +# Copyright (C) 2024 INRAE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# -*- coding: utf-8 -*- + +from tools import trace, timer + +from Model.Except import NotImplementedMethodeError +from Model.Tools.PamhyrList import PamhyrModelList +from Model.OutputKpAdists.OutputKpAdists import OutputKpAdists + + +class OutputKpAdistsList(PamhyrModelList): + _sub_classes = [OutputKpAdistsList] + + @classmethod + def _db_load(cls, execute, data=None): + new = cls(status=data["status"]) + + new._lst = OutputKpAdists._db_load(execute, data) + + return new + + def _db_save(self, execute, data=None): + ok = True + + # Delete previous data + execute("DELETE FROM OutputKpAdists") + + for sl in self._lst: + ok &= sl._db_save(execute, data) + + return ok + + @property + def OutputKp_List(self): + return self.lst + + def new(self, index): + n = OutputKpAdists(status=self._status) + self.insert(index, n) + self._status.modified() + return n