-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set the main owner for the attribution credits in layer properties #55
Draft
Gustry
wants to merge
1
commit into
3liz:master
Choose a base branch
from
Gustry:main_attribution
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
from qgis.core import ( | ||
NULL, | ||
QgsAbstractDatabaseProviderConnection, | ||
QgsApplication, | ||
QgsProviderConnectionException, | ||
QgsProviderRegistry, | ||
|
@@ -269,6 +270,7 @@ def layer_changed(self, layer): | |
|
||
self.set_html_content(body=data[0][0]) | ||
self.save_button.setEnabled(True) | ||
self.set_layer_metadata(layer, connection, uri.schema(), uri.table()) | ||
self.current_datasource_uri = uri | ||
self.current_connection = connection | ||
|
||
|
@@ -314,3 +316,39 @@ def set_html_content(self, title=None, body=None): | |
def default_html_content(self): | ||
self.set_html_content( | ||
'PgMetadata', tr('You should click on a layer in the legend which is stored in PostgreSQL.')) | ||
|
||
@staticmethod | ||
def set_layer_metadata( | ||
layer: QgsVectorLayer, | ||
connection: QgsAbstractDatabaseProviderConnection, | ||
schema: str, | ||
table: str, | ||
): | ||
""" Set the main owner contact for the attribution. """ | ||
sql = ( | ||
"SELECT name FROM pgmetadata.v_contact " | ||
f"WHERE table_name = '{table}' " | ||
f"AND schema_name = '{schema}' " | ||
"ORDER BY CASE " | ||
"WHEN contact_role_code = 'OW' then 1 " | ||
"WHEN contact_role_code = 'DI' then 2 " | ||
"WHEN contact_role_code = 'CU' then 3 " | ||
"ELSE 10 " | ||
"END ASC " | ||
"LIMIT 1;" | ||
) | ||
|
||
data = connection.executeSql(sql) | ||
if not data: | ||
return | ||
|
||
if data[0] == NULL or data[0][0] == NULL: | ||
return | ||
|
||
# QGIS Server panel | ||
layer.setAttribution(data[0][0]) | ||
|
||
# Metadata panel | ||
metadata = layer.metadata() | ||
metadata.setRights([data[0][0]]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we always override existing metadata, or only if a new checkbox is checked in options ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you successfully run the code above? |
||
layer.setMetadata(metadata) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also add title and abstract to the QGIS Server corresponding properties ? Related to Lizmap plugin too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which code can we use to add title and abstract to the QGIS server corresponding properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mwekezi I think you should raise your topic in an issue, but not in a pull request. This one was a WIP, work in progress.
You need to use some Python to make it automatic for now. (semi-automatic to synchronize database metadata into the layer properties)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I tried running this code in the python console of QGIS but it didn't work. It mentioned an indentation error. Could you help with how I could successfully run the code above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
"Indentation error" is the most common Python error. Before digging in this project, I suggest you to read about programming with Python, follow a tutorial about Python, you will be able to understand why you couldn't run the code.