Skip to content

Commit

Permalink
Merge pull request #497 from Xpirix/fix_xml_redirection
Browse files Browse the repository at this point in the history
Add latest, ltr and stable to cache
  • Loading branch information
Xpirix authored Jan 6, 2025
2 parents 7732230 + 88923ad commit 60cbe0e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
14 changes: 0 additions & 14 deletions dockerize/sites-enabled/prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,3 @@ server {
allow all;
}
}

# Redirect requests on analytics.qgis.org over to the feed
# This is just a conveneience in case we ever decide to host
# metabase on its own server.
# Note that we also have a cloudflare trasnform rule in place
# which will redirect users from analytics.qgis.org over to the public dashboard
# https://dash.cloudflare.com/a2cec2d89cc90579a20a30365bedcaf7/qgis.org/rules/transform-rules
server {
listen 80;
server_name plugins-analytics.qgis.org;
ssl_certificate /etc/letsencrypt/live/plugins-analytics.qgis.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/plugins-analytics.qgis.org/privkey.pem;
return 301 $scheme://plugins.qgis.org/metabase/public/dashboard/7ecd345f-7321-423d-9844-71e526a454a9;
}
17 changes: 12 additions & 5 deletions qgis-app/plugins/tasks/generate_plugins_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from preferences import preferences
from django.conf import settings
from preferences import preferences
from plugins.utils import get_version_from_label


logger = get_task_logger(__name__)
Expand All @@ -28,6 +29,7 @@ def generate_plugins_xml(site=""):
plugins_url = "{}/plugins/plugins_new.xml".format(site)

versions = preferences.SitePreference.qgis_versions
labels = ["latest", "stable", "ltr"]

if versions:
versions = versions.split(",")
Expand Down Expand Up @@ -80,12 +82,17 @@ def generate_plugins_xml(site=""):
if not os.path.exists(folder_path):
os.mkdir(folder_path)

for version in versions:
response = requests.get(
"{url}?qgis={version}".format(url=plugins_url, version=version)
)
def fetch_and_save_xml(version_or_label, is_label=False):
version = get_version_from_label(version_or_label) if is_label else version_or_label
response = requests.get(f"{plugins_url}?qgis={version}")

if response.status_code == 200:
file_name = "plugins_{}.xml".format(version)
file_name = f"plugins_{version_or_label}.xml"
with open(os.path.join(folder_path, file_name), "w+") as file:
file.write(response.text)

for version in versions:
fetch_and_save_xml(version)

for label in labels:
fetch_and_save_xml(label, is_label=True)
4 changes: 2 additions & 2 deletions qgis-app/plugins/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_generate_plugins_xml(self, mock_open, mock_mkdir, mock_exists, mock_get
# Given
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.text = '<some xml content>'
mock_response.text = '<some xml content> QGIS Version 34002|Visit https://download.qgis.org to get your copy of version 3.40.2'
mock_get.return_value = mock_response
preferences.SitePreference.qgis_versions = '3.24,3.25'

Expand Down Expand Up @@ -74,7 +74,7 @@ def test_generate_plugins_xml_with_custom_site(self, mock_open, mock_mkdir, mock
# Given
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.text = '<some xml content>'
mock_response.text = '<some xml content> QGIS Version 34002|Visit https://download.qgis.org to get your copy of version 3.40.2'
mock_get.return_value = mock_response
preferences.SitePreference.qgis_versions = '3.24,3.25'

Expand Down
5 changes: 0 additions & 5 deletions qgis-app/plugins/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1630,11 +1630,6 @@ def xml_plugins(request, qg_version=None, stable_only=None, package_name=None):
"""
request_version = request.GET.get("qgis", "1.8.0")
if request_version in ["latest", "ltr", "stable"]:
numbered_version = get_version_from_label(request_version)
# Redirect to this view using the numbered version because
# the xml file is cached with that.
return HttpResponseRedirect(reverse("xml_plugins") + f"?qgis={numbered_version}")
version_level = len(str(request_version).split('.')) - 1
qg_version = (
qg_version
Expand Down

0 comments on commit 60cbe0e

Please sign in to comment.