|
|
|
@@ -88,47 +88,47 @@ class KontorDB:
|
|
|
|
|
result = [table.table_name for table in tables]
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def get_table_by_name(self, table_name: str) -> dict:
|
|
|
|
|
result = {}
|
|
|
|
|
__session__ = sessionmaker(self.engine)
|
|
|
|
|
_filter = {'table_name': table_name}
|
|
|
|
|
with __session__() as session:
|
|
|
|
|
table = session.query(MetaDataTable).filter_by(**_filter).one()
|
|
|
|
|
result['id'] = table.id
|
|
|
|
|
result['table_name'] = table.table_name
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def get_column_meta_data(self, table_name: str, view_only=True) -> dict:
|
|
|
|
|
meta_data = {}
|
|
|
|
|
order = 0
|
|
|
|
|
__session__ = sessionmaker(self.engine)
|
|
|
|
|
columns = list()
|
|
|
|
|
table_info = self.get_table_by_name(table_name)
|
|
|
|
|
_filters = {'table_id': table_info['id']}
|
|
|
|
|
if view_only:
|
|
|
|
|
_filters['is_shown'] = True
|
|
|
|
|
with __session__() as session:
|
|
|
|
|
if view_only:
|
|
|
|
|
for (_, column) in (session.query(MetaDataTable, MetaDataColumn).
|
|
|
|
|
filter(MetaDataTable.id == MetaDataColumn.table_id).
|
|
|
|
|
filter(MetaDataTable.table_name == table_name).
|
|
|
|
|
filter(MetaDataColumn.is_shown == 1).all()):
|
|
|
|
|
# self.log.info("get_column_meta_data: %s %s %d", column.column_name, column.column_label, column.column_order)
|
|
|
|
|
meta_data[order] = {
|
|
|
|
|
ColumnEntry.COLUMN_NAME: column.column_name,
|
|
|
|
|
ColumnEntry.COLUMN_LABEL: column.column_label,
|
|
|
|
|
ColumnEntry.COLUMN_ORDER: column.column_order,
|
|
|
|
|
ColumnEntry.COLUMN_REF_COLUMN: column.ref_column,
|
|
|
|
|
ColumnEntry.COLUMN_TYPE: column.column_type
|
|
|
|
|
}
|
|
|
|
|
order += 1
|
|
|
|
|
else:
|
|
|
|
|
for (_, column) in (session.query(MetaDataTable, MetaDataColumn).
|
|
|
|
|
filter(MetaDataTable.id == MetaDataColumn.table_id).
|
|
|
|
|
filter(MetaDataTable.table_name == table_name).all()):
|
|
|
|
|
meta_data[order] = {
|
|
|
|
|
ColumnEntry.COLUMN_NAME: column.column_name,
|
|
|
|
|
ColumnEntry.COLUMN_ORDER: column.column_order,
|
|
|
|
|
ColumnEntry.COLUMN_REF_COLUMN: column.ref_column,
|
|
|
|
|
ColumnEntry.COLUMN_TYPE: column.column_type
|
|
|
|
|
}
|
|
|
|
|
order += 1
|
|
|
|
|
# self.log.info("get_column_meta_data: %s", meta_data)
|
|
|
|
|
columns = session.query(MetaDataColumn).filter_by(**_filters).all()
|
|
|
|
|
for column in columns:
|
|
|
|
|
# self.log.info("get_column_meta_data: %s %s %d", column.column_name, column.column_label, column.column_order)
|
|
|
|
|
meta_data[order] = {
|
|
|
|
|
ColumnEntry.COLUMN_NAME: column.column_name,
|
|
|
|
|
ColumnEntry.COLUMN_LABEL: column.column_label,
|
|
|
|
|
ColumnEntry.COLUMN_ORDER: column.column_order,
|
|
|
|
|
ColumnEntry.COLUMN_REF_COLUMN: column.ref_column,
|
|
|
|
|
ColumnEntry.COLUMN_TYPE: column.column_type
|
|
|
|
|
}
|
|
|
|
|
order += 1
|
|
|
|
|
return meta_data
|
|
|
|
|
|
|
|
|
|
def get_columns(self, table_name: str) -> dict:
|
|
|
|
|
columns = {}
|
|
|
|
|
order = 0
|
|
|
|
|
__session__ = sessionmaker(self.engine)
|
|
|
|
|
table_info = self.get_table_by_name(table_name)
|
|
|
|
|
_filters = {'table_id': table_info['id']}
|
|
|
|
|
with __session__() as session:
|
|
|
|
|
for (_, column) in (session.query(MetaDataTable, MetaDataColumn).
|
|
|
|
|
filter(MetaDataTable.id == MetaDataColumn.table_id).
|
|
|
|
|
filter(MetaDataTable.table_name == table_name).all()):
|
|
|
|
|
for column in session.query(MetaDataColumn).filter_by(**_filters).all():
|
|
|
|
|
columns[column.column_name] = {
|
|
|
|
|
ColumnEntry.COLUMN_ORDER: column.column_order,
|
|
|
|
|
ColumnEntry.COLUMN_TYPE: column.column_type
|
|
|
|
@@ -138,11 +138,10 @@ class KontorDB:
|
|
|
|
|
def get_filters(self, table_name: str) -> dict:
|
|
|
|
|
_filter_map = {}
|
|
|
|
|
__session__ = sessionmaker(self.engine)
|
|
|
|
|
table_info = self.get_table_by_name(table_name)
|
|
|
|
|
_filters = {'table_id': table_info['id'], 'show_filter': True}
|
|
|
|
|
with __session__() as session:
|
|
|
|
|
for (_, column) in (session.query(MetaDataTable, MetaDataColumn).
|
|
|
|
|
filter(MetaDataTable.id == MetaDataColumn.table_id).
|
|
|
|
|
filter(MetaDataTable.table_name == table_name).
|
|
|
|
|
filter(MetaDataColumn.show_filter == 1).all()):
|
|
|
|
|
for column in session.query(MetaDataColumn).filter_by(**_filters).all():
|
|
|
|
|
_filter_map[column.column_name] = {
|
|
|
|
|
ColumnEntry.COLUMN_LABEL: column.filter_label,
|
|
|
|
|
ColumnEntry.COLUMN_WIDGET: None
|
|
|
|
@@ -342,8 +341,9 @@ class KontorDB:
|
|
|
|
|
def update_titles(self) -> dict:
|
|
|
|
|
update_list = {}
|
|
|
|
|
__session__ = sessionmaker(self.engine)
|
|
|
|
|
_filter = { 'review': True}
|
|
|
|
|
with __session__() as session:
|
|
|
|
|
links = session.query(MediaFile).filter(MediaFile.review == 1).all()
|
|
|
|
|
links = session.query(MediaFile).filter_by(**_filter).all()
|
|
|
|
|
for link in links:
|
|
|
|
|
url = link.url
|
|
|
|
|
if url is None:
|
|
|
|
@@ -356,8 +356,9 @@ class KontorDB:
|
|
|
|
|
def get_download_list(self) -> list:
|
|
|
|
|
download_list = []
|
|
|
|
|
__session__ = sessionmaker(self.engine)
|
|
|
|
|
_filter = { 'should_download': True}
|
|
|
|
|
with __session__() as session:
|
|
|
|
|
links = session.query(MediaFile).filter(MediaFile.should_download == 1).all()
|
|
|
|
|
links = session.query(MediaFile).filter_by(**_filter).all()
|
|
|
|
|
for link in links:
|
|
|
|
|
url = link.url
|
|
|
|
|
if url is None:
|
|
|
|
|