Skip to content

Commit e949d71

Browse files
committed
Generate contextual About content using Jinja2
1 parent a551102 commit e949d71

File tree

6 files changed

+87
-17
lines changed

6 files changed

+87
-17
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,6 @@ venv.bak/
112112

113113
# Custom folders
114114
_debug/
115+
116+
# Do not check in rendered HTML
117+
/geocatbridge/resources/geocat/index.html

geocatbridge/resources/geocat/index.html renamed to geocatbridge/resources/geocat/template.html

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,26 @@
8686
margin-left: 0.5em;
8787
}
8888
</style>
89-
<title>About GeoCat</title>
89+
<title>About {{ app_name }}</title>
9090
</head>
9191
<body>
9292
<table class="gc-columns">
9393
<tr>
9494
<td class="gc-left-column">
95-
<h1>Bridge <span>for QGIS</span></h1>
95+
<h1>{{ short_name }} <span>for QGIS</span></h1>
9696
<p>
97-
GeoCat Bridge is a Python plugin for QGIS, that has been designed
97+
{{ app_name }} is a Python plugin for QGIS, that has been designed
9898
to simplify the publishing process of your geographic data and metadata to
9999
open source web services like GeoServer, GeoNetwork, and MapServer.
100100
</p>
101101
<p>
102-
Please read our <a href="https://geocat.github.io/qgis-bridge-plugin/">online documentation</a>
102+
Please read our <a href="{{ doc_url }}">online documentation</a>
103103
for more information.
104104
</p>
105+
{% if not is_enterprise %}
105106
<div class="gc-top-space">
106107
<div class="gc-logo-ext-container">
107-
<a href="https://github.com/GeoCat/qgis-bridge-plugin" title="Source code on GitHub">
108+
<a href="{{ repo_url }}" title="Source code on GitHub">
108109
<div class="gc-logo-ext-wrapper">
109110
<img class="gc-logo-ext" src="img/github_logo.svg" alt="GitHub">
110111
</div>
@@ -120,23 +121,33 @@ <h1>Bridge <span>for QGIS</span></h1>
120121
</a>
121122
</div>
122123
</div>
124+
{% endif %}
123125
</td>
124126
<td class="gc-right-column">
125127
<div class="gc-logo-wrapper">
126128
<a href="https://www.geocat.net">
127129
<img class="gc-logo" src="img/geocat_logo.svg" alt="GeoCat">
128130
</a>
129131
</div>
130-
<h2>Bridge <span>Enterprise</span></h2>
132+
{% if is_enterprise %}
133+
<h2>{{ short_name }} <span>Support</span></h2>
131134
<p>
132-
Consider <a href="https://www.geocat.net/bridge/">upgrading</a> to
133-
GeoCat Bridge Enterprise. Get unlimited support and contribute to future developments.
135+
GeoCat customers can <a href="{{ support_url }}">submit a support ticket</a> if they have
136+
any questions or issues related to {{ app_name }} (login required). Our support team will
137+
contact you as soon as possible.
138+
</p>
139+
{% else %}
140+
<h2>{{ short_name }} <span>Enterprise</span></h2>
141+
<p>
142+
Consider <a href="{{ homepage }}">upgrading</a> to
143+
{{ app_name }} Enterprise. Get unlimited support and contribute to future developments.
134144
</p>
135145
<h2>GeoCat <span>Live</span></h2>
136146
<p>
137147
Try <a href="https://www.geocat.net/live/">all-in-one hosting</a> of GeoNetwork,
138-
GeoServer and PostGIS today and get Bridge Enterprise for free.
148+
GeoServer and PostGIS today and get {{ app_name }} Enterprise for free.
139149
</p>
150+
{% endif %}
140151
</td>
141152
</tr>
142153
</table>

geocatbridge/ui/bridgedialog.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def showAbout() -> bool:
6868
cur_version = meta.getVersion()
6969
old_version = meta.SemanticVersion(QSettings().value(VERSION_SETTING) or '')
7070
if old_version != cur_version:
71+
# Force-refresh the About HTML page
72+
files.getAboutUrl(True)
7173
QSettings().setValue(VERSION_SETTING, str(cur_version))
7274
return True
7375
return False

geocatbridge/ui/geocatwidget.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from qgis.PyQt.QtCore import QUrl
55
from qgis.PyQt.QtWebKitWidgets import QWebPage
66

7-
from geocatbridge.utils import files, gui, meta
7+
from geocatbridge.utils import gui, meta
8+
from geocatbridge.utils.files import getAboutUrl
89

910
WIDGET, BASE = gui.loadUiType(__file__)
1011

