def accept(self) -> None: if not self.nameLineEdit.text(): GUIUtilities.show_info_message("The name field is required", "info") return if self._value is None: usr_folder = FileUtilities.get_usr_folder() new_folder = FileUtilities.create_new_folder(usr_folder) vo = DatasetVO() ds_folder = os.path.basename(new_folder) vo.folder = ds_folder self._value = vo else: vo = self._value vo.name = self.nameLineEdit.text() vo.description = self.descriptionEditText.toPlainText() # dataset_vo.data_type=self.typeComboBox.currentText() return QDialog.accept(self)
def fetch_all(self): cursor = DatasetEntity.select().dicts().execute() result = [] for ds in list(cursor): vo = DatasetVO() result.append(vo) for k, v in ds.items(): setattr(vo, k, v) return result
def fetch_all_with_size(self): ds = DatasetEntity.alias("ds") m = DatasetEntryEntity.alias("m") query = (ds.select(ds.id, ds.name, ds.data_type, fn.SUM(m.file_size).alias("size")).join( m, JOIN.LEFT_OUTER, on=ds.id == m.dataset_id).group_by(ds.id)) query_results = list(query.dicts().execute()) result = [] for ds in query_results: vo = DatasetVO() result.append(vo) for k, v in ds.items(): setattr(vo, k, v) return result
def save(self, vo: DatasetVO): try: if vo.id is None: now = datetime.now() ds = DatasetEntity.create(name=vo.name, folder=vo.folder, description=vo.description, data_type=vo.data_type, date=now.isoformat()) vo.id = ds.get_id() else: ds = DatasetEntity.get_by_id(vo.id) if ds: ds.name = vo.name ds.description = vo.description ds.save() except IntegrityError as e: print(e)