Skip to content

Commit 1b504ad

Browse files
authored
Merge pull request #274 from geotribu/refactoring/modularize-compliance-and-license-widgets
Refactoring: modularize compliance and license widgets
2 parents 2bb5b3a + 1e35232 commit 1b504ad

File tree

14 files changed

+546
-244
lines changed

14 files changed

+546
-244
lines changed

docs/development/translation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ sudo apt install qttools5-dev-tools
1919
1. Update `.ts` files:
2020

2121
```bash
22-
pylupdate5 -noobsolete -verbose qtribu/resources/i18n/plugin_translation.pro
22+
pylupdate5 -verbose qtribu/resources/i18n/plugin_translation.pro
2323
```
2424

2525
1. Translate your text using QLinguist or directly into `.ts` files. Launching it through command-line is possible:

qtribu/constants.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#! python3 # noqa: E265
22

3-
"""
4-
Plugin constants.
5-
"""
3+
"""Plugin constants."""
64

75
# standard
86
from dataclasses import dataclass
@@ -23,6 +21,9 @@
2321

2422
# URLs
2523
contribution_guides_base_url: str = "https://contribuer.geotribu.fr/"
24+
SOURCE_REPOSITORY_URL: str = "https://github.com/geotribu/website/"
25+
ARTICLE_ISSUE_FORM_NAME: str = "ARTICLE.yml"
26+
RDP_ISSUE_FORM_NAME: str = "RDP_NEWS.yml"
2627

2728

2829
# Classes

qtribu/gui/dlg_settings.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
__uri_tracker__,
2424
__version__,
2525
)
26-
from qtribu.constants import contribution_guides_base_url
2726
from qtribu.toolbelt import PlgLogger, PlgOptionsManager
2827
from qtribu.toolbelt.commons import open_url_in_browser
2928
from qtribu.toolbelt.preferences import PlgSettingsStructure
@@ -79,20 +78,6 @@ def __init__(self, parent=None):
7978
self.btn_reset.setIcon(QIcon(QgsApplication.iconPath("mActionUndo.svg")))
8079
self.btn_reset.pressed.connect(self.reset_settings)
8180

82-
# contributing
83-
self.btn_license_open.pressed.connect(
84-
partial(
85-
open_url_in_browser,
86-
f"{contribution_guides_base_url}guides/licensing/#licence-par-defaut",
87-
)
88-
)
89-
self.btn_editorial_policy_open.pressed.connect(
90-
partial(
91-
open_url_in_browser,
92-
f"{contribution_guides_base_url}requirements/#ligne-editoriale",
93-
)
94-
)
95-
9681
# load previously saved settings
9782
self.load_settings()
9883

@@ -107,8 +92,6 @@ def apply(self):
10792
settings.notify_push_info = self.opt_notif_push_msg.isChecked()
10893
settings.notify_push_duration = self.sbx_notif_duration.value()
10994
settings.integration_qgis_news_feed = self.chb_integration_news_feed.isChecked()
110-
settings.license_global_accept = self.chb_license_global_accept.isChecked()
111-
settings.editorial_policy_accept = self.chb_editorial_policy_accept.isChecked()
11295

11396
# misc
11497
settings.debug_mode = self.opt_debug.isChecked()
@@ -119,6 +102,7 @@ def apply(self):
119102

120103
# sub widgets
121104
self.wdg_author.save_settings()
105+
self.wdg_editing_compliance.save_settings()
122106