@@ -16,9 +17,7 @@ def __init__(self, parent=None):
1617
self.parent = parent
1718
self.setupUi(self)
1819

19-
path = files.getResourcePath(files.Path("geocat") / "index.html")
20-
url = QUrl.fromLocalFile(path)
21-
self.txtAbout.load(url)
20+
self.txtAbout.load(getAboutUrl())
2221
self.txtAbout.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
2322
self.txtAbout.linkClicked.connect(partial(self.open_link))
2423

geocatbridge/utils/files.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@
33
import uuid
44
from pathlib import Path
55

6-
from qgis.PyQt.QtCore import QDir
6+
from qgis.PyQt.QtCore import QDir, QUrl
7+
from jinja2 import Environment, FileSystemLoader
78

89
from geocatbridge.utils import meta
910

10-
#: GeoCat Bridge Python root directory
11-
BRIDGE_ROOT_DIR = Path(__file__).parent.parent
12-
1311
_DIR_NAME_WIDGETS = "ui"
1412
_DIR_NAME_TRANSLATIONS = "i18n"
1513
_DIR_NAME_ICONS = "icons"
1614
_DIR_NAME_RESOURCES = "resources"
1715
_DIR_NAME_DOCS = "docs"
1816

17+
_ABOUT_SRCDIR = "geocat"
18+
_ABOUT_TEMPLATE = "template.html"
19+
_ABOUT_HTMLPAGE = "index.html"
20+
21+
#: GeoCat Bridge Python root directory
22+
BRIDGE_ROOT_DIR = Path(__file__).parent.parent
23+
BRIDGE_ABOUT_DIR = BRIDGE_ROOT_DIR / _DIR_NAME_RESOURCES / _ABOUT_SRCDIR
24+
1925

2026
def _fix_ext(name, ext):
2127
""" Appends a given extension to a file name if it doesn't have one. """
@@ -104,3 +110,33 @@ def getDirectory(path) -> str:
104110
""" Returns the parent directory path to the given file or directory path. """
105111
fix_path = Path(str(path).split('|')[0]) # Fix for GeoPackage layer paths
106112
return str(fix_path.resolve().parent)
113+
114+
115+
def getAboutUrl(refresh: bool = False) -> QUrl:
116+
"""
117+
Returns the QUrl for the Bridge About page (HTML).
118+
If 'refresh' is True or the HTML page does not exist, it is rendered from the template in the same folder.
119+
If the template does not exist,
120+
"""
121+
target_path = (BRIDGE_ABOUT_DIR / _ABOUT_HTMLPAGE).resolve()
122+
123+
# Render the index.html if it does not exist yet or if it should be updated (i.e. when version changed)
124+
if refresh or not target_path.is_file():
125+
template_path = target_path.with_name(_ABOUT_TEMPLATE)
126+
if not template_path.is_file():
127+
raise FileNotFoundError(f"HTML template at {template_path} does not exist")
128+
env = Environment(loader=FileSystemLoader(template_path.parent))
129+
template = env.get_template(_ABOUT_TEMPLATE)
130+
html = template.render(
131+
app_name=meta.getAppName(),
132+
short_name=meta.getShortAppName(),
133+
doc_url=meta.getDocsUrl(),
134+
repo_url=meta.getRepoUrl(),
135+
support_url=meta.getSupportUrl(),
136+
homepage=meta.getHomeUrl(),
137+
is_enterprise=meta.isEnterprise()
138+
)
139+
with open(target_path, mode="w+", encoding="utf-8") as fp:
140+
fp.write(html)
141+
142+
return QUrl.fromLocalFile(str(target_path))

geocatbridge/utils/meta.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ def getTrackerUrl() -> str:
125125
return getProperty("tracker")
126126

127127

128+
def getRepoUrl() -> str:
129+
""" Returns the Git repository URL for GeoCat Bridge (i.e. GitHub). """
130+
return getProperty("repository")
131+
132+
133+
def getHomeUrl() -> str:
134+
""" Returns the homepage URL for GeoCat Bridge. """
135+
return getProperty("homepage")
136+
137+
128138
def getVersion() -> SemanticVersion:
129139
""" Returns the GeoCat Bridge version string. """
130140
return SemanticVersion(getProperty("version"))
@@ -143,4 +153,13 @@ def getDocsUrl() -> str:
143153
return f"{doc_url.rstrip('/')}/v{getVersion()}/"
144154

145155

156+
def isEnterprise() -> bool:
157+
""" Returns True if this is the GeoCat Bridge Enterprise edition. """
158+
try:
159+
from geocatbridge.utils import license # noqa
160+
except ImportError:
161+
return False
162+
return True
163+
164+
146165
_load()

0 commit comments

Comments
 (0)