• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rero / sonar / 17425918180

03 Sep 2025 07:11AM UTC coverage: 95.796% (-0.6%) from 96.378%
17425918180

push

github

PascalRepond
translations: extract messages

Co-Authored-by: Pascal Repond <pascal.repond@rero.ch>

7816 of 8159 relevant lines covered (95.8%)

0.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.17
/sonar/modules/sitemap/views.py
1
# Swiss Open Access Repository
2
# Copyright (C) 2022 RERO
3
#
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU Affero General Public License as published by
6
# the Free Software Foundation, version 3 of the License.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Affero General Public License for more details.
12
#
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

16
"""Sitemap views."""
17

18
import os
1✔
19

20
from flask import Blueprint, Response, abort, current_app
1✔
21

22
blueprint = Blueprint("sitemap", __name__, template_folder="templates", url_prefix="/")
1✔
23

24

25
@blueprint.route("/<org_code:view>/sitemap.xml")
1✔
26
def sitemap(view):
1✔
27
    """Get the sitemap file."""
28
    file_path = ["sitemap.xml"]
1✔
29
    if view != current_app.config.get("SONAR_APP_DEFAULT_ORGANISATION"):
1✔
30
        file_path.insert(0, view)
×
31
    return response_file(file_path)
1✔
32

33

34
@blueprint.route("/<org_code:view>/sitemap_<int:index>.xml")
1✔
35
def sitemap_index(view, index):
1✔
36
    """Get the sitemap index file."""
37
    file_path = [f"sitemap_{index}.xml"]
1✔
38
    if view != current_app.config.get("SONAR_APP_DEFAULT_ORGANISATION"):
1✔
39
        file_path.insert(0, view)
×
40
    return response_file(file_path)
1✔
41

42

43
def response_file(file_path):
1✔
44
    """Generate the file path and load file."""
45

46
    def stream_file(sitemap_file):
1✔
47
        """Stream file."""
48
        with open(sitemap_file, encoding="utf-8", buffering=100000) as f:
×
49
            yield from f
×
50

51
    sitemap_folder = current_app.config.get("SONAR_APP_SITEMAP_FOLDER_PATH")
1✔
52
    sitemap_file = os.path.join(sitemap_folder, *file_path)
1✔
53
    if not os.path.exists(sitemap_file):
1✔
54
        abort(404)
1✔
55
    return Response(stream_file(sitemap_file), mimetype="application/xml")
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc