Skip to content

Commit

Permalink
Configuration Wizard: Add columns export feature
Browse files Browse the repository at this point in the history
This patch adds a feature to export entity columns as csv
  • Loading branch information
pgathogo committed Jul 26, 2024
1 parent 3c6934d commit a49f760
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions stdm/ui/wizard/ui_stdm_config.ui
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,20 @@
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnExport">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down
37 changes: 37 additions & 0 deletions stdm/ui/wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,24 @@ def __init__(self, parent):
self.btnCopy.setIcon(GuiUtils.get_icon('composer_table.png'))
self.btnPDelete.setIcon(GuiUtils.get_icon('remove.png'))
self.btnNewP.setIcon(GuiUtils.get_icon('add.png'))

self.btnNewEntity.setIcon(GuiUtils.get_icon('add.png'))
self.btnEditEntity.setIcon(GuiUtils.get_icon('edit.png'))
self.btnDeleteEntity.setIcon(GuiUtils.get_icon('delete.png'))

self.btnAddColumn.setIcon(GuiUtils.get_icon('add.png'))
self.btnEditColumn.setIcon(GuiUtils.get_icon('edit.png'))
self.btnDeleteColumn.setIcon(GuiUtils.get_icon('delete.png'))
self.btnExport.setIcon(GuiUtils.get_icon('export.png'))

self.btnAddLookup.setIcon(GuiUtils.get_icon('add.png'))
self.btnEditLookup.setIcon(GuiUtils.get_icon('edit.png'))
self.btnDeleteLookup.setIcon(GuiUtils.get_icon('delete.png'))

self.btnAddLkupValue.setIcon(GuiUtils.get_icon('add.png'))
self.btnEditLkupValue.setIcon(GuiUtils.get_icon('edit.png'))
self.btnDeleteLkupValue.setIcon(GuiUtils.get_icon('delete.png'))

self.btn_sp_units_tenure.setIcon(GuiUtils.get_icon('social_tenure.png'))
self.btn_custom_attrs.setIcon(GuiUtils.get_icon('column.png'))

Expand Down Expand Up @@ -602,6 +608,7 @@ def init_column_ctrls_event_handlers(self):
self.btnAddColumn.clicked.connect(self.new_column)
self.btnEditColumn.clicked.connect(self.edit_column)
self.btnDeleteColumn.clicked.connect(self.delete_column)
self.btnExport.clicked.connect(self.export_columns)

def init_lookup_ctrls_event_handlers(self):
"""
Expand Down Expand Up @@ -2599,6 +2606,36 @@ def delete_column(self):
if self.column_has_entity_relation(column):
self.delete_privilege_cache(entity.short_name, column.name)

def export_columns(self):
if len(self.lvEntities.selectedIndexes()) == 0:
self.show_message(QApplication.translate("Configuration Wizard", \
"No entity selected to export columns!"))
return
model_item, entity, row_id = self.get_model_entity(self.lvEntities)
entity_item_model = self.lvEntities.selectionModel()
view_model = entity_item_model.currentIndex().model()
ent_name = view_model.data(view_model.index(row_id, 0))
columns = list(view_model.entity(ent_name).columns.values())
if len(columns) == 0:
return

dest_path, _ = QFileDialog.getSaveFileName(self, self.tr("Configuration"),
ent_name,
"{0} (*.csv)".format(self.tr('Export files')))

if not dest_path:
return

with open(dest_path, 'w') as f:
for column in columns:
if column.user_editable():
data_type_name = column.TYPE_INFO
if column.TYPE_INFO == 'VARCHAR':
data_type_name = f'{data_type_name} ({column.maximum})'
row = f"{column.name},{data_type_name}\n"
f.write(row)
self.show_message("Export done.")

def check_column_dependencies(self, column):
"""
Checks if a columns has dependencies,
Expand Down

0 comments on commit a49f760

Please sign in to comment.