flake8 metabase
This commit is contained in:
parent
fd5d516f14
commit
d7267c0542
@ -4,14 +4,13 @@ __email__ = "info@3liz.org"
|
|||||||
|
|
||||||
|
|
||||||
from qgis.core import QgsApplication
|
from qgis.core import QgsApplication
|
||||||
from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator, QUrl
|
from qgis.PyQt.QtCore import Qt, QUrl, QSettings
|
||||||
from qgis.PyQt.QtGui import QDesktopServices, QIcon
|
from qgis.PyQt.QtGui import QDesktopServices, QIcon
|
||||||
from qgis.PyQt.QtWidgets import QAction, QMessageBox
|
from qgis.PyQt.QtWidgets import QAction
|
||||||
from qgis.utils import iface
|
from qgis.utils import iface
|
||||||
import qgis
|
import qgis
|
||||||
|
|
||||||
|
# include <QSettings>
|
||||||
#include <QSettings>
|
|
||||||
'''
|
'''
|
||||||
from pg_metadata.connection_manager import (
|
from pg_metadata.connection_manager import (
|
||||||
store_connections,
|
store_connections,
|
||||||
@ -24,8 +23,9 @@ from pg_metadata.processing.provider import PgMetadataProvider
|
|||||||
from pg_metadata.qgis_plugin_tools.tools.custom_logging import setup_logger
|
from pg_metadata.qgis_plugin_tools.tools.custom_logging import setup_logger
|
||||||
'''
|
'''
|
||||||
import os
|
import os
|
||||||
|
from .about_form import MetabaseAboutDialog
|
||||||
from .tools.resources import (
|
from .tools.resources import (
|
||||||
plugin_path,
|
# plugin_path,
|
||||||
pyperclip,
|
pyperclip,
|
||||||
resources_path,
|
resources_path,
|
||||||
maj_verif,
|
maj_verif,
|
||||||
@ -33,10 +33,8 @@ from .tools.resources import (
|
|||||||
pyperclip()
|
pyperclip()
|
||||||
from .dock import CenRa_Metabase
|
from .dock import CenRa_Metabase
|
||||||
from .editor import Metabase_Editor
|
from .editor import Metabase_Editor
|
||||||
from .about_form import MetabaseAboutDialog
|
|
||||||
#from CenRa_Metabase.issues import CenRa_Issues
|
|
||||||
|
|
||||||
from qgis.PyQt.QtCore import *
|
# from CenRa_Metabase.issues import CenRa_Issues
|
||||||
|
|
||||||
|
|
||||||
class PgMetadata:
|
class PgMetadata:
|
||||||
@ -50,42 +48,42 @@ class PgMetadata:
|
|||||||
self.dock_action = None
|
self.dock_action = None
|
||||||
self.help_action = None
|
self.help_action = None
|
||||||
plugin_dir = os.path.dirname(__file__)
|
plugin_dir = os.path.dirname(__file__)
|
||||||
end_find = plugin_dir.rfind('\\')+1
|
end_find = plugin_dir.rfind('\\') + 1
|
||||||
global NAME
|
global NAME
|
||||||
NAME = plugin_dir[end_find:]
|
NAME = plugin_dir[end_find:]
|
||||||
maj_verif(NAME)
|
maj_verif(NAME)
|
||||||
|
|
||||||
# Display About window on first use
|
# Display About window on first use
|
||||||
version = qgis.utils.pluginMetadata('CenRa_METABASE','version')
|
version = qgis.utils.pluginMetadata('CenRa_METABASE', 'version')
|
||||||
s = QSettings()
|
s = QSettings()
|
||||||
versionUse = s.value("metadata/version", 1, type=str)
|
versionUse = s.value("metadata/version", 1, type=str)
|
||||||
if str(versionUse) != str(version) :
|
if str(versionUse) != str(version):
|
||||||
s.setValue("metadata/version", str(version))
|
s.setValue("metadata/version", str(version))
|
||||||
print(versionUse,version)
|
print(versionUse, version)
|
||||||
self.open_about_dialog()
|
self.open_about_dialog()
|
||||||
# setup_logger('pg_metadata')
|
# setup_logger('pg_metadata')
|
||||||
|
|
||||||
#locale, file_path = setup_translation(
|
# locale, file_path = setup_translation(
|
||||||
# folder=plugin_path("i18n"), file_pattern="CenRa_Metabase_{}.qm")
|
# folder=plugin_path("i18n"), file_pattern="CenRa_Metabase_{}.qm")
|
||||||
#if file_path:
|
# if file_path:
|
||||||
# self.translator = QTranslator()
|
# self.translator = QTranslator()
|
||||||
# self.translator.load(file_path)
|
# self.translator.load(file_path)
|
||||||
# noinspection PyCallByClass,PyArgumentList
|
# noinspection PyCallByClass,PyArgumentList
|
||||||
# QCoreApplication.installTranslator(self.translator)
|
# QCoreApplication.installTranslator(self.translator)
|
||||||
|
|
||||||
# noinspection PyPep8Naming
|
# noinspection PyPep8Naming
|
||||||
#def initProcessing(self):
|
# def initProcessing(self):
|
||||||
#""" Add the QGIS Processing provider. """
|
# """ Add the QGIS Processing provider. """
|
||||||
#if not self.provider:
|
# if not self.provider:
|
||||||
#self.provider = PgMetadataProvider()
|
# self.provider = PgMetadataProvider()
|
||||||
#QgsApplication.processingRegistry().addProvider(self.provider)
|
# QgsApplication.processingRegistry().addProvider(self.provider)
|
||||||
|
|
||||||
# noinspection PyPep8Naming
|
# noinspection PyPep8Naming
|
||||||
def initGui(self):
|
def initGui(self):
|
||||||
""" Build the plugin GUI. """
|
""" Build the plugin GUI. """
|
||||||
#self.initProcessing()
|
# self.initProcessing()
|
||||||
|
|
||||||
#self.check_invalid_connection_names()
|
# self.check_invalid_connection_names()
|
||||||
|
|
||||||
self.toolBar = iface.addToolBar("CenRa_Metabase")
|
self.toolBar = iface.addToolBar("CenRa_Metabase")
|
||||||
self.toolBar.setObjectName("CenRa_Metabase")
|
self.toolBar.setObjectName("CenRa_Metabase")
|
||||||
@ -100,8 +98,7 @@ class PgMetadata:
|
|||||||
if not self.editor:
|
if not self.editor:
|
||||||
self.editor = Metabase_Editor()
|
self.editor = Metabase_Editor()
|
||||||
|
|
||||||
|
self.editor_action = QAction(icon2, 'CenRa_Metabase', None)
|
||||||
self.editor_action = QAction(icon2, 'CenRa_Metabase',None)
|
|
||||||
self.toolBar.addAction(self.editor_action)
|
self.toolBar.addAction(self.editor_action)
|
||||||
self.editor_action.triggered.connect(self.open_editor)
|
self.editor_action.triggered.connect(self.open_editor)
|
||||||
|
|
||||||
@ -159,6 +156,7 @@ class PgMetadata:
|
|||||||
"""
|
"""
|
||||||
dialog = MetabaseAboutDialog(iface)
|
dialog = MetabaseAboutDialog(iface)
|
||||||
dialog.exec()
|
dialog.exec()
|
||||||
|
|
||||||
def open_help():
|
def open_help():
|
||||||
""" Open the online help. """
|
""" Open the online help. """
|
||||||
QDesktopServices.openUrl(QUrl('https://plateformesig.cenra-outils.org/'))
|
QDesktopServices.openUrl(QUrl('https://plateformesig.cenra-outils.org/'))
|
||||||
@ -178,9 +176,9 @@ class PgMetadata:
|
|||||||
|
|
||||||
def unload(self):
|
def unload(self):
|
||||||
""" Unload the plugin. """
|
""" Unload the plugin. """
|
||||||
#if self.editor:
|
# if self.editor:
|
||||||
#iface.removePluginMenu('CenRa_Metabase',self.editor_action)
|
# iface.removePluginMenu('CenRa_Metabase',self.editor_action)
|
||||||
#self.editor.removeToolBarIcon(self.editor_action)
|
# self.editor.removeToolBarIcon(self.editor_action)
|
||||||
|
|
||||||
if self.dock:
|
if self.dock:
|
||||||
iface.removeDockWidget(self.dock)
|
iface.removeDockWidget(self.dock)
|
||||||
@ -202,7 +200,6 @@ class PgMetadata:
|
|||||||
iface.pluginMenu().removeAction(self.dock_action)
|
iface.pluginMenu().removeAction(self.dock_action)
|
||||||
del self.dock_action
|
del self.dock_action
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run_tests(pattern='test_*.py', package=None):
|
def run_tests(pattern='test_*.py', package=None):
|
||||||
"""Run the test inside QGIS."""
|
"""Run the test inside QGIS."""
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import os.path
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from qgis.PyQt import uic
|
from qgis.PyQt import uic
|
||||||
from qgis.PyQt.QtGui import QPixmap
|
# from qgis.PyQt.QtGui import QPixmap
|
||||||
from qgis.PyQt.QtWidgets import QDialog
|
from qgis.PyQt.QtWidgets import QDialog
|
||||||
|
|
||||||
from .tools.resources import devlog
|
from .tools.resources import devlog
|
||||||
@ -16,6 +16,7 @@ ABOUT_FORM_CLASS, _ = uic.loadUiType(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class MetabaseAboutDialog(QDialog, ABOUT_FORM_CLASS):
|
class MetabaseAboutDialog(QDialog, ABOUT_FORM_CLASS):
|
||||||
|
|
||||||
""" About - Let the user display the about dialog. """
|
""" About - Let the user display the about dialog. """
|
||||||
|
|||||||
@ -14,48 +14,31 @@ from pathlib import Path
|
|||||||
from xml.dom.minidom import parseString
|
from xml.dom.minidom import parseString
|
||||||
|
|
||||||
from qgis.core import (
|
from qgis.core import (
|
||||||
NULL,
|
|
||||||
QgsApplication,
|
QgsApplication,
|
||||||
QgsDataSourceUri,
|
|
||||||
QgsProject,
|
|
||||||
QgsProviderConnectionException,
|
|
||||||
QgsProviderRegistry,
|
QgsProviderRegistry,
|
||||||
QgsRasterLayer,
|
|
||||||
QgsSettings,
|
QgsSettings,
|
||||||
QgsVectorLayer,
|
|
||||||
)
|
)
|
||||||
from qgis.PyQt.QtCore import QLocale, QUrl
|
from qgis.PyQt.QtCore import QLocale, QUrl
|
||||||
from qgis.PyQt.QtGui import QDesktopServices, QIcon
|
from qgis.PyQt.QtGui import QDesktopServices, QIcon
|
||||||
from qgis.PyQt.QtPrintSupport import QPrinter
|
from qgis.PyQt.QtPrintSupport import QPrinter
|
||||||
#from qgis.PyQt.QtWebKitWidgets import QWebPage
|
# from qgis.PyQt.QtWebKitWidgets import QWebPage
|
||||||
from qgis.PyQt.QtWidgets import (
|
from qgis.PyQt.QtWidgets import (
|
||||||
QDialog,
|
|
||||||
QAction,
|
QAction,
|
||||||
QDockWidget,
|
QDockWidget,
|
||||||
QFileDialog,
|
QFileDialog,
|
||||||
QInputDialog,
|
|
||||||
QMenu,
|
QMenu,
|
||||||
QToolButton,
|
QToolButton,
|
||||||
)
|
)
|
||||||
from qgis.gui import *
|
|
||||||
from qgis.utils import iface
|
from qgis.utils import iface
|
||||||
import qgis
|
import qgis
|
||||||
'''
|
|
||||||
from pg_metadata.connection_manager import (
|
|
||||||
check_pgmetadata_is_installed,
|
|
||||||
connections_list,
|
|
||||||
settings_connections_names,
|
|
||||||
)
|
|
||||||
'''
|
|
||||||
try:
|
|
||||||
from .tools.PythonSQL import login_base
|
|
||||||
except:
|
|
||||||
print('Pas de fichier PythonSQL')
|
|
||||||
|
|
||||||
from .tools.resources import (
|
from .tools.resources import (
|
||||||
load_ui,
|
load_ui,
|
||||||
resources_path,
|
resources_path,
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
from .tools.PythonSQL import login_base
|
||||||
|
except ValueError:
|
||||||
|
print('Pas de fichier PythonSQL')
|
||||||
|
|
||||||
DOCK_CLASS = load_ui('CenRa_Metabase_dockwidget_base.ui')
|
DOCK_CLASS = load_ui('CenRa_Metabase_dockwidget_base.ui')
|
||||||
LOGGER = logging.getLogger('CenRa_Metabase')
|
LOGGER = logging.getLogger('CenRa_Metabase')
|
||||||
@ -84,8 +67,8 @@ class CenRa_Metabase(QDockWidget, DOCK_CLASS):
|
|||||||
self.current_datasource_uri = None
|
self.current_datasource_uri = None
|
||||||
self.current_connection = None
|
self.current_connection = None
|
||||||
|
|
||||||
#self.viewer.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
|
# self.viewer.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
|
||||||
#self.viewer.page().linkClicked.connect(self.open_link)
|
# self.viewer.page().linkClicked.connect(self.open_link)
|
||||||
|
|
||||||
# Help button
|
# Help button
|
||||||
self.external_help.setText('')
|
self.external_help.setText('')
|
||||||
@ -94,13 +77,13 @@ class CenRa_Metabase(QDockWidget, DOCK_CLASS):
|
|||||||
|
|
||||||
# Flat table button
|
# Flat table button
|
||||||
self.flatten_dataset_table.setText('')
|
self.flatten_dataset_table.setText('')
|
||||||
#self.flatten_dataset_table.setToolTip(tr("Add the catalog table"))
|
# self.flatten_dataset_table.setToolTip(tr("Add the catalog table"))
|
||||||
self.flatten_dataset_table.setIcon(QgsApplication.getThemeIcon("/mActionAddHtml.svg"))
|
self.flatten_dataset_table.setIcon(QgsApplication.getThemeIcon("/mActionAddHtml.svg"))
|
||||||
#self.flatten_dataset_table.clicked.connect(self.add_flatten_dataset_table)
|
# self.flatten_dataset_table.clicked.connect(self.add_flatten_dataset_table)
|
||||||
|
|
||||||
# Settings menu
|
# Settings menu
|
||||||
self.config.setAutoRaise(True)
|
self.config.setAutoRaise(True)
|
||||||
#self.config.setToolTip(tr("Settings"))
|
# self.config.setToolTip(tr("Settings"))
|
||||||
self.config.setPopupMode(QToolButton.ToolButtonPopupMode(2))
|
self.config.setPopupMode(QToolButton.ToolButtonPopupMode(2))
|
||||||
self.config.setIcon(QgsApplication.getThemeIcon("/mActionOptions.svg"))
|
self.config.setIcon(QgsApplication.getThemeIcon("/mActionOptions.svg"))
|
||||||
|
|
||||||
@ -118,7 +101,7 @@ class CenRa_Metabase(QDockWidget, DOCK_CLASS):
|
|||||||
|
|
||||||
# Setting PDF/HTML menu
|
# Setting PDF/HTML menu
|
||||||
self.save_button.setAutoRaise(True)
|
self.save_button.setAutoRaise(True)
|
||||||
#self.save_button.setToolTip(tr("Save metadata"))
|
# self.save_button.setToolTip(tr("Save metadata"))
|
||||||
self.save_button.setPopupMode(QToolButton.ToolButtonPopupMode(2))
|
self.save_button.setPopupMode(QToolButton.ToolButtonPopupMode(2))
|
||||||
self.save_button.setIcon(QIcon(QgsApplication.iconPath('mActionFileSave.svg')))
|
self.save_button.setIcon(QIcon(QgsApplication.iconPath('mActionFileSave.svg')))
|
||||||
|
|
||||||
@ -146,21 +129,21 @@ class CenRa_Metabase(QDockWidget, DOCK_CLASS):
|
|||||||
self.metadata = QgsProviderRegistry.instance().providerMetadata('postgres')
|
self.metadata = QgsProviderRegistry.instance().providerMetadata('postgres')
|
||||||
|
|
||||||
# Display message in the dock
|
# Display message in the dock
|
||||||
#if not settings_connections_names():
|
# if not settings_connections_names():
|
||||||
#self.default_html_content_not_installed()
|
# self.default_html_content_not_installed()
|
||||||
#else:
|
# else:
|
||||||
self.default_html_content_not_pg_layer()
|
self.default_html_content_not_pg_layer()
|
||||||
|
iface.layerTreeView().currentLayerChanged.connect(self.layer_changed)
|
||||||
try:
|
try:
|
||||||
login_base()
|
login_base()
|
||||||
iface.layerTreeView().currentLayerChanged.connect(self.layer_changed)
|
iface.layerTreeView().currentLayerChanged.connect(self.layer_changed)
|
||||||
except:
|
except ValueError:
|
||||||
#qgis.utils.plugins['CenRa_METABASE'].initGui()
|
# qgis.utils.plugins['CenRa_METABASE'].initGui()
|
||||||
qgis.utils.plugins['CenRa_METABASE'].unload()
|
qgis.utils.plugins['CenRa_METABASE'].unload()
|
||||||
#self.default_html_content_not_pg_layer()
|
# self.default_html_content_not_pg_layer()
|
||||||
|
|
||||||
if iface.activeLayer():
|
if iface.activeLayer():
|
||||||
layer=iface.activeLayer()
|
layer = iface.activeLayer()
|
||||||
iface.layerTreeView().setCurrentLayer(None)
|
iface.layerTreeView().setCurrentLayer(None)
|
||||||
iface.layerTreeView().setCurrentLayer(layer)
|
iface.layerTreeView().setCurrentLayer(layer)
|
||||||
|
|
||||||
@ -192,7 +175,7 @@ class CenRa_Metabase(QDockWidget, DOCK_CLASS):
|
|||||||
if output_format == OutputFormats.PDF:
|
if output_format == OutputFormats.PDF:
|
||||||
printer = QPrinter()
|
printer = QPrinter()
|
||||||
printer.setOutputFormat(QPrinter.OutputFormat(1))
|
printer.setOutputFormat(QPrinter.OutputFormat(1))
|
||||||
#printer.setPageMargins(20,20,20,20,QPrinter.Unit(0))
|
# printer.setPageMargins(20,20,20,20,QPrinter.Unit(0))
|
||||||
printer.setOutputFileName(output_file_path)
|
printer.setOutputFileName(output_file_path)
|
||||||
self.viewer.print(printer)
|
self.viewer.print(printer)
|
||||||
iface.messageBar().pushSuccess(
|
iface.messageBar().pushSuccess(
|
||||||
@ -202,7 +185,7 @@ class CenRa_Metabase(QDockWidget, DOCK_CLASS):
|
|||||||
"<a href=\"{}\">{}</a>").format(parent_folder, output_file_path)
|
"<a href=\"{}\">{}</a>").format(parent_folder, output_file_path)
|
||||||
)
|
)
|
||||||
|
|
||||||
elif output_format in [OutputFormats.HTML,OutputFormats.DCAT]:
|
elif output_format in [OutputFormats.HTML, OutputFormats.DCAT]:
|
||||||
if output_format == OutputFormats.HTML:
|
if output_format == OutputFormats.HTML:
|
||||||
data_str = self.viewer.page().currentFrame().toHtml()
|
data_str = self.viewer.page().currentFrame().toHtml()
|
||||||
else:
|
else:
|
||||||
@ -231,43 +214,15 @@ class CenRa_Metabase(QDockWidget, DOCK_CLASS):
|
|||||||
def save_auto_open_dock(self):
|
def save_auto_open_dock(self):
|
||||||
""" Save settings about the dock. """
|
""" Save settings about the dock. """
|
||||||
self.settings.setValue("pgmetadata/auto_open_dock", self.auto_open_dock_action.isChecked())
|
self.settings.setValue("pgmetadata/auto_open_dock", self.auto_open_dock_action.isChecked())
|
||||||
def sql_to_xml(self,dataall):
|
|
||||||
distribution=''
|
def sql_to_xml(self, dataall):
|
||||||
|
distribution = ''
|
||||||
for y in dataall[1]:
|
for y in dataall[1]:
|
||||||
distribution = distribution + (
|
distribution = distribution + ('<dcat:distribution>' + '<dcat:Distribution>' + '<dct:title>{data}</dct:title>'.format(data=y[0]) + '<dcat:downloadURL>{data}</dcat:downloadURL>'.format(data=y[1]) + '<dcat:mediaType>{data}</dcat:mediaType>'.format(data=y[2]) + '<dct:format>{data}</dct:format>'.format(data=y[3]) + '<dct:bytesize>{data}</dct:bytesize>'.format(data=y[4]) + '</dcat:Distribution>' + '</dcat:distribution>')
|
||||||
'<dcat:distribution>'+
|
publisher = ''
|
||||||
'<dcat:Distribution>'+
|
|
||||||
'<dct:title>{data}</dct:title>'.format(data=y[0])+
|
|
||||||
'<dcat:downloadURL>{data}</dcat:downloadURL>'.format(data=y[1])+
|
|
||||||
'<dcat:mediaType>{data}</dcat:mediaType>'.format(data=y[2])+
|
|
||||||
'<dct:format>{data}</dct:format>'.format(data=y[3])+
|
|
||||||
'<dct:bytesize>{data}</dct:bytesize>'.format(data=y[4])+
|
|
||||||
'</dcat:Distribution>'+
|
|
||||||
'</dcat:distribution>')
|
|
||||||
publisher=''
|
|
||||||
for z in dataall[2]:
|
for z in dataall[2]:
|
||||||
publisher = publisher + (
|
publisher = publisher + ('<dct:publisher>' + '<foaf:Organization>' + '<foaf:name>{data}</foaf:name>'.format(data=z[1]) + '<foaf:mbox>{data}</foaf:mbox>'.format(data=z[3]) + '</foaf:Organization>' + '</dct:publisher>')
|
||||||
'<dct:publisher>'+
|
data_str = [[dataall[0][26], '<dct:identifier>{data}</dct:identifier>'.format(data=dataall[0][1]) + '<dct:title>{data}</dct:title>'.format(data=dataall[0][4]) + '<dct:description>{data}</dct:description>'.format(data=dataall[0][5]) + '<dct:language>{data}</dct:language>'.format(data=dataall[0][26]) + '<dct:spatial>{data}</dct:spatial>'.format(data=dataall[0][28]) + '<dct:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">{data}</dct:created>'.format(data=dataall[0][20]) + '<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">{data}</dct:issued>'.format(data=dataall[0][11]) + '<dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">{data}</dct:modified>'.format(data=dataall[0][21]) + '<dct:license>{data}</dct:license>'.format(data=dataall[0][13]) + distribution + publisher + '<dcat:theme>{data}</dcat:theme>'.format(data=", ".join(str(x) for x in dataall[0][24])) + '<dcat:keyword>{data}</dcat:keyword>'.format(data=", ".join(str(x) for x in dataall[0][6])) + '<dct:accrualPeriodicity>{data}</dct:accrualPeriodicity>'.format(data=dataall[0][12])]]
|
||||||
'<foaf:Organization>'+
|
|
||||||
'<foaf:name>{data}</foaf:name>'.format(data=z[1])+
|
|
||||||
'<foaf:mbox>{data}</foaf:mbox>'.format(data=z[3])+
|
|
||||||
'</foaf:Organization>'+
|
|
||||||
'</dct:publisher>')
|
|
||||||
data_str = [[dataall[0][26],
|
|
||||||
'<dct:identifier>{data}</dct:identifier>'.format(data=dataall[0][1])+
|
|
||||||
'<dct:title>{data}</dct:title>'.format(data=dataall[0][4])+
|
|
||||||
'<dct:description>{data}</dct:description>'.format(data=dataall[0][5])+
|
|
||||||
'<dct:language>{data}</dct:language>'.format(data=dataall[0][26])+
|
|
||||||
'<dct:spatial>{data}</dct:spatial>'.format(data=dataall[0][28])+
|
|
||||||
'<dct:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">{data}</dct:created>'.format(data=dataall[0][20])+
|
|
||||||
'<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">{data}</dct:issued>'.format(data=dataall[0][11])+
|
|
||||||
'<dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">{data}</dct:modified>'.format(data=dataall[0][21])+
|
|
||||||
'<dct:license>{data}</dct:license>'.format(data=dataall[0][13])+
|
|
||||||
distribution+
|
|
||||||
publisher+
|
|
||||||
'<dcat:theme>{data}</dcat:theme>'.format(data=", ".join(str(x) for x in dataall[0][24]))+
|
|
||||||
'<dcat:keyword>{data}</dcat:keyword>'.format(data=", ".join(str(x) for x in dataall[0][6]))+
|
|
||||||
'<dct:accrualPeriodicity>{data}</dct:accrualPeriodicity>'.format(data=dataall[0][12])]]
|
|
||||||
|
|
||||||
return data_str
|
return data_str
|
||||||
|
|
||||||
@ -277,7 +232,7 @@ publisher+
|
|||||||
locale = QgsSettings().value("locale/userLocale", QLocale().name())
|
locale = QgsSettings().value("locale/userLocale", QLocale().name())
|
||||||
locale = locale.split('_')[0].lower()
|
locale = locale.split('_')[0].lower()
|
||||||
|
|
||||||
if output_format == [OutputFormats.HTML,OutputFormats.DCAT]:
|
if output_format == [OutputFormats.HTML, OutputFormats.DCAT]:
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT pgmetadata.get_dataset_item_html_content('{schema}', '{table}', '{locale}');"
|
"SELECT pgmetadata.get_dataset_item_html_content('{schema}', '{table}', '{locale}');"
|
||||||
).format(schema=uri.schema(), table=uri.table(), locale=locale)
|
).format(schema=uri.schema(), table=uri.table(), locale=locale)
|
||||||
@ -292,7 +247,6 @@ publisher+
|
|||||||
self.current_connection = None
|
self.current_connection = None
|
||||||
self.ce_trouve_dans_psql(layer)
|
self.ce_trouve_dans_psql(layer)
|
||||||
|
|
||||||
|
|
||||||
def add_flatten_dataset_table(self):
|
def add_flatten_dataset_table(self):
|
||||||
""" Add a flatten dataset table with all links and contacts. """
|
""" Add a flatten dataset table with all links and contacts. """
|
||||||
'''
|
'''
|
||||||
@ -337,17 +291,17 @@ publisher+
|
|||||||
|
|
||||||
def set_html_content(self, title=None, body=None):
|
def set_html_content(self, title=None, body=None):
|
||||||
""" Set the content in the dock. """
|
""" Set the content in the dock. """
|
||||||
#link_logo=resources_path('icons', 'CEN_RA.png')
|
# ink_logo=resources_path('icons', 'CEN_RA.png')
|
||||||
css_file = resources_path('css', 'dock.css')
|
css_file = resources_path('css', 'dock.css')
|
||||||
with open(css_file, 'r', encoding='utf8') as f:
|
with open(css_file, 'r', encoding='utf8') as f:
|
||||||
css = f.read()
|
css = f.read()
|
||||||
|
|
||||||
html = '<html><head>'
|
html = '<html><head>'
|
||||||
#html += '<script src="http://ignf.github.io/geoportal-sdk/latest/dist/2d/GpSDK2D.js" defer ></script>'
|
# html += '<script src="http://ignf.github.io/geoportal-sdk/latest/dist/2d/GpSDK2D.js" defer ></script>'
|
||||||
html += '<style>{css}</style></head><body>'.format(css=css)
|
html += '<style>{css}</style></head><body>'.format(css=css)
|
||||||
#html += '<link rel="stylesheet" href="http://ignf.github.io/geoportal-sdk/latest/dist/2d/GpSDK2D.css" >'
|
# html += '<link rel="stylesheet" href="http://ignf.github.io/geoportal-sdk/latest/dist/2d/GpSDK2D.css" >'
|
||||||
#html += '<script src="file:///C:/Users/tlaveille/Desktop/maps.js" defer></script>'
|
# html += '<script src="file:///C:/Users/tlaveille/Desktop/maps.js" defer></script>'
|
||||||
#html += '<noscript>Your browser does not support JavaScript!</noscript>'
|
# html += '<noscript>Your browser does not support JavaScript!</noscript>'
|
||||||
if title:
|
if title:
|
||||||
html += '<h2>{title} <img class=logo src=https://i2.wp.com/www.cen-rhonealpes.fr/wp-content/uploads/2013/04/cen-rhonealpes-couleurs1.jpg?w=340&ssl=1></h2>'.format(title=title)
|
html += '<h2>{title} <img class=logo src=https://i2.wp.com/www.cen-rhonealpes.fr/wp-content/uploads/2013/04/cen-rhonealpes-couleurs1.jpg?w=340&ssl=1></h2>'.format(title=title)
|
||||||
if body:
|
if body:
|
||||||
@ -356,16 +310,16 @@ publisher+
|
|||||||
html += '</body></html>'
|
html += '</body></html>'
|
||||||
|
|
||||||
# It must be a file, even if it does not exist on the file system.
|
# It must be a file, even if it does not exist on the file system.
|
||||||
base_url = QUrl.fromLocalFile(resources_path('images', 'must_be_a_file.png'))
|
# base_url = QUrl.fromLocalFile(resources_path('images', 'must_be_a_file.png'))
|
||||||
self.viewer.setHtml(html)#, base_url)
|
self.viewer.setHtml(html)
|
||||||
|
|
||||||
def ce_trouve_dans_psql(self,layer):
|
def ce_trouve_dans_psql(self, layer):
|
||||||
try:
|
try:
|
||||||
uri = layer.dataProvider().uri()
|
uri = layer.dataProvider().uri()
|
||||||
except:
|
except AttributeError:
|
||||||
self.default_html_content_not_pg_layer()
|
self.default_html_content_not_pg_layer()
|
||||||
self.save_button.setEnabled(False)
|
self.save_button.setEnabled(False)
|
||||||
uri=''
|
uri = ''
|
||||||
if uri != '':
|
if uri != '':
|
||||||
if not uri.table():
|
if not uri.table():
|
||||||
layertype = layer.providerType().lower()
|
layertype = layer.providerType().lower()
|
||||||
@ -376,23 +330,23 @@ publisher+
|
|||||||
self.save_button.setEnabled(False)
|
self.save_button.setEnabled(False)
|
||||||
else:
|
else:
|
||||||
data_count = self.sql_check(uri)
|
data_count = self.sql_check(uri)
|
||||||
#print(data_count)
|
# print(data_count)
|
||||||
if data_count == 0:
|
if data_count == 0:
|
||||||
self.default_html_content_not_metadata()
|
self.default_html_content_not_metadata()
|
||||||
self.save_button.setEnabled(False)
|
self.save_button.setEnabled(False)
|
||||||
else:
|
else:
|
||||||
self.build_html_content(layer,uri)
|
self.build_html_content(layer, uri)
|
||||||
self.save_button.setEnabled(True)
|
self.save_button.setEnabled(True)
|
||||||
|
|
||||||
def build_html_content(self,layer,uri):
|
def build_html_content(self, layer, uri):
|
||||||
body = ''
|
body = ''
|
||||||
|
|
||||||
dataall=self.sql_info(uri)
|
dataall = self.sql_info(uri)
|
||||||
data=dataall[0]
|
data = dataall[0]
|
||||||
data_url=dataall[1]
|
data_url = dataall[1]
|
||||||
data_contact=dataall[2]
|
data_contact = dataall[2]
|
||||||
#print(len(data_url))
|
# print(len(data_url))
|
||||||
data_collonne=[field.name() for field in layer.dataProvider().fields()]
|
# data_collonne = [field.name() for field in layer.dataProvider().fields()]
|
||||||
|
|
||||||
body += '<div><h3>Identification</h3><table class="table table-condensed">'
|
body += '<div><h3>Identification</h3><table class="table table-condensed">'
|
||||||
body += '<tr><th>Titre</th><td>{data[4]}</td></tr>'.format(data=data)
|
body += '<tr><th>Titre</th><td>{data[4]}</td></tr>'.format(data=data)
|
||||||
@ -415,7 +369,7 @@ publisher+
|
|||||||
body += '<tr><th>Emprise</th><td>{data[28]}</td></tr>'.format(data=data)
|
body += '<tr><th>Emprise</th><td>{data[28]}</td></tr>'.format(data=data)
|
||||||
body += '</table></div>'
|
body += '</table></div>'
|
||||||
|
|
||||||
#body += '<div id="map"></div>'
|
# body += '<div id="map"></div>'
|
||||||
|
|
||||||
body += '<div><h3>Publication</h3><table class="table table-condensed">'
|
body += '<div><h3>Publication</h3><table class="table table-condensed">'
|
||||||
body += '<tr><th>Date</th><td>{data[11]}</td></tr>'.format(data=data)
|
body += '<tr><th>Date</th><td>{data[11]}</td></tr>'.format(data=data)
|
||||||
@ -454,45 +408,46 @@ publisher+
|
|||||||
self.set_html_content(
|
self.set_html_content(
|
||||||
layer.name(), body)
|
layer.name(), body)
|
||||||
|
|
||||||
def set_html_to_wms(self,layer):
|
def set_html_to_wms(self, layer):
|
||||||
self.set_html_content(
|
self.set_html_content(
|
||||||
'CenRa Metadata',(layer.htmlMetadata()))
|
'CenRa Metadata', (layer.htmlMetadata()))
|
||||||
|
|
||||||
def default_html_content_not_pg_layer(self):
|
def default_html_content_not_pg_layer(self):
|
||||||
""" When it's not a PostgreSQL layer. """
|
""" When it's not a PostgreSQL layer. """
|
||||||
self.set_html_content(
|
self.set_html_content(
|
||||||
'CenRa Metadata', ('Vous devez cliquer sur une couche dans la légende qui est stockée dans PostgreSQL.'))
|
'CenRa Metadata', ('Vous devez cliquer sur une couche dans la légende qui est stockée dans PostgreSQL.'))
|
||||||
|
|
||||||
def default_html_content_not_metadata(self):
|
def default_html_content_not_metadata(self):
|
||||||
self.set_html_content(
|
self.set_html_content(
|
||||||
'CenRa Metadata', ('La couche ne contien pas de métadonnée.'))
|
'CenRa Metadata', ('La couche ne contien pas de métadonnée.'))
|
||||||
|
|
||||||
def sql_check(self,uri):
|
def sql_check(self, uri):
|
||||||
cur=login_base()
|
cur = login_base()
|
||||||
table = uri.table()
|
table = uri.table()
|
||||||
schema = uri.schema()
|
schema = uri.schema()
|
||||||
|
|
||||||
sql_count = """SELECT count(uid) FROM metadata.dataset
|
sql_count = """SELECT count(uid) FROM metadata.dataset
|
||||||
WHERE schema_name LIKE '"""+schema+"""' AND table_name LIKE '"""+table+"""';"""
|
WHERE schema_name LIKE '""" + schema + """' AND table_name LIKE '""" + table + """';"""
|
||||||
|
|
||||||
cur.execute(sql_count)
|
cur.execute(sql_count)
|
||||||
data_count = cur.fetchall()
|
data_count = cur.fetchall()
|
||||||
cur.close()
|
cur.close()
|
||||||
return data_count[0][0]
|
return data_count[0][0]
|
||||||
|
|
||||||
def sql_info(self,uri):
|
def sql_info(self, uri):
|
||||||
cur=login_base()
|
cur = login_base()
|
||||||
table = uri.table()
|
table = uri.table()
|
||||||
schema = uri.schema()
|
schema = uri.schema()
|
||||||
#[s for s in iface.activeLayer().source().split(" ") if "dbname" in s][0].split("'")[1]
|
# [s for s in iface.activeLayer().source().split(" ") if "dbname" in s][0].split("'")[1]
|
||||||
sql_find = """SELECT *,right(left(st_astext(geom,2),-2),-9) FROM metadata.dataset
|
sql_find = """SELECT *,right(left(st_astext(geom,2),-2),-9) FROM metadata.dataset
|
||||||
WHERE schema_name LIKE '"""+schema+"""' AND table_name LIKE '"""+table+"""';"""
|
WHERE schema_name LIKE '""" + schema + """' AND table_name LIKE '""" + table + """';"""
|
||||||
cur.execute(sql_find)
|
cur.execute(sql_find)
|
||||||
data_general = cur.fetchall()
|
data_general = cur.fetchall()
|
||||||
sql_findurl = """SELECT type,url,mime,format,taille FROM metadata.dataurl WHERE schema_name LIKE '"""+schema+"""' AND table_name LIKE '"""+table+"""';"""
|
sql_findurl = """SELECT type,url,mime,format,taille FROM metadata.dataurl WHERE schema_name LIKE '""" + schema + """' AND table_name LIKE '""" + table + """';"""
|
||||||
cur.execute(sql_findurl)
|
cur.execute(sql_findurl)
|
||||||
data_url = cur.fetchall()
|
data_url = cur.fetchall()
|
||||||
sql_findcontact = """SELECT role,nom,organisation,email,telephone FROM metadata.datacontact WHERE schema_name LIKE '"""+schema+"""' AND table_name LIKE '"""+table+"""';"""
|
sql_findcontact = """SELECT role,nom,organisation,email,telephone FROM metadata.datacontact WHERE schema_name LIKE '""" + schema + """' AND table_name LIKE '""" + table + """';"""
|
||||||
cur.execute(sql_findcontact)
|
cur.execute(sql_findcontact)
|
||||||
data_contact = cur.fetchall()
|
data_contact = cur.fetchall()
|
||||||
cur.close()
|
cur.close()
|
||||||
return data_general[0],data_url,data_contact
|
return data_general[0], data_url, data_contact
|
||||||
|
|
||||||
|
|||||||
@ -1,66 +1,53 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from collections import namedtuple
|
# from collections import namedtuple
|
||||||
from enum import Enum
|
# from enum import Enum
|
||||||
from functools import partial
|
# from functools import partial
|
||||||
from pathlib import Path
|
# from pathlib import Path
|
||||||
from xml.dom.minidom import parseString
|
# from xml.dom.minidom import parseString
|
||||||
from qgis.gui import *
|
# from qgis.gui import *
|
||||||
from qgis.core import (
|
from qgis.core import (
|
||||||
NULL,
|
|
||||||
QgsApplication,
|
QgsApplication,
|
||||||
QgsDataSourceUri,
|
|
||||||
QgsProject,
|
|
||||||
QgsProviderConnectionException,
|
|
||||||
QgsProviderRegistry,
|
|
||||||
QgsRasterLayer,
|
|
||||||
QgsSettings,
|
QgsSettings,
|
||||||
QgsVectorLayer,
|
|
||||||
QgsGeometry,
|
QgsGeometry,
|
||||||
QgsWkbTypes,
|
QgsWkbTypes,
|
||||||
)
|
)
|
||||||
from qgis.PyQt import QtGui
|
from qgis.PyQt import QtGui, QtCore
|
||||||
from qgis.PyQt.QtCore import QLocale, QUrl, QDateTime
|
from qgis.PyQt.QtGui import QIcon
|
||||||
from qgis.PyQt.QtGui import QDesktopServices, QIcon
|
# from qgis.PyQt.QtPrintSupport import QPrinter
|
||||||
from qgis.PyQt.QtPrintSupport import QPrinter
|
# from qgis.PyQt.QtWebKitWidgets import QWebPage
|
||||||
#from qgis.PyQt.QtWebKitWidgets import QWebPage
|
import psycopg2
|
||||||
from qgis.PyQt.QtWidgets import (
|
from qgis.PyQt.QtWidgets import (
|
||||||
QDialog,
|
QDialog,
|
||||||
QAction,
|
|
||||||
QDockWidget,
|
|
||||||
QFileDialog,
|
QFileDialog,
|
||||||
QInputDialog,
|
|
||||||
QMenu,
|
|
||||||
QToolButton,
|
|
||||||
QTableWidget,
|
|
||||||
QTableWidgetItem,
|
QTableWidgetItem,
|
||||||
)
|
)
|
||||||
from qgis.utils import iface
|
from qgis.utils import iface
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .tools.PythonSQL import login_base
|
from .tools.PythonSQL import login_base
|
||||||
except:
|
except ValueError:
|
||||||
print('Pas de fichier PythonSQL')
|
print('Pas de fichier PythonSQL')
|
||||||
|
|
||||||
from .tools.resources import (
|
from .tools.resources import (
|
||||||
load_ui,
|
load_ui,
|
||||||
resources_path,
|
resources_path,
|
||||||
send_issues,
|
# send_issues,
|
||||||
)
|
)
|
||||||
from .issues import CenRa_Issues
|
# from .issues import CenRa_Issues
|
||||||
|
|
||||||
EDITOR_CLASS = load_ui('CenRa_Metabase_editorwidget_base.ui')
|
EDITOR_CLASS = load_ui('CenRa_Metabase_editorwidget_base.ui')
|
||||||
LOGGER = logging.getLogger('CenRa_Metabase')
|
LOGGEr = logging.getLogger('CenRa_Metabase')
|
||||||
|
|
||||||
|
|
||||||
class Metabase_Editor(QDialog, EDITOR_CLASS):
|
class Metabase_Editor(QDialog, EDITOR_CLASS):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
_ = parent
|
_ = parent
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.settings = QgsSettings()
|
self.settings = QgsSettings()
|
||||||
self.setWindowIcon(QtGui.QIcon(resources_path('icons','icon.png')))
|
self.setWindowIcon(QtGui.QIcon(resources_path('icons', 'icon.png')))
|
||||||
self.import_xml.setAutoRaise(True)
|
self.import_xml.setAutoRaise(True)
|
||||||
self.import_xml.setText('')
|
self.import_xml.setText('')
|
||||||
self.import_xml.setIcon(QIcon(QgsApplication.iconPath('mActionAddHtml.svg')))
|
self.import_xml.setIcon(QIcon(QgsApplication.iconPath('mActionAddHtml.svg')))
|
||||||
@ -68,13 +55,13 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
self.issues_app.setAutoRaise(True)
|
self.issues_app.setAutoRaise(True)
|
||||||
self.issues_app.setText('')
|
self.issues_app.setText('')
|
||||||
self.issues_app.setIcon(QIcon(QgsApplication.iconPath('mIconInfo.svg')))
|
self.issues_app.setIcon(QIcon(QgsApplication.iconPath('mIconInfo.svg')))
|
||||||
self.auto_adding.setIcon(QtGui.QIcon(resources_path('icons','auto_add.png')))
|
self.auto_adding.setIcon(QtGui.QIcon(resources_path('icons', 'auto_add.png')))
|
||||||
self.auto_adding.hide()
|
self.auto_adding.hide()
|
||||||
if os.getlogin() == 'tlaveille' or 'lpoulin' or 'rclement':
|
if os.getlogin() == 'tlaveille' or 'lpoulin' or 'rclement':
|
||||||
self.auto_adding.show()
|
self.auto_adding.show()
|
||||||
|
|
||||||
self.auto_adding.clicked.connect(self.auto_run)
|
self.auto_adding.clicked.connect(self.auto_run)
|
||||||
self.issues_app.clicked.connect(self.issues_open)
|
# self.issues_app.clicked.connect(self.issues_open)
|
||||||
self.categories_select_view.itemDoubleClicked.connect(self.add_categories_view)
|
self.categories_select_view.itemDoubleClicked.connect(self.add_categories_view)
|
||||||
self.categories_view.itemDoubleClicked.connect(self.deleter_categories_view)
|
self.categories_view.itemDoubleClicked.connect(self.deleter_categories_view)
|
||||||
self.themes_select_view.itemDoubleClicked.connect(self.add_themes_view)
|
self.themes_select_view.itemDoubleClicked.connect(self.add_themes_view)
|
||||||
@ -102,6 +89,7 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
self.format_box.setCurrentIndex(0)
|
self.format_box.setCurrentIndex(0)
|
||||||
self.taille_line.setText('45')
|
self.taille_line.setText('45')
|
||||||
self.add_lien()
|
self.add_lien()
|
||||||
|
|
||||||
def add_metadata(self):
|
def add_metadata(self):
|
||||||
table_name = layer.dataProvider().uri().table()
|
table_name = layer.dataProvider().uri().table()
|
||||||
schema_name = layer.dataProvider().uri().schema()
|
schema_name = layer.dataProvider().uri().schema()
|
||||||
@ -117,19 +105,19 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
array_categories = '{'
|
array_categories = '{'
|
||||||
while row_count_categories >= row:
|
while row_count_categories >= row:
|
||||||
if row_count_categories != row:
|
if row_count_categories != row:
|
||||||
array_categories += (self.categories_view.item(row-1,0).text())+','
|
array_categories += (self.categories_view.item(row - 1, 0).text()) + ', '
|
||||||
else:
|
else:
|
||||||
array_categories += (self.categories_view.item(row-1,0).text())
|
array_categories += (self.categories_view.item(row - 1, 0).text())
|
||||||
row = row+1
|
row = row + 1
|
||||||
array_categories += '}'
|
array_categories += '}'
|
||||||
row = 1
|
row = 1
|
||||||
array_themes = '{'
|
array_themes = '{'
|
||||||
while row_count_themes >= row:
|
while row_count_themes >= row:
|
||||||
if row_count_themes != row:
|
if row_count_themes != row:
|
||||||
array_themes += (self.themes_view.item(row-1,0).text())+','
|
array_themes += (self.themes_view.item(row - 1, 0).text()) + ', '
|
||||||
else:
|
else:
|
||||||
array_themes += (self.themes_view.item(row-1,0).text())
|
array_themes += (self.themes_view.item(row - 1, 0).text())
|
||||||
row = row+1
|
row = row + 1
|
||||||
array_themes += '}'
|
array_themes += '}'
|
||||||
|
|
||||||
text_date_creation = str(self.date_creation_date.date().toPyDate())
|
text_date_creation = str(self.date_creation_date.date().toPyDate())
|
||||||
@ -162,65 +150,65 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
array_link = ''
|
array_link = ''
|
||||||
while row_count_link >= row:
|
while row_count_link >= row:
|
||||||
if row_count_link != row:
|
if row_count_link != row:
|
||||||
array_link += "('"+ table_name +"','"+ schema_name +"','"+ (self.table_lien.item(row-1,1).text()) +"','"+ (self.table_lien.item(row-1,2).text()) +"','"+ (self.table_lien.item(row-1,3).text()) +"','"+ (self.table_lien.item(row-1,4).text()) +"','"+ (self.table_lien.item(row-1,5).text()) +"')"+','
|
array_link += "('" + table_name + "', '" + schema_name + "', '" + (self.table_lien.item(row - 1,1).text()) + "', '" + (self.table_lien.item(row - 1,2).text()) + "', '" + (self.table_lien.item(row - 1,3).text()) + "', '" + (self.table_lien.item(row - 1,4).text()) + "', '" + (self.table_lien.item(row - 1,5).text()) + "')" + ', '
|
||||||
else:
|
else:
|
||||||
array_link += "('"+ table_name +"','"+ schema_name +"','"+ (self.table_lien.item(row-1,1).text()) +"','"+ (self.table_lien.item(row-1,2).text()) +"','"+ (self.table_lien.item(row-1,3).text()) +"','"+ (self.table_lien.item(row-1,4).text()) +"','"+ (self.table_lien.item(row-1,5).text()) +"')"
|
array_link += "('" + table_name + "', '" + schema_name + "', '" + (self.table_lien.item(row - 1,1).text()) + "', '" + (self.table_lien.item(row - 1,2).text()) + "', '" + (self.table_lien.item(row - 1,3).text()) + "', '" + (self.table_lien.item(row - 1,4).text()) + "', '" + (self.table_lien.item(row - 1,5).text()) + "')"
|
||||||
row = row+1
|
row = row + 1
|
||||||
|
|
||||||
row_count_contact = self.table_contact.rowCount()
|
row_count_contact = self.table_contact.rowCount()
|
||||||
row = 1
|
row = 1
|
||||||
array_contact = ''
|
array_contact = ''
|
||||||
while row_count_contact >= row:
|
while row_count_contact >= row:
|
||||||
if row_count_contact != row:
|
if row_count_contact != row:
|
||||||
array_contact += "('"+ table_name +"','"+ schema_name +"','"+ (self.table_contact.item(row-1,1).text()) +"','"+ (self.table_contact.item(row-1,2).text()) +"','"+ (self.table_contact.item(row-1,3).text()) +"','"+ (self.table_contact.item(row-1,4).text()) +"','"+ (self.table_contact.item(row-1,5).text()) +"')"+','
|
array_contact += "('" + table_name + "', '" + schema_name + "', '" + (self.table_contact.item(row - 1,1).text()) + "', '" + (self.table_contact.item(row - 1,2).text()) + "', '" + (self.table_contact.item(row - 1,3).text()) + "', '" + (self.table_contact.item(row - 1,4).text()) + "', '" + (self.table_contact.item(row - 1,5).text()) + "')" + ', '
|
||||||
else:
|
else:
|
||||||
array_contact += "('"+ table_name +"','"+ schema_name +"','"+ (self.table_contact.item(row-1,1).text()) +"','"+ (self.table_contact.item(row-1,2).text()) +"','"+ (self.table_contact.item(row-1,3).text()) +"','"+ (self.table_contact.item(row-1,4).text()) +"','"+ (self.table_contact.item(row-1,5).text()) +"')"
|
array_contact += "('" + table_name + "', '" + schema_name + "', '" + (self.table_contact.item(row - 1,1).text()) + "', '" + (self.table_contact.item(row - 1,2).text()) + "', '" + (self.table_contact.item(row - 1,3).text()) + "', '" + (self.table_contact.item(row - 1,4).text()) + "', '" + (self.table_contact.item(row - 1,5).text()) + "')"
|
||||||
row = row+1
|
row = row + 1
|
||||||
'''
|
'''
|
||||||
|
|
||||||
exist=self.status_metadata(layer)
|
exist = self.status_metadata(layer)
|
||||||
cur_con=login_base(take=True)
|
cur_con = login_base(take=True)
|
||||||
cur=cur_con[0]
|
cur = cur_con[0]
|
||||||
con=cur_con[1]
|
con = cur_con[1]
|
||||||
list_champs_sql = ''
|
list_champs_sql = ''
|
||||||
values_sql_add = ''
|
values_sql_add = ''
|
||||||
if exist:
|
if exist:
|
||||||
SQL_uid = """SELECT uid from metadata.dataset where table_name like '"""+table_name+"""' and schema_name like '"""+schema_name+"""';"""
|
SQL_uid = """SELECT uid from metadata.dataset where table_name like '""" + table_name + """' and schema_name like '""" + schema_name + """';"""
|
||||||
cur.execute(SQL_uid)
|
cur.execute(SQL_uid)
|
||||||
text_uid = (cur.fetchall())[0][0]
|
text_uid = (cur.fetchall())[0][0]
|
||||||
|
|
||||||
SQL_delete = """DELETE from metadata.dataset where table_name like '"""+table_name+"""' and schema_name like '"""+schema_name+"""';"""
|
SQL_delete = """DELETE from metadata.dataset where table_name like '""" + table_name + """' and schema_name like '""" + schema_name + """';"""
|
||||||
cur.execute(SQL_delete)
|
cur.execute(SQL_delete)
|
||||||
values_sql_add += "'"+text_uid+"',"
|
values_sql_add += "'" + text_uid + "',"
|
||||||
|
|
||||||
list_champs_sql+='uid,'
|
list_champs_sql += 'uid,'
|
||||||
global uid_delete_list_link,uid_delete_list_contact
|
global uid_delete_list_link, uid_delete_list_contact
|
||||||
if len(uid_delete_list_link) >= 35:
|
if len(uid_delete_list_link) >= 35:
|
||||||
SQL_delete_link = """DELETE FROM metadata.dataurl WHERE uid IN ("""+ uid_delete_list_link[:-1] +""");"""
|
SQL_delete_link = """DELETE FROM metadata.dataurl WHERE uid IN (""" + uid_delete_list_link[:- 1] + """);"""
|
||||||
cur.execute(SQL_delete_link)
|
cur.execute(SQL_delete_link)
|
||||||
uid_delete_list_link = ''
|
uid_delete_list_link = ''
|
||||||
if len(uid_delete_list_contact) >= 35:
|
if len(uid_delete_list_contact) >= 35:
|
||||||
SQL_delete_contact = """DELETE FROM metadata.datacontact WHERE uid IN ("""+ uid_delete_list_contact[:-1] +""");"""
|
SQL_delete_contact = """DELETE FROM metadata.datacontact WHERE uid IN (""" + uid_delete_list_contact[:- 1] + """);"""
|
||||||
cur.execute(SQL_delete_contact)
|
cur.execute(SQL_delete_contact)
|
||||||
uid_delete_list_contact=''
|
uid_delete_list_contact = ''
|
||||||
|
|
||||||
list_champs_sql += 'table_name,schema_name,title,abstract,keywords,data_last_update,langue,categories,themes,creation_date,update_date,encode,geom,spatial_extent,feature_count,geometry_type,projection_name,projection_authid,spatial_level,minimum_optimal_scale,maximum_optimal_scale,publication_date,publication_frequency,confidentiality,license,license_attribution'
|
list_champs_sql += 'table_name, schema_name, title, abstract, keywords, data_last_update, langue, categories, themes, creation_date, update_date, encode, geom, spatial_extent, feature_count, geometry_type, projection_name, projection_authid, spatial_level, minimum_optimal_scale, maximum_optimal_scale, publication_date, publication_frequency, confidentiality, license, license_attribution'
|
||||||
values_sql_add += "'"+table_name+"','"+schema_name+"','"+text_titre+"','"+text_description+"','"+text_mots_cles+"','"+text_date_maj+"','"+text_langue+"','"+array_categories+"','"+array_themes+"','"+text_date_creation+"','"+text_date_modification+"','"+text_encode+"','"+text_extend+"','"+text_extend+"','"+int_nbr_entites+"','"+text_geomtype+"','"+text_crsname+"','"+text_crscode+"','"+text_niveau+"',"+text_echelle_min+","+text_echelle_max+",'"+text_date_publication+"','"+text_frequence+"','"+text_restriction+"','"+text_licence+"','"+text_licence_attrib+"'"
|
values_sql_add += "'" + table_name + "', '" + schema_name + "', '" + text_titre + "', '" + text_description + "', '" + text_mots_cles + "', '" + text_date_maj + "', '" + text_langue + "', '" + array_categories + "', '" + array_themes + "', '" + text_date_creation + "', '" + text_date_modification + "', '" + text_encode + "', '" + text_extend + "', '" + text_extend + "', '" + int_nbr_entites + "', '" + text_geomtype + "', '" + text_crsname + "', '" + text_crscode + "', '" + text_niveau + "'," + text_echelle_min + "," + text_echelle_max + ",'" + text_date_publication + "', '" + text_frequence + "', '" + text_restriction + "', '" + text_licence + "', '" + text_licence_attrib + "'"
|
||||||
|
|
||||||
SQL_add = """INSERT INTO metadata.dataset ("""+list_champs_sql+""") VALUES ("""+values_sql_add+""");"""
|
SQL_add = """INSERT INTO metadata.dataset (""" + list_champs_sql + """) VALUES (""" + values_sql_add + """);"""
|
||||||
|
|
||||||
cur.execute(SQL_add)
|
cur.execute(SQL_add)
|
||||||
|
|
||||||
global array_link,array_contact
|
global array_link, array_contact
|
||||||
if len(array_link) >= 25:
|
if len(array_link) >= 25:
|
||||||
array_link=array_link[:-1]
|
array_link = array_link[:- 1]
|
||||||
SQL_add_link = """INSERT INTO metadata.dataurl (table_name,schema_name,type,url,mime,format,taille) VALUES """+array_link+""";"""
|
SQL_add_link = """INSERT INTO metadata.dataurl (table_name, schema_name, type, url, mime, format, taille) VALUES """ + array_link + """;"""
|
||||||
cur.execute(SQL_add_link)
|
cur.execute(SQL_add_link)
|
||||||
array_link = ''
|
array_link = ''
|
||||||
|
|
||||||
if len(array_contact) >= 25:
|
if len(array_contact) >= 25:
|
||||||
array_contact=array_contact[0:-1]
|
array_contact = array_contact[0:- 1]
|
||||||
SQL_add_contact = """INSERT INTO metadata.datacontact (table_name,schema_name,role,nom,organisation,email,telephone) VALUES """+array_contact+""";"""
|
SQL_add_contact = """INSERT INTO metadata.datacontact (table_name, schema_name, role, nom, organisation, email, telephone) VALUES """ + array_contact + """;"""
|
||||||
cur.execute(SQL_add_contact)
|
cur.execute(SQL_add_contact)
|
||||||
array_contact = ''
|
array_contact = ''
|
||||||
|
|
||||||
@ -235,28 +223,28 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
self.activateWindow()
|
self.activateWindow()
|
||||||
global layer
|
global layer
|
||||||
layer = iface.activeLayer()
|
layer = iface.activeLayer()
|
||||||
global uid_delete_list_link,uid_delete_list_contact,array_link,array_contact
|
global uid_delete_list_link, uid_delete_list_contact, array_link, array_contact
|
||||||
uid_delete_list_link=''
|
uid_delete_list_link = ''
|
||||||
uid_delete_list_contact=''
|
uid_delete_list_contact = ''
|
||||||
array_link = ''
|
array_link = ''
|
||||||
array_contact = ''
|
array_contact = ''
|
||||||
|
|
||||||
is_ok=self.is_in_psql(layer)
|
is_ok = self.is_in_psql(layer)
|
||||||
if is_ok:
|
if is_ok:
|
||||||
exist=self.status_metadata(layer)
|
exist = self.status_metadata(layer)
|
||||||
if exist:
|
if exist:
|
||||||
self.reload_data(layer)
|
self.reload_data(layer)
|
||||||
else:
|
else:
|
||||||
self.new_data(layer)
|
self.new_data(layer)
|
||||||
else:
|
else:
|
||||||
self.close()
|
self.close()
|
||||||
iface.messageBar().pushMessage("Information :", "Cette couche n'est pas stockée dans PostgreSQL", level=Qgis.Warning, duration=30)
|
iface.messageBar().pushMessage("Information:", "Cette couche n'est pas stockée dans PostgreSQL", level=1, duration=30)
|
||||||
|
|
||||||
def is_in_psql(self,layer):
|
def is_in_psql(self, layer):
|
||||||
try:
|
try:
|
||||||
uri = layer.dataProvider().uri()
|
uri = layer.dataProvider().uri()
|
||||||
except:
|
except AttributeError:
|
||||||
uri=''
|
uri = ''
|
||||||
return False
|
return False
|
||||||
if uri != '':
|
if uri != '':
|
||||||
if not uri.table():
|
if not uri.table():
|
||||||
@ -264,13 +252,13 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def status_metadata(self,layer):
|
def status_metadata(self, layer):
|
||||||
uri = layer.dataProvider().uri()
|
uri = layer.dataProvider().uri()
|
||||||
table = uri.table()
|
table = uri.table()
|
||||||
schema = uri.schema()
|
schema = uri.schema()
|
||||||
|
|
||||||
cur=login_base()
|
cur = login_base()
|
||||||
count_sql = """ SELECT count(uid) FROM metadata.dataset WHERE table_name LIKE '"""+table+"""' AND schema_name LIKE '"""+schema+"""';"""
|
count_sql = """ SELECT count(uid) FROM metadata.dataset WHERE table_name LIKE '""" + table + """' AND schema_name LIKE '""" + schema + """';"""
|
||||||
|
|
||||||
cur.execute(count_sql)
|
cur.execute(count_sql)
|
||||||
data_count = (cur.fetchall())[0][0]
|
data_count = (cur.fetchall())[0][0]
|
||||||
@ -280,17 +268,17 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
return False
|
return False
|
||||||
cur.close()
|
cur.close()
|
||||||
|
|
||||||
def new_data(self,layer):
|
def new_data(self, layer):
|
||||||
#print(layer.name(),'is new data')
|
# print(layer.name(),'is new data')
|
||||||
reloader=False
|
reloader = False
|
||||||
self.interface_view(layer,reloader)
|
self.interface_view(layer, reloader)
|
||||||
|
|
||||||
def reload_data(self,layer):
|
def reload_data(self, layer):
|
||||||
#print(layer.name(),'reload data')
|
# print(layer.name(),'reload data')
|
||||||
reloader=True
|
reloader = True
|
||||||
self.interface_view(layer,reloader)
|
self.interface_view(layer, reloader)
|
||||||
|
|
||||||
def interface_view(self,layer,reloader):
|
def interface_view(self, layer, reloader):
|
||||||
|
|
||||||
self.description_text.setText(None)
|
self.description_text.setText(None)
|
||||||
self.mots_cles_text.setText(None)
|
self.mots_cles_text.setText(None)
|
||||||
@ -309,27 +297,26 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
self.licence_attrib_box.clear()
|
self.licence_attrib_box.clear()
|
||||||
self.restriction_box.clear()
|
self.restriction_box.clear()
|
||||||
|
|
||||||
all_list=self.fletch_ref()
|
all_list = self.fletch_ref()
|
||||||
|
|
||||||
categories_list=all_list[0]
|
categories_list = all_list[0]
|
||||||
themes_list=all_list[1]
|
themes_list = all_list[1]
|
||||||
langue_list=all_list[2]
|
langue_list = all_list[2]
|
||||||
encodage_list=all_list[3]
|
encodage_list = all_list[3]
|
||||||
frequency_list=all_list[4]
|
frequency_list = all_list[4]
|
||||||
confidentiality_list=all_list[5]
|
confidentiality_list = all_list[5]
|
||||||
license_list=all_list[6]
|
license_list = all_list[6]
|
||||||
type_list=all_list[7]
|
type_list = all_list[7]
|
||||||
mime_list=all_list[8]
|
mime_list = all_list[8]
|
||||||
format_list=all_list[9]
|
format_list = all_list[9]
|
||||||
role_list=all_list[10]
|
role_list = all_list[10]
|
||||||
organisation_list=all_list[11]
|
organisation_list = all_list[11]
|
||||||
|
|
||||||
|
# langue_box
|
||||||
#langue_box
|
|
||||||
self.langue_box.clear()
|
self.langue_box.clear()
|
||||||
self.langue_box.addItem('')
|
self.langue_box.addItem('')
|
||||||
#self.langue_box.addItem('Fr')
|
# self.langue_box.addItem('Fr')
|
||||||
#self.langue_box.addItem('En')
|
# self.langue_box.addItem('En')
|
||||||
for langue_list_data in langue_list:
|
for langue_list_data in langue_list:
|
||||||
self.langue_box.addItem(langue_list_data[0])
|
self.langue_box.addItem(langue_list_data[0])
|
||||||
|
|
||||||
@ -339,46 +326,46 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
self.table_ligne.setText(layer.dataProvider().uri().table())
|
self.table_ligne.setText(layer.dataProvider().uri().table())
|
||||||
self.schema_ligne.setText(layer.dataProvider().uri().schema())
|
self.schema_ligne.setText(layer.dataProvider().uri().schema())
|
||||||
|
|
||||||
#categories_select_view
|
# categories_select_view
|
||||||
self.categories_select_view.setColumnCount(1)
|
self.categories_select_view.setColumnCount(1)
|
||||||
self.categories_select_view.setColumnWidth(0, 230)
|
self.categories_select_view.setColumnWidth(0, 230)
|
||||||
self.categories_select_view.setHorizontalHeaderLabels(['List des categories'])
|
self.categories_select_view.setHorizontalHeaderLabels(['List des categories'])
|
||||||
#categories_view
|
# categories_view
|
||||||
self.categories_view.setRowCount(0)
|
self.categories_view.setRowCount(0)
|
||||||
self.categories_view.setColumnCount(1)
|
self.categories_view.setColumnCount(1)
|
||||||
self.categories_view.setColumnWidth(0, 230)
|
self.categories_view.setColumnWidth(0, 230)
|
||||||
self.categories_view.setHorizontalHeaderLabels(['Categories'])
|
self.categories_view.setHorizontalHeaderLabels(['Categories'])
|
||||||
|
|
||||||
#themes_select_view
|
# themes_select_view
|
||||||
self.themes_select_view.setColumnCount(1)
|
self.themes_select_view.setColumnCount(1)
|
||||||
self.themes_select_view.setColumnWidth(0, 230)
|
self.themes_select_view.setColumnWidth(0, 230)
|
||||||
self.themes_select_view.setHorizontalHeaderLabels(['List des thèmes'])
|
self.themes_select_view.setHorizontalHeaderLabels(['List des thèmes'])
|
||||||
#themes_view
|
# themes_view
|
||||||
self.themes_view.setRowCount(0)
|
self.themes_view.setRowCount(0)
|
||||||
self.themes_view.setColumnCount(1)
|
self.themes_view.setColumnCount(1)
|
||||||
self.themes_view.setColumnWidth(0, 230)
|
self.themes_view.setColumnWidth(0, 230)
|
||||||
self.themes_view.setHorizontalHeaderLabels(['Thèmes'])
|
self.themes_view.setHorizontalHeaderLabels(['Thèmes'])
|
||||||
|
|
||||||
#lien_view
|
# lien_view
|
||||||
self.table_lien.setRowCount(0)
|
self.table_lien.setRowCount(0)
|
||||||
self.table_lien.setColumnCount(6)
|
self.table_lien.setColumnCount(6)
|
||||||
self.table_lien.setColumnWidth(0, 0)
|
self.table_lien.setColumnWidth(0, 0)
|
||||||
self.table_lien.setHorizontalHeaderLabels(['','Type','URL','MIME','Format','Taille'])
|
self.table_lien.setHorizontalHeaderLabels(['', 'Type', 'URL', 'MIME', 'Format', 'Taille'])
|
||||||
|
|
||||||
#contact_view
|
# contact_view
|
||||||
self.table_contact.setRowCount(0)
|
self.table_contact.setRowCount(0)
|
||||||
self.table_contact.setColumnCount(6)
|
self.table_contact.setColumnCount(6)
|
||||||
self.table_contact.setColumnWidth(0, 0)
|
self.table_contact.setColumnWidth(0, 0)
|
||||||
self.table_contact.setHorizontalHeaderLabels(['','Rôle','Nom','Organisation','Email','Telephone'])
|
self.table_contact.setHorizontalHeaderLabels(['', 'Rôle', 'Nom', 'Organisation', 'Email', 'Telephone'])
|
||||||
|
|
||||||
#print(self.date_maj_date.date().toPyDate())
|
# print(self.date_maj_date.date().toPyDate())
|
||||||
vector_extend = layer.extent()
|
vector_extend = layer.extent()
|
||||||
polygone_extend = QgsGeometry.fromRect(vector_extend).asWkt()
|
polygone_extend = QgsGeometry.fromRect(vector_extend).asWkt()
|
||||||
self.extend_plaintext.setPlainText(str(polygone_extend))
|
self.extend_plaintext.setPlainText(str(polygone_extend))
|
||||||
|
|
||||||
qgstype = str(layer.type())[10:]
|
qgstype = str(layer.type())[10:]
|
||||||
|
|
||||||
if qgstype != 'Raster' :
|
if qgstype != 'Raster':
|
||||||
count_layers = str(layer.featureCount())
|
count_layers = str(layer.featureCount())
|
||||||
geomtype = QgsWkbTypes.displayString(layer.wkbType())
|
geomtype = QgsWkbTypes.displayString(layer.wkbType())
|
||||||
elif qgstype == 'Raster':
|
elif qgstype == 'Raster':
|
||||||
@ -392,7 +379,6 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
crs_code = str(layer.crs().authid())
|
crs_code = str(layer.crs().authid())
|
||||||
self.crscode_plaintext.setPlainText(crs_code)
|
self.crscode_plaintext.setPlainText(crs_code)
|
||||||
|
|
||||||
|
|
||||||
self.frequence_box.addItem('')
|
self.frequence_box.addItem('')
|
||||||
self.restriction_box.addItem('')
|
self.restriction_box.addItem('')
|
||||||
self.licence_box.addItem('')
|
self.licence_box.addItem('')
|
||||||
@ -428,12 +414,12 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
self.organisation_box.addItem(organisation_list_data[0])
|
self.organisation_box.addItem(organisation_list_data[0])
|
||||||
|
|
||||||
if reloader:
|
if reloader:
|
||||||
sql_dataload=self.sql_info(layer.dataProvider().uri())
|
sql_dataload = self.sql_info(layer.dataProvider().uri())
|
||||||
sql_contactlink=self.sql_infoother(layer.dataProvider().uri())
|
sql_contactlink = self.sql_infoother(layer.dataProvider().uri())
|
||||||
sql_datalink=sql_contactlink[0]
|
sql_datalink = sql_contactlink[0]
|
||||||
sql_datacontact=sql_contactlink[1]
|
sql_datacontact = sql_contactlink[1]
|
||||||
|
|
||||||
#print(sql_dataload)
|
# print(sql_dataload)
|
||||||
self.titre_line.setText(sql_dataload[4])
|
self.titre_line.setText(sql_dataload[4])
|
||||||
self.date_maj_date.setDateTime(sql_dataload[23])
|
self.date_maj_date.setDateTime(sql_dataload[23])
|
||||||
self.date_publication_date.setDateTime(sql_dataload[11])
|
self.date_publication_date.setDateTime(sql_dataload[11])
|
||||||
@ -444,38 +430,38 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
self.uuid_ligne.setText(sql_dataload[1])
|
self.uuid_ligne.setText(sql_dataload[1])
|
||||||
|
|
||||||
self.categories_view.setRowCount(len(sql_dataload[6]))
|
self.categories_view.setRowCount(len(sql_dataload[6]))
|
||||||
i=0
|
i = 0
|
||||||
for categorie_data in sql_dataload[6]:
|
for categorie_data in sql_dataload[6]:
|
||||||
self.categories_view.setItem(i,0,QTableWidgetItem(categorie_data))
|
self.categories_view.setItem(i, 0, QTableWidgetItem(categorie_data))
|
||||||
i=i+1
|
i = i + 1
|
||||||
self.themes_view.setRowCount(len(sql_dataload[24]))
|
self.themes_view.setRowCount(len(sql_dataload[24]))
|
||||||
i=0
|
i = 0
|
||||||
for themes_data in sql_dataload[24]:
|
for themes_data in sql_dataload[24]:
|
||||||
self.themes_view.setItem(i,0,QTableWidgetItem(themes_data))
|
self.themes_view.setItem(i, 0, QTableWidgetItem(themes_data))
|
||||||
i=i+1
|
i = i + 1
|
||||||
|
|
||||||
self.categories_select_view.setRowCount(len(categories_list)-len(sql_dataload[6]))
|
self.categories_select_view.setRowCount(len(categories_list) - len(sql_dataload[6]))
|
||||||
self.themes_select_view.setRowCount(len(themes_list)-len(sql_dataload[24]))
|
self.themes_select_view.setRowCount(len(themes_list) - len(sql_dataload[24]))
|
||||||
i=0
|
i = 0
|
||||||
for categorie_select_data in categories_list:
|
for categorie_select_data in categories_list:
|
||||||
try:
|
try:
|
||||||
in_index = sql_dataload[6].index(categorie_select_data[0])
|
in_index = sql_dataload[6].index(categorie_select_data[0])
|
||||||
in_index=False
|
in_index = False
|
||||||
except:
|
except ValueError:
|
||||||
in_index=True
|
in_index = True
|
||||||
if in_index:
|
if in_index:
|
||||||
self.categories_select_view.setItem(i,0,QTableWidgetItem(categorie_select_data[0]))
|
self.categories_select_view.setItem(i, 0, QTableWidgetItem(categorie_select_data[0]))
|
||||||
i=i+1
|
i = i + 1
|
||||||
i=0
|
i = 0
|
||||||
for themes_select_data in themes_list:
|
for themes_select_data in themes_list:
|
||||||
try:
|
try:
|
||||||
in_index = sql_dataload[24].index(themes_select_data[0])
|
in_index = sql_dataload[24].index(themes_select_data[0])
|
||||||
in_index=False
|
in_index = False
|
||||||
except:
|
except ValueError:
|
||||||
in_index=True
|
in_index = True
|
||||||
if in_index:
|
if in_index:
|
||||||
self.themes_select_view.setItem(i,0,QTableWidgetItem(themes_select_data[0]))
|
self.themes_select_view.setItem(i, 0, QTableWidgetItem(themes_select_data[0]))
|
||||||
i=i+1
|
i = i + 1
|
||||||
|
|
||||||
array_encodage_box = [self.encodage_box.itemText(i) for i in range(self.encodage_box.count())]
|
array_encodage_box = [self.encodage_box.itemText(i) for i in range(self.encodage_box.count())]
|
||||||
self.encodage_box.setCurrentIndex(array_encodage_box.index(sql_dataload[27]))
|
self.encodage_box.setCurrentIndex(array_encodage_box.index(sql_dataload[27]))
|
||||||
@ -504,35 +490,35 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
array_licence_attrib_box = [self.licence_attrib_box.itemText(i) for i in range(self.licence_attrib_box.count())]
|
array_licence_attrib_box = [self.licence_attrib_box.itemText(i) for i in range(self.licence_attrib_box.count())]
|
||||||
self.licence_attrib_box.setCurrentIndex(array_licence_attrib_box.index(sql_dataload[25]))
|
self.licence_attrib_box.setCurrentIndex(array_licence_attrib_box.index(sql_dataload[25]))
|
||||||
|
|
||||||
c=0
|
c = 0
|
||||||
#self.table_lien.setRowCount(len(sql_datalink))
|
# self.table_lien.setRowCount(len(sql_datalink))
|
||||||
for lien_data in sql_datalink:
|
for lien_data in sql_datalink:
|
||||||
self.table_lien.insertRow(c)
|
self.table_lien.insertRow(c)
|
||||||
self.table_lien.setItem(c,0,QTableWidgetItem(lien_data[1]))
|
self.table_lien.setItem(c, 0, QTableWidgetItem(lien_data[1]))
|
||||||
self.table_lien.setItem(c,1,QTableWidgetItem(lien_data[4]))
|
self.table_lien.setItem(c, 1, QTableWidgetItem(lien_data[4]))
|
||||||
self.table_lien.setItem(c,2,QTableWidgetItem(lien_data[5]))
|
self.table_lien.setItem(c, 2, QTableWidgetItem(lien_data[5]))
|
||||||
self.table_lien.setItem(c,3,QTableWidgetItem(lien_data[6]))
|
self.table_lien.setItem(c, 3, QTableWidgetItem(lien_data[6]))
|
||||||
self.table_lien.setItem(c,4,QTableWidgetItem(lien_data[7]))
|
self.table_lien.setItem(c, 4, QTableWidgetItem(lien_data[7]))
|
||||||
self.table_lien.setItem(c,5,QTableWidgetItem(lien_data[8]))
|
self.table_lien.setItem(c, 5, QTableWidgetItem(lien_data[8]))
|
||||||
c=c+1
|
c = c + 1
|
||||||
c=0
|
c = 0
|
||||||
#self.table_contact.setRowCount(len(sql_datacontact))
|
# self.table_contact.setRowCount(len(sql_datacontact))
|
||||||
for contact_data in sql_datacontact:
|
for contact_data in sql_datacontact:
|
||||||
self.table_contact.insertRow(c)
|
self.table_contact.insertRow(c)
|
||||||
self.table_contact.setItem(c,0,QTableWidgetItem(contact_data[1]))
|
self.table_contact.setItem(c, 0, QTableWidgetItem(contact_data[1]))
|
||||||
self.table_contact.setItem(c,1,QTableWidgetItem(contact_data[4]))
|
self.table_contact.setItem(c, 1, QTableWidgetItem(contact_data[4]))
|
||||||
self.table_contact.setItem(c,2,QTableWidgetItem(contact_data[5]))
|
self.table_contact.setItem(c, 2, QTableWidgetItem(contact_data[5]))
|
||||||
self.table_contact.setItem(c,3,QTableWidgetItem(contact_data[6]))
|
self.table_contact.setItem(c, 3, QTableWidgetItem(contact_data[6]))
|
||||||
self.table_contact.setItem(c,4,QTableWidgetItem(contact_data[7]))
|
self.table_contact.setItem(c, 4, QTableWidgetItem(contact_data[7]))
|
||||||
self.table_contact.setItem(c,5,QTableWidgetItem(contact_data[8]))
|
self.table_contact.setItem(c, 5, QTableWidgetItem(contact_data[8]))
|
||||||
c=c+1
|
c = c + 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
#titre_line
|
# titre_line
|
||||||
self.titre_line.setText(layer.name())
|
self.titre_line.setText(layer.name())
|
||||||
self.langue_box.setCurrentIndex(1)
|
self.langue_box.setCurrentIndex(1)
|
||||||
#date_maj_date
|
# date_maj_date
|
||||||
now = QtCore.QDateTime.currentDateTime()
|
now = QtCore.QDateTime.currentDateTime()
|
||||||
self.date_maj_date.setDateTime(now)
|
self.date_maj_date.setDateTime(now)
|
||||||
self.date_creation_date.setDateTime(now)
|
self.date_creation_date.setDateTime(now)
|
||||||
@ -540,87 +526,89 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
self.date_publication_date.setDateTime(now)
|
self.date_publication_date.setDateTime(now)
|
||||||
self.categories_select_view.setRowCount(len(categories_list))
|
self.categories_select_view.setRowCount(len(categories_list))
|
||||||
self.themes_select_view.setRowCount(len(themes_list))
|
self.themes_select_view.setRowCount(len(themes_list))
|
||||||
i=0
|
i = 0
|
||||||
for categorie_select_data in categories_list:
|
for categorie_select_data in categories_list:
|
||||||
self.categories_select_view.setItem(i,0,QTableWidgetItem(categorie_select_data[0]))
|
self.categories_select_view.setItem(i, 0, QTableWidgetItem(categorie_select_data[0]))
|
||||||
i=i+1
|
i = i + 1
|
||||||
i=0
|
i = 0
|
||||||
for themes_select_data in themes_list:
|
for themes_select_data in themes_list:
|
||||||
self.themes_select_view.setItem(i,0,QTableWidgetItem(themes_select_data[0]))
|
self.themes_select_view.setItem(i, 0, QTableWidgetItem(themes_select_data[0]))
|
||||||
i=i+1
|
i = i + 1
|
||||||
|
|
||||||
#print(self.langue_box.currentText())
|
# print(self.langue_box.currentText())
|
||||||
|
|
||||||
def sql_info(self,uri):
|
def sql_info(self, uri):
|
||||||
cur=login_base()
|
cur = login_base()
|
||||||
table = uri.table()
|
table = uri.table()
|
||||||
schema = uri.schema()
|
schema = uri.schema()
|
||||||
#[s for s in iface.activeLayer().source().split(" ") if "dbname" in s][0].split("'")[1]
|
# [s for s in iface.activeLayer().source().split(" ") if "dbname" in s][0].split("'")[1]
|
||||||
sql_find = """SELECT *,right(left(st_astext(geom,2),-2),-9) FROM metadata.dataset
|
sql_find = """SELECT *, right(left(st_astext(geom,2),-2),-9) FROM metadata.dataset
|
||||||
WHERE schema_name LIKE '"""+schema+"""' AND table_name LIKE '"""+table+"""';"""
|
WHERE schema_name LIKE '""" + schema + """' AND table_name LIKE '""" + table + """';"""
|
||||||
cur.execute(sql_find)
|
cur.execute(sql_find)
|
||||||
data_general = cur.fetchall()
|
data_general = cur.fetchall()
|
||||||
cur.close()
|
cur.close()
|
||||||
return data_general[0]
|
return data_general[0]
|
||||||
|
|
||||||
def sql_infoother(self,uri):
|
def sql_infoother(self, uri):
|
||||||
cur=login_base()
|
cur = login_base()
|
||||||
table = uri.table()
|
table = uri.table()
|
||||||
schema = uri.schema()
|
schema = uri.schema()
|
||||||
|
|
||||||
sql_findlink = """SELECT * FROM metadata.dataurl
|
sql_findlink = """SELECT * FROM metadata.dataurl
|
||||||
WHERE schema_name LIKE '"""+schema+"""' AND table_name LIKE '"""+table+"""';"""
|
WHERE schema_name LIKE '""" + schema + """' AND table_name LIKE '""" + table + """';"""
|
||||||
cur.execute(sql_findlink)
|
cur.execute(sql_findlink)
|
||||||
data_link = cur.fetchall()
|
data_link = cur.fetchall()
|
||||||
|
|
||||||
sql_findcontact = """SELECT * FROM metadata.datacontact
|
sql_findcontact = """SELECT * FROM metadata.datacontact
|
||||||
WHERE schema_name LIKE '"""+schema+"""' AND table_name LIKE '"""+table+"""';"""
|
WHERE schema_name LIKE '""" + schema + """' AND table_name LIKE '""" + table + """';"""
|
||||||
cur.execute(sql_findcontact)
|
cur.execute(sql_findcontact)
|
||||||
data_contact = cur.fetchall()
|
data_contact = cur.fetchall()
|
||||||
|
|
||||||
cur.close()
|
cur.close()
|
||||||
return data_link,data_contact
|
return data_link, data_contact
|
||||||
|
|
||||||
def add_categories_view(self):
|
def add_categories_view(self):
|
||||||
values_add_categories = self.categories_select_view.selectedItems()[0].text()
|
values_add_categories = self.categories_select_view.selectedItems()[0].text()
|
||||||
self.categories_select_view.removeRow(self.categories_select_view.currentRow())
|
self.categories_select_view.removeRow(self.categories_select_view.currentRow())
|
||||||
self.categories_view.insertRow(0)
|
self.categories_view.insertRow(0)
|
||||||
self.categories_view.setItem(0,0,QTableWidgetItem(values_add_categories))
|
self.categories_view.setItem(0, 0, QTableWidgetItem(values_add_categories))
|
||||||
|
|
||||||
def deleter_categories_view(self):
|
def deleter_categories_view(self):
|
||||||
values_deleter_categories = self.categories_view.selectedItems()[0].text()
|
values_deleter_categories = self.categories_view.selectedItems()[0].text()
|
||||||
self.categories_view.removeRow(self.categories_view.currentRow())
|
self.categories_view.removeRow(self.categories_view.currentRow())
|
||||||
self.categories_select_view.insertRow(0)
|
self.categories_select_view.insertRow(0)
|
||||||
self.categories_select_view.setItem(0,0,QTableWidgetItem(values_deleter_categories))
|
self.categories_select_view.setItem(0, 0, QTableWidgetItem(values_deleter_categories))
|
||||||
|
|
||||||
def add_themes_view(self):
|
def add_themes_view(self):
|
||||||
values_add_themes = self.themes_select_view.selectedItems()[0].text()
|
values_add_themes = self.themes_select_view.selectedItems()[0].text()
|
||||||
self.themes_select_view.removeRow(self.themes_select_view.currentRow())
|
self.themes_select_view.removeRow(self.themes_select_view.currentRow())
|
||||||
self.themes_view.insertRow(0)
|
self.themes_view.insertRow(0)
|
||||||
self.themes_view.setItem(0,0,QTableWidgetItem(values_add_themes))
|
self.themes_view.setItem(0, 0, QTableWidgetItem(values_add_themes))
|
||||||
|
|
||||||
def deleter_themes_view(self):
|
def deleter_themes_view(self):
|
||||||
values_deleter_themes = self.themes_view.selectedItems()[0].text()
|
values_deleter_themes = self.themes_view.selectedItems()[0].text()
|
||||||
self.themes_view.removeRow(self.themes_view.currentRow())
|
self.themes_view.removeRow(self.themes_view.currentRow())
|
||||||
self.themes_select_view.insertRow(0)
|
self.themes_select_view.insertRow(0)
|
||||||
self.themes_select_view.setItem(0,0,QTableWidgetItem(values_deleter_themes))
|
self.themes_select_view.setItem(0, 0, QTableWidgetItem(values_deleter_themes))
|
||||||
|
|
||||||
def add_lien(self):
|
def add_lien(self):
|
||||||
cur=login_base()
|
cur = login_base()
|
||||||
maxrow=self.table_lien.rowCount()
|
maxrow = self.table_lien.rowCount()
|
||||||
self.table_lien.insertRow(maxrow)
|
self.table_lien.insertRow(maxrow)
|
||||||
|
|
||||||
table = layer.dataProvider().uri().table()
|
table = layer.dataProvider().uri().table()
|
||||||
schema = layer.dataProvider().uri().schema()
|
schema = layer.dataProvider().uri().schema()
|
||||||
|
|
||||||
if self.taille_line.text() == '':
|
if self.taille_line.text() == '':
|
||||||
sql_sizefile = """SELECT pg_size_pretty(pg_total_relation_size('"""+schema+'.'+table+"""'));"""
|
sql_sizefile = """SELECT pg_size_pretty(pg_total_relation_size('""" + schema + '.' + table + """'));"""
|
||||||
try:
|
try:
|
||||||
cur.execute(sql_sizefile)
|
cur.execute(sql_sizefile)
|
||||||
boolean = True
|
boolean = True
|
||||||
|
|
||||||
except:
|
except psycopg2.errors.UndefinedTable:
|
||||||
boolean = False
|
boolean = False
|
||||||
|
|
||||||
if boolean == True:
|
if boolean is True:
|
||||||
size_file = (cur.fetchall())[0][0]
|
size_file = (cur.fetchall())[0][0]
|
||||||
else:
|
else:
|
||||||
size_file = ''
|
size_file = ''
|
||||||
@ -628,148 +616,159 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
|
|||||||
else:
|
else:
|
||||||
size_file = self.taille_line.text()
|
size_file = self.taille_line.text()
|
||||||
|
|
||||||
self.table_lien.setItem(maxrow,0,QTableWidgetItem('new_value'))
|
self.table_lien.setItem(maxrow, 0, QTableWidgetItem('new_value'))
|
||||||
self.table_lien.setItem(maxrow,1,QTableWidgetItem(self.type_box.currentText()))
|
self.table_lien.setItem(maxrow, 1, QTableWidgetItem(self.type_box.currentText()))
|
||||||
self.table_lien.setItem(maxrow,2,QTableWidgetItem(self.url_line.text()))
|
self.table_lien.setItem(maxrow, 2, QTableWidgetItem(self.url_line.text()))
|
||||||
self.table_lien.setItem(maxrow,3,QTableWidgetItem(self.mime_box.currentText()))
|
self.table_lien.setItem(maxrow, 3, QTableWidgetItem(self.mime_box.currentText()))
|
||||||
self.table_lien.setItem(maxrow,4,QTableWidgetItem(self.format_box.currentText()))
|
self.table_lien.setItem(maxrow, 4, QTableWidgetItem(self.format_box.currentText()))
|
||||||
self.table_lien.setItem(maxrow,5,QTableWidgetItem(str(size_file)))
|
self.table_lien.setItem(maxrow, 5, QTableWidgetItem(str(size_file)))
|
||||||
|
|
||||||
global array_link
|
global array_link
|
||||||
array_link += "('"+ table +"','"+ schema +"','"+ self.type_box.currentText() +"','"+ self.url_line.text() +"','"+ self.mime_box.currentText() +"','"+ self.format_box.currentText() +"','"+ size_file +"'),"
|
array_link += "('" + table + "', '" + schema + "', '" + self.type_box.currentText() + "', '" + self.url_line.text() + "', '" + self.mime_box.currentText() + "', '" + self.format_box.currentText() + "', '" + size_file + "'),"
|
||||||
|
|
||||||
cur.close()
|
cur.close()
|
||||||
|
|
||||||
def add_contact(self):
|
def add_contact(self):
|
||||||
maxrow=self.table_contact.rowCount()
|
maxrow = self.table_contact.rowCount()
|
||||||
self.table_contact.insertRow(maxrow)
|
self.table_contact.insertRow(maxrow)
|
||||||
|
|
||||||
self.table_contact.setItem(maxrow,0,QTableWidgetItem('new_value'))
|
self.table_contact.setItem(maxrow, 0, QTableWidgetItem('new_value'))
|
||||||
self.table_contact.setItem(maxrow,1,QTableWidgetItem(self.role_box.currentText()))
|
self.table_contact.setItem(maxrow, 1, QTableWidgetItem(self.role_box.currentText()))
|
||||||
self.table_contact.setItem(maxrow,2,QTableWidgetItem(self.nom_line.text()))
|
self.table_contact.setItem(maxrow, 2, QTableWidgetItem(self.nom_line.text()))
|
||||||
self.table_contact.setItem(maxrow,3,QTableWidgetItem(self.organisation_box.currentText()))
|
self.table_contact.setItem(maxrow, 3, QTableWidgetItem(self.organisation_box.currentText()))
|
||||||
self.table_contact.setItem(maxrow,4,QTableWidgetItem(self.email_line.text()))
|
self.table_contact.setItem(maxrow, 4, QTableWidgetItem(self.email_line.text()))
|
||||||
self.table_contact.setItem(maxrow,5,QTableWidgetItem(self.telephone_line.text()))
|
self.table_contact.setItem(maxrow, 5, QTableWidgetItem(self.telephone_line.text()))
|
||||||
|
|
||||||
table = layer.dataProvider().uri().table()
|
table = layer.dataProvider().uri().table()
|
||||||
schema = layer.dataProvider().uri().schema()
|
schema = layer.dataProvider().uri().schema()
|
||||||
|
|
||||||
global array_contact
|
global array_contact
|
||||||
array_contact += "('"+ table +"','"+ schema +"','"+ self.role_box.currentText() +"','"+ self.nom_line.text() +"','"+ self.organisation_box.currentText() +"','"+ self.email_line.text() +"','"+ self.telephone_line.text() +"'),"
|
array_contact += "('" + table + "', '" + schema + "', '" + self.role_box.currentText() + "', '" + self.nom_line.text() + "', '" + self.organisation_box.currentText() + "', '" + self.email_line.text() + "', '" + self.telephone_line.text() + "'),"
|
||||||
|
|
||||||
def delete_lien(self):
|
def delete_lien(self):
|
||||||
|
fin = ''
|
||||||
global uid_delete_list_link,array_link
|
global uid_delete_list_link, array_link
|
||||||
lien_uid = self.table_lien.item(self.table_lien.currentRow(),0).text()
|
try:
|
||||||
|
lien_uid = self.table_lien.item(self.table_lien.currentRow(), 0).text()
|
||||||
|
except AttributeError:
|
||||||
|
lien_uid = True
|
||||||
self.table_lien.removeRow(self.table_lien.currentRow())
|
self.table_lien.removeRow(self.table_lien.currentRow())
|
||||||
if lien_uid == 'new_value':
|
if lien_uid == 'new_value':
|
||||||
position = self.table_lien.currentRow()
|
position = self.table_lien.currentRow()
|
||||||
if position < 0:
|
if position < 0:
|
||||||
position=position+1
|
position = position + 1
|
||||||
run_x = 0
|
run_x = 0
|
||||||
while position >= run_x:
|
while position >= run_x:
|
||||||
#print(position,run_x)
|
# print(position, run_x)
|
||||||
if run_x == 0:
|
if run_x == 0:
|
||||||
debut = array_link.find("(")
|
debut = array_link.find("(")
|
||||||
else:
|
else:
|
||||||
debut = array_link.find("(",fin+1)
|
debut = array_link.find("(", fin + 1)
|
||||||
fin = array_link.find(")",debut)
|
fin = array_link.find(")", debut)
|
||||||
#print(debut,fin)
|
# print(debut, fin)
|
||||||
if run_x == 50:
|
if run_x == 50:
|
||||||
break
|
break
|
||||||
run_x+=1
|
run_x += 1
|
||||||
#print(array_link[fin+1:])
|
# print(array_link[fin + 1:])
|
||||||
if debut <= 0:
|
if debut <= 0:
|
||||||
debut = 1
|
debut = 1
|
||||||
fin+= 1
|
fin += 1
|
||||||
array_link = array_link[:debut-1]+array_link[fin+1:]
|
array_link = array_link[:debut - 1] + array_link[fin + 1:]
|
||||||
#print('a:',array_link)
|
# print('a:', array_link)
|
||||||
|
elif lien_uid is True:
|
||||||
|
print('Pas de ligne "Lien"')
|
||||||
else:
|
else:
|
||||||
uid_delete_list_link += "'"+lien_uid+"',"
|
uid_delete_list_link += "'" + lien_uid + "',"
|
||||||
|
|
||||||
def delete_contact(self):
|
def delete_contact(self):
|
||||||
global uid_delete_list_contact,array_contact
|
fin = ''
|
||||||
contact_uid = self.table_contact.item(self.table_contact.currentRow(),0).text()
|
global uid_delete_list_contact, array_contact
|
||||||
|
try:
|
||||||
|
contact_uid = self.table_contact.item(self.table_contact.currentRow(), 0).text()
|
||||||
|
except AttributeError:
|
||||||
|
contact_uid = True
|
||||||
self.table_contact.removeRow(self.table_contact.currentRow())
|
self.table_contact.removeRow(self.table_contact.currentRow())
|
||||||
if contact_uid == 'new_value':
|
if contact_uid == 'new_value':
|
||||||
position = self.table_contact.currentRow()
|
position = self.table_contact.currentRow()
|
||||||
if position < 0:
|
if position < 0:
|
||||||
position=position+1
|
position = position + 1
|
||||||
#print('p:',position)
|
# print('p:', position)
|
||||||
run_x = 0
|
run_x = 0
|
||||||
while position >= run_x:
|
while position >= run_x:
|
||||||
if run_x == 0:
|
if run_x == 0:
|
||||||
debut = array_contact.find("(")
|
debut = array_contact.find("(")
|
||||||
else:
|
else:
|
||||||
debut = array_contact.find("(",fin+1)
|
debut = array_contact.find("(", fin + 1)
|
||||||
fin = array_contact.find(")",debut)
|
fin = array_contact.find(")", debut)
|
||||||
#print(debut,fin)
|
# print(debut, fin)
|
||||||
if run_x == 50:
|
if run_x == 50:
|
||||||
break
|
break
|
||||||
run_x+=1
|
run_x += 1
|
||||||
#print(array_contact[fin+1:])
|
# print(array_contact[fin + 1:])
|
||||||
if debut <= 0:
|
if debut <= 0:
|
||||||
debut = 1
|
debut = 1
|
||||||
fin+= 1
|
fin += 1
|
||||||
array_contact = array_contact[:debut-1]+array_contact[fin+1:]
|
array_contact = array_contact[:debut - 1] + array_contact[fin + 1:]
|
||||||
#print('a:',array_contact)
|
# print('a:', array_contact)
|
||||||
|
elif contact_uid is True:
|
||||||
|
print('Pas de ligne "Contact"')
|
||||||
else:
|
else:
|
||||||
uid_delete_list_contact += "'"+contact_uid+"',"
|
uid_delete_list_contact += "'" + contact_uid + "',"
|
||||||
|
|
||||||
|
|
||||||
def fletch_ref(self):
|
def fletch_ref(self):
|
||||||
cur=login_base()
|
cur = login_base()
|
||||||
|
|
||||||
SQL_categories="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.categories' ORDER BY code,item_order;"""
|
SQL_categories = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.categories' ORDER BY code, item_order;"""
|
||||||
SQL_themes="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.themes' ORDER BY label_fr;"""
|
SQL_themes = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.themes' ORDER BY label_fr;"""
|
||||||
SQL_langue="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.langue';"""
|
SQL_langue = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.langue';"""
|
||||||
SQL_encodage="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.encodage';"""
|
SQL_encodage = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.encodage';"""
|
||||||
SQL_frequency="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.publication_frequency' ORDER BY label_fr;"""
|
SQL_frequency = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.publication_frequency' ORDER BY label_fr;"""
|
||||||
SQL_confidentiality="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.confidentiality' ORDER BY label_fr;"""
|
SQL_confidentiality = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.confidentiality' ORDER BY label_fr;"""
|
||||||
SQL_license="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.license' ORDER BY label_fr;"""
|
SQL_license = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'dataset.license' ORDER BY label_fr;"""
|
||||||
SQL_type="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'link.type' ORDER BY label_fr;"""
|
SQL_type = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'link.type' ORDER BY label_fr;"""
|
||||||
SQL_mime="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'link.mime' ORDER BY label_fr;"""
|
SQL_mime = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'link.mime' ORDER BY label_fr;"""
|
||||||
SQL_format="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'link.format' ORDER BY label_fr;"""
|
SQL_format = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'link.format' ORDER BY label_fr;"""
|
||||||
SQL_role="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'contact.contact_role' ORDER BY label_fr;"""
|
SQL_role = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'contact.contact_role' ORDER BY label_fr;"""
|
||||||
SQL_organisation="""SELECT label_fr FROM metadata.glossary WHERE field LIKE 'contact.organisation' ORDER BY label_fr;"""
|
SQL_organisation = """SELECT label_fr FROM metadata.glossary WHERE field LIKE 'contact.organisation' ORDER BY label_fr;"""
|
||||||
|
|
||||||
cur.execute(SQL_categories)
|
cur.execute(SQL_categories)
|
||||||
categories_list=cur.fetchall()
|
categories_list = cur.fetchall()
|
||||||
cur.execute(SQL_themes)
|
cur.execute(SQL_themes)
|
||||||
themes_list=cur.fetchall()
|
themes_list = cur.fetchall()
|
||||||
cur.execute(SQL_langue)
|
cur.execute(SQL_langue)
|
||||||
langue_list=cur.fetchall()
|
langue_list = cur.fetchall()
|
||||||
cur.execute(SQL_encodage)
|
cur.execute(SQL_encodage)
|
||||||
encodage_list=cur.fetchall()
|
encodage_list = cur.fetchall()
|
||||||
|
|
||||||
cur.execute(SQL_frequency)
|
cur.execute(SQL_frequency)
|
||||||
frequency_list=cur.fetchall()
|
frequency_list = cur.fetchall()
|
||||||
cur.execute(SQL_confidentiality)
|
cur.execute(SQL_confidentiality)
|
||||||
confidentiality_list=cur.fetchall()
|
confidentiality_list = cur.fetchall()
|
||||||
cur.execute(SQL_license)
|
cur.execute(SQL_license)
|
||||||
license_list=cur.fetchall()
|
license_list = cur.fetchall()
|
||||||
|
|
||||||
cur.execute(SQL_type)
|
cur.execute(SQL_type)
|
||||||
type_list=cur.fetchall()
|
type_list = cur.fetchall()
|
||||||
cur.execute(SQL_mime)
|
cur.execute(SQL_mime)
|
||||||
mime_list=cur.fetchall()
|
mime_list = cur.fetchall()
|
||||||
cur.execute(SQL_format)
|
cur.execute(SQL_format)
|
||||||
format_list=cur.fetchall()
|
format_list = cur.fetchall()
|
||||||
cur.execute(SQL_role)
|
cur.execute(SQL_role)
|
||||||
role_list=cur.fetchall()
|
role_list = cur.fetchall()
|
||||||
cur.execute(SQL_organisation)
|
cur.execute(SQL_organisation)
|
||||||
organisation_list=cur.fetchall()
|
organisation_list = cur.fetchall()
|
||||||
|
|
||||||
return categories_list,themes_list,langue_list,encodage_list,frequency_list,confidentiality_list,license_list,type_list,mime_list,format_list,role_list,organisation_list
|
return categories_list, themes_list, langue_list, encodage_list, frequency_list, confidentiality_list, license_list, type_list, mime_list, format_list, role_list, organisation_list
|
||||||
|
|
||||||
cur.close()
|
cur.close()
|
||||||
|
|
||||||
def py_import_xml(self):
|
def py_import_xml(self):
|
||||||
folder = QFileDialog.getOpenFileName()
|
folder = QFileDialog.getOpenFileName()
|
||||||
if folder:
|
if folder:
|
||||||
folder=folder[0]
|
folder = folder[0]
|
||||||
if folder[len(folder)-4:] == '.xml' :
|
if folder[len(folder) - 4:] == '.xml':
|
||||||
print('is .xml')
|
print('is .xml')
|
||||||
def issues_open(self):
|
|
||||||
self.issues = CenRa_Issues()
|
# def issues_open(self):
|
||||||
self.issues.show()
|
# self.issues = CenRa_Issues()
|
||||||
|
# self.issues.show()
|
||||||
|
|||||||
@ -3,9 +3,12 @@
|
|||||||
import configparser
|
import configparser
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
# import base64
|
||||||
|
# import psycopg2
|
||||||
|
# import psycopg2.extras
|
||||||
import os
|
import os
|
||||||
from os.path import abspath, join, pardir, dirname
|
from os.path import abspath, join, pardir, dirname
|
||||||
from qgis.PyQt.QtWidgets import QApplication
|
|
||||||
from qgis.PyQt import uic
|
from qgis.PyQt import uic
|
||||||
|
|
||||||
__copyright__ = "Copyright 2019, 3Liz"
|
__copyright__ = "Copyright 2019, 3Liz"
|
||||||
@ -92,14 +95,6 @@ def resources_path(*args):
|
|||||||
path = abspath(join(path, item))
|
path = abspath(join(path, item))
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def pyperclip():
|
|
||||||
dst = dirname(dirname(__file__))+"\\tools\\"
|
|
||||||
if os.access('N:/',os.R_OK):
|
|
||||||
src = 'N:/SI_Systeme d information/Z_QGIS/PLUGIN/PythonSQL.py'
|
|
||||||
try:
|
|
||||||
shutil.copy(src, dst)
|
|
||||||
except:
|
|
||||||
print('404')
|
|
||||||
|
|
||||||
def load_ui(*args):
|
def load_ui(*args):
|
||||||
"""Get compile UI file.
|
"""Get compile UI file.
|
||||||
@ -113,65 +108,77 @@ def load_ui(*args):
|
|||||||
|
|
||||||
return ui_class
|
return ui_class
|
||||||
|
|
||||||
def send_issues(url,titre,body,labels):
|
|
||||||
|
def pyperclip():
|
||||||
|
dst = dirname(dirname(__file__)) + "\\tools\\"
|
||||||
|
if os.access('N:/', os.R_OK):
|
||||||
|
src = 'N:/SI_Systeme d information/Z_QGIS/PLUGIN/PythonSQL.py'
|
||||||
|
try:
|
||||||
|
shutil.copy(src, dst)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print('404')
|
||||||
|
except UnboundLocalError:
|
||||||
|
print('404')
|
||||||
|
|
||||||
|
|
||||||
|
def send_issues(url, titre, body, labels):
|
||||||
import requests
|
import requests
|
||||||
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
import os
|
# import os
|
||||||
import qgis
|
# import qgis
|
||||||
|
|
||||||
usr = os.environ['USERNAME']
|
# usr = os.environ['USERNAME']
|
||||||
token = '9d0a4e0bea561710e0728f161f7edf4e5201e112'
|
token = '9d0a4e0bea561710e0728f161f7edf4e5201e112'
|
||||||
url=url+'?token='+token
|
url = url + '?token=' + token
|
||||||
|
|
||||||
headers = {'Authorization': 'token ' + token,'accept': 'application/json','Content-Type': 'application/json'}
|
|
||||||
|
|
||||||
|
headers = {'Authorization': 'token ' + token, 'accept': 'application/json', 'Content-Type': 'application/json'}
|
||||||
|
|
||||||
payload = {'title': titre, 'body': body, 'labels': labels}
|
payload = {'title': titre, 'body': body, 'labels': labels}
|
||||||
try:
|
try:
|
||||||
urllib.request.urlopen('https://google.com')
|
urllib.request.urlopen('https://google.com')
|
||||||
binar = True
|
binar = True
|
||||||
except:
|
except ValueError:
|
||||||
binar = False
|
binar = False
|
||||||
r = ''
|
r = ''
|
||||||
if binar:
|
if binar:
|
||||||
r = requests.post(url, data=json.dumps(payload), headers=headers)
|
r = requests.post(url, data=json.dumps(payload), headers=headers)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def maj_verif(NAME):
|
def maj_verif(NAME):
|
||||||
import qgis
|
import qgis
|
||||||
import urllib.request
|
import urllib.request
|
||||||
iface = qgis.utils.iface
|
iface = qgis.utils.iface
|
||||||
from qgis.core import Qgis
|
from qgis.core import Qgis
|
||||||
|
|
||||||
url = qgis.utils.pluginMetadata(NAME,'repository')
|
# url = qgis.utils.pluginMetadata(NAME, 'repository')
|
||||||
#URL = url+'/raw/branch/main/plugins.xml'
|
# URL = url+'/raw/branch/main/plugins.xml'
|
||||||
URL = 'https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS/releases/download/latest/plugins.xml'
|
URL = 'https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS/releases/download/latest/plugins.xml'
|
||||||
# print(URL)
|
# print(URL)
|
||||||
version = qgis.utils.pluginMetadata(NAME,'version')
|
version = qgis.utils.pluginMetadata(NAME, 'version')
|
||||||
len_version = len(version)
|
len_version = len(version)
|
||||||
try:
|
try:
|
||||||
urllib.request.urlopen('https://google.com')
|
urllib.request.urlopen('https://google.com')
|
||||||
binar = True
|
binar = True
|
||||||
except:
|
except urllib.error.URLError:
|
||||||
binar = False
|
binar = False
|
||||||
if binar:
|
if binar:
|
||||||
try:
|
try:
|
||||||
version_web = str(urllib.request.urlopen(URL).read())
|
version_web = str(urllib.request.urlopen(URL).read())
|
||||||
plugin_num = version_web.find(NAME)
|
plugin_num = version_web.find(NAME)
|
||||||
valeur_version_web = version_web.find('<version>',plugin_num)+9
|
valeur_version_web = version_web.find('<version>', plugin_num) + 9
|
||||||
version_plugin = version_web[valeur_version_web:valeur_version_web+len_version]
|
version_plugin = version_web[valeur_version_web:valeur_version_web + len_version]
|
||||||
if version_plugin != version:
|
if version_plugin != version:
|
||||||
iface.messageBar().pushMessage("MAJ :", "Des mise à jour de plugin sont disponibles.", level=Qgis.Info, duration=30)
|
iface.messageBar().pushMessage("MAJ :", "Des mise à jour de plugin sont disponibles.", level=Qgis.Info, duration=30)
|
||||||
except:
|
except urllib.error.URLError:
|
||||||
print("error gitea version ssl")
|
print("error gitea version ssl")
|
||||||
else:
|
else:
|
||||||
iface.messageBar().pushMessage("WiFi :", "Pas de connection à internet.", level=Qgis.Warning, duration=30)
|
iface.messageBar().pushMessage("WiFi :", "Pas de connection à internet.", level=Qgis.Warning, duration=30)
|
||||||
|
|
||||||
def tr(text, context="@default"):
|
|
||||||
return QApplication.translate(context, text)
|
|
||||||
|
|
||||||
def devlog(NAME):
|
def devlog(NAME):
|
||||||
import qgis
|
import qgis
|
||||||
devmaj = '<head><style>* {margin:0; padding:0; }</style></head>'
|
devmaj = '<head><style>* {margin:0; padding:0; }</style></head>'
|
||||||
devmaj = devmaj+qgis.utils.pluginMetadata(NAME,'changelog')
|
devmaj = devmaj + qgis.utils.pluginMetadata(NAME, 'changelog')
|
||||||
return devmaj
|
return devmaj
|
||||||
Loading…
x
Reference in New Issue
Block a user