Exemple #1
0
    def _get_catalog(self):
        """convenience function to init catalog wrapper"""

        auth = None

        if self.disable_ssl_verification:
            try:
                auth = Authentication(verify=False)
            except NameError:
                pass

        # connect to the server
        with OverrideCursor(Qt.WaitCursor):
            try:
                self.catalog = get_catalog_service(
                    self.catalog_url,
                    catalog_type=self.catalog_type,
                    timeout=self.timeout,
                    username=self.catalog_username or None,
                    password=self.catalog_password or None,
                    auth=auth)
                return True
            except Exception as err:
                msg = self.tr('Error connecting to service: {0}').format(err)

        QMessageBox.warning(self, self.tr('CSW Connection error'), msg)
        return False
Exemple #2
0
    def show_metadata(self):
        """show record metadata"""

        if not self.treeRecords.selectedItems():
            return

        item = self.treeRecords.currentItem()
        if not item:
            return

        identifier = get_item_data(item, 'identifier')

        self.disable_ssl_verification = self.disableSSLVerification.isChecked()
        auth = None

        if self.disable_ssl_verification:
            try:
                auth = Authentication(verify=False)
            except NameError:
                pass

        try:
            with OverrideCursor(Qt.WaitCursor):
                cat = get_catalog_service(
                    self.catalog_url,  # spellok
                    catalog_type=self.catalog_type,
                    timeout=self.timeout,
                    username=self.catalog_username,
                    password=self.catalog_password,
                    auth=auth)
                record = cat.get_record(identifier)
                if cat.type == 'OGC API - Records':
                    record['url'] = cat.conn.request
                elif cat.type == 'OGC CSW 2.0.2':
                    record.url = cat.conn.request

        except Exception as err:
            QMessageBox.warning(
                self, self.tr('GetRecords error'),
                self.tr('Error getting response: {0}').format(err))
            return
        except KeyError as err:
            QMessageBox.warning(
                self, self.tr('Record parsing error'),
                self.tr('Unable to locate record identifier: {0}').format(err))
            return

        crd = RecordDialog()
        metadata = render_template('en', self.context, record,
                                   self.catalog.record_info_template)

        style = QgsApplication.reportStyleSheet()
        crd.textMetadata.document().setDefaultStyleSheet(style)
        crd.textMetadata.setHtml(metadata)
        crd.exec_()