From c20d004be957be2701e7e5aa9aa718f95b60973b Mon Sep 17 00:00:00 2001 From: "Julien M." Date: Mon, 29 Apr 2024 14:03:45 +0200 Subject: [PATCH 1/5] feature(ui): connect to github issue form --- qtribu/gui/form_rdp_news.py | 27 +++++++++++++++++++++------ qtribu/gui/form_rdp_news.ui | 23 +++++------------------ 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/qtribu/gui/form_rdp_news.py b/qtribu/gui/form_rdp_news.py index 75815b8a..5de77103 100644 --- a/qtribu/gui/form_rdp_news.py +++ b/qtribu/gui/form_rdp_news.py @@ -16,7 +16,7 @@ from qgis.PyQt import uic from qgis.PyQt.QtCore import Qt from qgis.PyQt.QtGui import QIcon -from qgis.PyQt.QtWidgets import QDialog +from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox # plugin from qtribu.__about__ import DIR_PLUGIN_ROOT @@ -75,13 +75,19 @@ def __init__(self, parent=None): ) ) - # connect help button + # connect standard buttons + self.btn_box: QDialogButtonBox = self.btn_box self.btn_box.helpRequested.connect( partial( open_url_in_browser, "https://contribuer.geotribu.fr/rdp/add_news/", ) ) + self.btn_box.button(QDialogButtonBox.Open).setText(self.tr("Load draft")) + self.btn_box.button(QDialogButtonBox.Open).clicked.connect(self.on_btn_open) + self.btn_box.button(QDialogButtonBox.Save).setText(self.tr("Save draft")) + self.btn_box.button(QDialogButtonBox.Ok).setText(self.tr("Submit")) + self.btn_box.button(QDialogButtonBox.Ok).setDefault(True) def cbb_icon_populate(self) -> None: """Populate combobox of news icons.""" @@ -164,11 +170,20 @@ def generate_preview(self) -> None: self.txt_preview.clear() self.txt_preview.setMarkdown(md_txt) - def accept(self) -> bool: - """Auto-connected to the OK button (within the button box), i.e. the `accepted` - signal. Check if required form fields are correctly filled. + def on_btn_open(self): - :return: False if some check fails. True and emit accepted() signal if everything is ok. + self.log("piouou") + + def on_btn_save(self): + + self.log("piouou") + + def on_btn_submit(self) -> bool: + """Check if required form fields are correctly filled and submit to Github issue + form. + + :return: False if some check fails. True and emit accepted() signal if + everything is ok. :rtype: bool """ invalid_fields = [] diff --git a/qtribu/gui/form_rdp_news.ui b/qtribu/gui/form_rdp_news.ui index 7a77cc43..cdb70d21 100644 --- a/qtribu/gui/form_rdp_news.ui +++ b/qtribu/gui/form_rdp_news.ui @@ -14,7 +14,7 @@ GeoRDP - News Form - 0.98 + 0.980000000000000 @@ -299,6 +299,9 @@ p, li { white-space: pre-wrap; } + + + @@ -318,7 +321,7 @@ p, li { white-space: pre-wrap; } Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok + QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok|QDialogButtonBox::Open|QDialogButtonBox::Save @@ -385,22 +388,6 @@ p, li { white-space: pre-wrap; } - - btn_box - accepted() - dlg_form_rdp_news - accept() - - - 248 - 254 - - - 157 - 274 - - - btn_box rejected() From e48e736e804398644e38ebedc6629bc1efe89dfa Mon Sep 17 00:00:00 2001 From: "Julien M." Date: Mon, 29 Apr 2024 15:52:18 +0200 Subject: [PATCH 2/5] feature(form): connect rdp form to issue template --- qtribu/gui/form_rdp_news.py | 70 +++++++++++++++++++++++++------------ qtribu/gui/form_rdp_news.ui | 11 +++--- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/qtribu/gui/form_rdp_news.py b/qtribu/gui/form_rdp_news.py index 5de77103..de339cdf 100644 --- a/qtribu/gui/form_rdp_news.py +++ b/qtribu/gui/form_rdp_news.py @@ -9,6 +9,7 @@ # standard from functools import partial from pathlib import Path +from typing import Union from urllib.parse import urlparse # PyQGIS @@ -19,7 +20,7 @@ from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox # plugin -from qtribu.__about__ import DIR_PLUGIN_ROOT +from qtribu.__about__ import DIR_PLUGIN_ROOT, __title__, __version__ from qtribu.constants import GEORDP_NEWS_CATEGORIES, GEORDP_NEWS_ICONS, GeotribuImage from qtribu.toolbelt import NetworkRequestsManager, PlgLogger, PlgOptionsManager from qtribu.toolbelt.commons import open_url_in_browser @@ -29,6 +30,9 @@ class RdpNewsForm(QDialog): """QDialog form to submit a news to a next GeoRDP.""" LOCAL_CDN_PATH: Path = Path().home() / ".geotribu/cdn/" + ISSUE_FORM_BASE_URL: str = ( + "https://github.com/geotribu/website/issues/new?template=RDP_NEWS.yml" + ) def __init__(self, parent=None): """Constructor. @@ -83,11 +87,9 @@ def __init__(self, parent=None): "https://contribuer.geotribu.fr/rdp/add_news/", ) ) - self.btn_box.button(QDialogButtonBox.Open).setText(self.tr("Load draft")) - self.btn_box.button(QDialogButtonBox.Open).clicked.connect(self.on_btn_open) - self.btn_box.button(QDialogButtonBox.Save).setText(self.tr("Save draft")) - self.btn_box.button(QDialogButtonBox.Ok).setText(self.tr("Submit")) + self.btn_box.button(QDialogButtonBox.Ok).clicked.connect(self.on_btn_submit) self.btn_box.button(QDialogButtonBox.Ok).setDefault(True) + self.btn_box.button(QDialogButtonBox.Ok).setText(self.tr("Submit")) def cbb_icon_populate(self) -> None: """Populate combobox of news icons.""" @@ -170,22 +172,7 @@ def generate_preview(self) -> None: self.txt_preview.clear() self.txt_preview.setMarkdown(md_txt) - def on_btn_open(self): - - self.log("piouou") - - def on_btn_save(self): - - self.log("piouou") - - def on_btn_submit(self) -> bool: - """Check if required form fields are correctly filled and submit to Github issue - form. - - :return: False if some check fails. True and emit accepted() signal if - everything is ok. - :rtype: bool - """ + def check_required_fields(self) -> bool: invalid_fields = [] error_message = "" @@ -252,6 +239,43 @@ def on_btn_submit(self) -> bool: for wdg in invalid_fields: wdg.setStyleSheet("border: 1px solid red;") return False + + return True + + def on_btn_submit(self) -> Union[bool, str, None]: + """Check if required form fields are correctly filled and submit to Github issue + form. + + :return: False if some check fails. True and emit accepted() signal if + everything is ok. + :rtype: bool + """ + if not self.check_required_fields(): + return False + + completed_url = ( + f"{self.ISSUE_FORM_BASE_URL}" + f"&in_author_name={self.wdg_author.lne_firstname.text()} " + f"{self.wdg_author.lne_lastname.text()}" + f"&in_author_mail={self.wdg_author.lne_email.text()}" + f"&in_author_linkedin={self.wdg_author.lne_linkedin_account.text()}" + f"&in_author_mastodon={self.wdg_author.lne_mastodon_account.text()}" + f"&in_author_twitter={self.wdg_author.lne_twitter_account.text()}" + f"&in_author_license=true" + f"&cb_author_content_relationship={self.chb_transparency.isChecked()}" + f"&dr_news_category={self.cbb_category.currentText()}" + f"&in_news_title={self.lne_title.text()}" + f"&in_news_icon={self.cbb_icon.currentText()}" + f"&tx_news_content={self.txt_body.toPlainText()}" + f"&tx_misc_comment={self.txt_comment.toPlainText()}" + f"&title=[GeoRDP] {self.lne_title.text()} - {__title__} {__version__}" + ) + self.log(message=f"Opening issue form: {completed_url}", log_level=4) + url_opened = open_url_in_browser(url=completed_url) + if url_opened: + self.log(message="URL opened!", push=True, duration=2, log_level=0) else: - super().accept() - return True + self.log(message="URL NOT OPENEDED :(", push=True, duration=4, log_level=2) + + super().accept() + return True diff --git a/qtribu/gui/form_rdp_news.ui b/qtribu/gui/form_rdp_news.ui index cdb70d21..13ae573d 100644 --- a/qtribu/gui/form_rdp_news.ui +++ b/qtribu/gui/form_rdp_news.ui @@ -6,7 +6,7 @@ 0 0 - 763 + 891 1156 @@ -267,14 +267,14 @@ p, li { white-space: pre-wrap; } - + Transparency: - + I'm not related to the published content. If not, I give some details in the comment area. @@ -321,13 +321,10 @@ p, li { white-space: pre-wrap; } Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok|QDialogButtonBox::Open|QDialogButtonBox::Save + QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok - - - From a551e656004f9a0e1a06da8f5bc0bc3d920c5032 Mon Sep 17 00:00:00 2001 From: "Julien M." Date: Mon, 29 Apr 2024 15:53:55 +0200 Subject: [PATCH 3/5] quality(sonar): remove self assignment --- qtribu/gui/form_rdp_news.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qtribu/gui/form_rdp_news.py b/qtribu/gui/form_rdp_news.py index de339cdf..fdad5267 100644 --- a/qtribu/gui/form_rdp_news.py +++ b/qtribu/gui/form_rdp_news.py @@ -80,7 +80,6 @@ def __init__(self, parent=None): ) # connect standard buttons - self.btn_box: QDialogButtonBox = self.btn_box self.btn_box.helpRequested.connect( partial( open_url_in_browser, From e0352303b128104cfa540133573d1692774fc906 Mon Sep 17 00:00:00 2001 From: "Julien M." Date: Mon, 29 Apr 2024 16:57:49 +0200 Subject: [PATCH 4/5] =?UTF-8?q?review(gounux):=20fix=20largeur=20et=20URL?= =?UTF-8?q?=20non=20envoy=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qtribu/gui/form_rdp_news.py | 22 +++++++++++++++++----- qtribu/gui/form_rdp_news.ui | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/qtribu/gui/form_rdp_news.py b/qtribu/gui/form_rdp_news.py index fdad5267..6e1985cb 100644 --- a/qtribu/gui/form_rdp_news.py +++ b/qtribu/gui/form_rdp_news.py @@ -272,9 +272,21 @@ def on_btn_submit(self) -> Union[bool, str, None]: self.log(message=f"Opening issue form: {completed_url}", log_level=4) url_opened = open_url_in_browser(url=completed_url) if url_opened: - self.log(message="URL opened!", push=True, duration=2, log_level=0) + self.log( + message=self.tr("Issue form URL opened in default system web browser."), + log_level=4, + ) + super().accept() + return True else: - self.log(message="URL NOT OPENEDED :(", push=True, duration=4, log_level=2) - - super().accept() - return True + self.log( + parent_location=self, + message=self.tr( + "Opening issue form URL in default system web browser failed. " + "Check if there is any special characters in form fields and try again." + ), + push=True, + duration=10, + log_level=2, + ) + return False diff --git a/qtribu/gui/form_rdp_news.ui b/qtribu/gui/form_rdp_news.ui index 13ae573d..59eeb313 100644 --- a/qtribu/gui/form_rdp_news.ui +++ b/qtribu/gui/form_rdp_news.ui @@ -6,7 +6,7 @@ 0 0 - 891 + 800 1156 From af5072bfac952164c370322f15bba62a62796685 Mon Sep 17 00:00:00 2001 From: "Julien M." Date: Mon, 29 Apr 2024 17:04:50 +0200 Subject: [PATCH 5/5] quality(sonar): improve code readability --- qtribu/toolbelt/network_manager.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/qtribu/toolbelt/network_manager.py b/qtribu/toolbelt/network_manager.py index 49d99f42..239a5408 100644 --- a/qtribu/toolbelt/network_manager.py +++ b/qtribu/toolbelt/network_manager.py @@ -167,10 +167,7 @@ def get_from_source( ) req_reply = self.ntwk_requester.reply() - if ( - not req_reply.rawHeader(b"Content-Type") - == response_expected_content_type - ): + if req_reply.rawHeader(b"Content-Type") != response_expected_content_type: raise TypeError( f"Response mime-type is '{req_reply.rawHeader(b'Content-type')}' " f"not '{response_expected_content_type}' as required.".format()