123107
if __debug__:
124108
self.log(
@@ -135,8 +119,6 @@ def load_settings(self) -> None:
135119
self.opt_notif_push_msg.setChecked(settings.notify_push_info)
136120
self.sbx_notif_duration.setValue(settings.notify_push_duration)
137121
self.chb_integration_news_feed.setChecked(settings.integration_qgis_news_feed)
138-
self.chb_license_global_accept.setChecked(settings.license_global_accept)
139-
self.chb_editorial_policy_accept.setChecked(settings.editorial_policy_accept)
140122

141123
# misc
142124
self.opt_debug.setChecked(settings.debug_mode)

qtribu/gui/dlg_settings.ui

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -308,61 +308,12 @@
308308
<string>Contributing</string>
309309
</property>
310310
<layout class="QGridLayout" name="gridLayout_3">
311-
<item row="0" column="0" colspan="2">
312-
<widget class="QCheckBox" name="chb_license_global_accept">
313-
<property name="minimumSize">
314-
<size>
315-
<width>0</width>
316-
<height>25</height>
317-
</size>
318-
</property>
319-
<property name="text">
320-
<string>Accept publication license globally</string>
321-
</property>
322-
</widget>
323-
</item>
324-
<item row="0" column="2">
325-
<widget class="QPushButton" name="btn_license_open">
326-
<property name="autoFillBackground">
327-
<bool>true</bool>
328-
</property>
329-
<property name="text">
330-
<string>Open GeoRDP publication license</string>
331-
</property>
332-
<property name="autoDefault">
333-
<bool>false</bool>
334-
</property>
335-
<property name="flat">
336-
<bool>false</bool>
337-
</property>
338-
</widget>
339-
</item>
340-
<item row="2" column="2">
341-
<widget class="QPushButton" name="btn_editorial_policy_open">
342-
<property name="autoFillBackground">
343-
<bool>true</bool>
344-
</property>
345-
<property name="text">
346-
<string>Open editorial policy</string>
347-
</property>
348-
<property name="autoDefault">
349-
<bool>false</bool>
350-
</property>
351-
<property name="flat">
352-
<bool>false</bool>
353-
</property>
354-
</widget>
355-
</item>
356-
<item row="2" column="0" colspan="2">
357-
<widget class="QCheckBox" name="chb_editorial_policy_accept">
358-
<property name="text">
359-
<string>I have read and understood the editorial policy</string>
360-
</property>
361-
</widget>
362-
</item>
363-
<item row="3" column="0" colspan="3">
311+
<item row="2" column="0" colspan="3">
364312
<widget class="AuthoringWidget" name="wdg_author" native="true"/>
365313
</item>
314+
<item row="0" column="0" colspan="3">
315+
<widget class="EditingPolicyWidget" name="wdg_editing_compliance" native="true"/>
316+
</item>
366317
</layout>
367318
</widget>
368319
</item>
@@ -534,6 +485,12 @@
534485
<header>qtribu.gui.wdg_authoring</header>
535486
<container>1</container>
536487
</customwidget>
488+
<customwidget>
489+
<class>EditingPolicyWidget</class>
490+
<extends>QWidget</extends>
491+
<header>qtribu.gui.wdg_editing_compliance</header>
492+
<container>1</container>
493+
</customwidget>
537494
</customwidgets>
538495
<tabstops>
539496
<tabstop>opt_browser_qt</tabstop>

qtribu/gui/form_article.py

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,29 @@
1414
# PyQGIS
1515
from qgis.core import Qgis
1616
from qgis.PyQt import uic
17+
from qgis.PyQt.QtCore import QDate
1718
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QWidget
1819

1920
# plugin
2021
from qtribu.__about__ import __title__, __version__
21-
from qtribu.constants import ICON_ARTICLE, contribution_guides_base_url
22+
from qtribu.constants import (
23+
ARTICLE_ISSUE_FORM_NAME,
24+
ICON_ARTICLE,
25+
SOURCE_REPOSITORY_URL,
26+
contribution_guides_base_url,
27+
)
28+
from qtribu.gui.wdg_authoring import AuthoringWidget
29+
from qtribu.gui.wdg_editing_compliance import EditingPolicyWidget
2230
from qtribu.toolbelt import NetworkRequestsManager, PlgLogger, PlgOptionsManager
2331
from qtribu.toolbelt.commons import open_url_in_browser
2432

2533

2634
class ArticleForm(QDialog):
2735
"""QDialog form to submit an article."""
2836

29-
ISSUE_FORM_BASE_URL: str = (
30-
"https://github.com/geotribu/website/issues/new?template=ARTICLE.yml"
31-
)
37+
# type hints for sub-widgets
38+
wdg_author: AuthoringWidget
39+
wdg_editing_compliance: EditingPolicyWidget
3240

3341
def __init__(self, parent: Optional[QWidget] = None):
3442
"""Constructor.
@@ -43,20 +51,14 @@ def __init__(self, parent: Optional[QWidget] = None):
4351
self.plg_settings = PlgOptionsManager()
4452
self.qntwk = NetworkRequestsManager()
4553

54+
# initialize GUI
55+
self.initGui()
56+
57+
def initGui(self) -> None:
58+
"""Initialize GUI elements."""
4659
# custom icon
4760
self.setWindowIcon(ICON_ARTICLE)
4861

49-
# publication
50-
self.cbb_license.addItems(
51-
[
52-
"Creative Commons International BY-NC-SA 4.0",
53-
"Creative Commons International BY-SA 4.0",
54-
"Creative Commons International BY 4.0",
55-
"Beerware (Révision 42)",
56-
"autre - merci de préciser dans le champ libre en fin de formulaire",
57-
]
58-
)
59-
6062
# connect help button
6163
self.btn_box.helpRequested.connect(
6264
partial(
@@ -72,6 +74,27 @@ def __init__(self, parent: Optional[QWidget] = None):
7274
self.tr("Submit")
7375
)
7476

77+
# custom sub-widget
78+
self.wdg_editing_compliance.chb_license_rdp.setEnabled(False)
79+
self.wdg_editing_compliance.chb_transparency.setText(
80+
self.wdg_editing_compliance.chb_transparency.text()
81+
+ self.tr("\n If not, I give some details in the comment area.")
82+
)
83+
84+
# set the minimum proposed date to 2 weeks from
85+
today: QDate = QDate.currentDate()
86+
min_date: QDate = today.addDays(14)
87+
self.dte_proposed_date.setMinimumDate(min_date)
88+
89+
@property
90+
def issue_form_url(self) -> str:
91+
"""Get Github issue form base URL.
92+
93+
:return: issue form base URL
94+
:rtype: str
95+
"""
96+
return f"{SOURCE_REPOSITORY_URL}issues/new?&template={ARTICLE_ISSUE_FORM_NAME}"
97+
7598
def check_required_fields(self) -> bool:
7699
invalid_fields = []
77100
error_message = ""
@@ -153,16 +176,17 @@ def on_btn_submit(self) -> Union[bool, str, None]:
153176
if not self.check_required_fields():
154177
return False
155178

156-
completed_url = (
157-
f"{self.ISSUE_FORM_BASE_URL}"
179+
completed_url: str = (
180+
f"{self.issue_form_url}"
158181
f"&in_author_name={self.wdg_author.lne_firstname.text()} "
159182
f"{self.wdg_author.lne_lastname.text()}"
160183
f"&in_author_mail={self.wdg_author.lne_email.text()}"
161184
f"&in_author_linkedin={self.wdg_author.lne_linkedin_account.text()}"
162185
f"&in_author_mastodon={self.wdg_author.lne_mastodon_account.text()}"
163186
f"&in_author_twitter={self.wdg_author.lne_twitter_account.text()}"
164187
f"&in_author_license=true"
165-
f"&cb_author_content_relationship={self.chb_transparency.isChecked()}"
188+
f"&cb_author_content_relationship={self.wdg_editing_compliance.chb_transparency.isChecked()}"
189+
f"&cb_author_aware_ai_guidelines={self.wdg_editing_compliance.chb_genai_editing_policy.isChecked()}"
166190
f"&in_art_title={self.lne_title.text()}"
167191
f"&in_art_date={self.dte_proposed_date.date().toString('dd/MM/yyyy')}"
168192
f"&tx_art_content={self.txt_description.toPlainText()}"
@@ -171,7 +195,7 @@ def on_btn_submit(self) -> Union[bool, str, None]:
171195
f"&title=[Proposition] {self.lne_title.text()} - {__title__} {__version__}"
172196
)
173197
self.log(message=f"Opening issue form: {completed_url}", log_level=4)
174-
url_opened = open_url_in_browser(url=completed_url)
198+
url_opened: bool = open_url_in_browser(url=completed_url)
175199
if url_opened:
176200
self.log(
177201
message=self.tr("Issue form URL opened in default system web browser."),

qtribu/gui/form_article.ui

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>705</width>
10-
<height>739</height>
9+
<width>968</width>
10+
<height>823</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -45,8 +45,8 @@
4545
<rect>
4646
<x>0</x>
4747
<y>0</y>
48-
<width>687</width>
49-
<height>658</height>
48+
<width>950</width>
49+
<height>738</height>
5050
</rect>
5151
</property>
5252
<layout class="QVBoxLayout" name="verticalLayout">
@@ -190,51 +190,23 @@
190190
<string>Publication</string>
191191
</property>
192192
<layout class="QFormLayout" name="formLayout_4">
193-
<item row="0" column="0">
194-
<widget class="QLabel" name="lbl_license">
195-
<property name="font">
196-
<font>
197-
<pointsize>11</pointsize>
198-
<weight>75</weight>
199-
<bold>true</bold>
200-
</font>
201-
</property>
202-
<property name="text">
203-
<string>License:</string>
204-
</property>
205-
</widget>
206-
</item>
207-
<item row="2" column="1">
208-
<widget class="QPlainTextEdit" name="txt_comment">
209-
<property name="maximumBlockCount">
210-
<number>300</number>
211-
</property>
212-
</widget>
193+
<item row="0" column="0" colspan="2">
194+
<widget class="EditingPolicyWidget" name="wdg_editing_compliance" native="true"/>
213195
</item>
214-
<item row="2" column="0">
196+
<item row="1" column="0">
215197
<widget class="QLabel" name="lbl_comment">
216198
<property name="text">
217199
<string>Comment:</string>
218200
</property>
219201
</widget>
220202
</item>
221-
<item row="1" column="0">
222-
<widget class="QLabel" name="lbl_transparency">
223-
<property name="text">
224-
<string>Transparency:</string>
225-
</property>
226-
</widget>
227-
</item>
228203
<item row="1" column="1">
229-
<widget class="QCheckBox" name="chb_transparency">
230-
<property name="text">
231-
<string>I'm sure that the content fit with editing rules. If not, I give some details in the comment area.</string>
204+
<widget class="QPlainTextEdit" name="txt_comment">
205+
<property name="maximumBlockCount">
206+
<number>300</number>
232207
</property>
233208
</widget>
234209
</item>
235-
<item row="0" column="1">
236-
<widget class="QComboBox" name="cbb_license"/>
237-
</item>
238210
</layout>
239211
</widget>
240212
</item>
@@ -299,6 +271,12 @@
299271
<header>qgsmessagebar.h</header>
300272
<container>1</container>
301273
</customwidget>
274+
<customwidget>
275+
<class>EditingPolicyWidget</class>
276+
<extends>QWidget</extends>
277+
<header>qtribu.gui.wdg_editing_compliance</header>
278+
<container>1</container>
279+
</customwidget>
302280
</customwidgets>
303281
<resources/>
304282
<connections>

0 commit comments

Comments
 (0)