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

HEPData / hepdata / 25533076011

07 May 2026 05:17PM UTC coverage: 86.047% (-0.02%) from 86.064%
25533076011

push

github

GraemeWatt
dependabot: pin invenio-db until Invenio upgrade

* See #848.

4952 of 5755 relevant lines covered (86.05%)

0.86 hits per line

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

86.59
hepdata/modules/theme/views.py
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of HEPData.
4
# Copyright (C) 2016 CERN.
5
#
6
# HEPData is free software; you can redistribute it
7
# and/or modify it under the terms of the GNU General Public License as
8
# published by the Free Software Foundation; either version 2 of the
9
# License, or (at your option) any later version.
10
#
11
# HEPData is distributed in the hope that it will be
12
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with HEPData; if not, write to the
18
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19
# MA 02111-1307, USA.
20
#
21
# In applying this license, CERN does not
22
# waive the privileges and immunities granted to it by virtue of its status
23
# as an Intergovernmental Organization or submit itself to any jurisdiction.
24

25
"""Theme blueprint in order for template and static files to be loaded."""
26

27
import re
1✔
28
import json
1✔
29

30
from flask import Blueprint, render_template, current_app, redirect, request, url_for, jsonify
1✔
31
from hepdata_validator import LATEST_SCHEMA_VERSION, RAW_SCHEMAS_URL
1✔
32

33
from hepdata.modules.email.utils import send_flask_message_email
1✔
34
from hepdata.modules.submission.api import get_latest_hepsubmission
1✔
35
from hepdata.utils.miscellaneous import sanitize_html
1✔
36
from hepdata.version import __version__
1✔
37

38
blueprint = Blueprint(
1✔
39
    'hepdata_theme',
40
    __name__,
41
    url_prefix='',
42
    template_folder='templates',
43
    static_folder='static',
44
)
45

46

47
@blueprint.record_once
1✔
48
def init(state):
1✔
49
    """Init app."""
50
    app = state.app
1✔
51
    # Customise flask-security emails
52
    security = app.extensions['security']
1✔
53

54
    @security.send_mail_task
1✔
55
    def send_hepdata_mail(msg):
1✔
56
        send_flask_message_email(msg)
1✔
57

58
    @security.mail_context_processor
1✔
59
    def security_mail_processor():
1✔
60
        site_url = app.config.get('SITE_URL', 'https://www.hepdata.net')
1✔
61
        return dict(site_url=site_url)
1✔
62

63
    @app.context_processor
1✔
64
    def set_banner_msg():
1✔
65
        banner_msg = app.config.get('BANNER_MSG', None)
1✔
66
        banner_msg = sanitize_html(banner_msg)
1✔
67
        return dict(banner_msg=banner_msg)
1✔
68

69

70
@blueprint.route('/')
1✔
71
def index():
1✔
72
    return render_template('hepdata_theme/home.html', ctx={"sw_version": __version__})
1✔
73

74

75
@blueprint.route('/submission')
1✔
76
def submission_help():
1✔
77
    return render_template('hepdata_theme/pages/help.html')
1✔
78

79

80
@blueprint.route('/submission/schemas/<path:jsonschema>')
1✔
81
def submission_schema(jsonschema):
1✔
82
    if not re.match(r"[\d+\.]+/.*", jsonschema):
1✔
83
        jsonschema = LATEST_SCHEMA_VERSION + '/' + jsonschema
1✔
84

85
    return redirect(RAW_SCHEMAS_URL + '/' + jsonschema)
1✔
86

87

88
@blueprint.route('/analyses/schemas/<path:jsonschema>')
1✔
89
def analyses_schema(jsonschema):
1✔
90
    with current_app.open_resource('templates/analyses_schema/' + jsonschema) as jsonfile:
1✔
91
        schema = json.load(jsonfile)
1✔
92
    return jsonify(schema)
1✔
93

94

95
@blueprint.route('/cookies')
1✔
96
def cookie_policy():
1✔
97
    return render_template('hepdata_theme/pages/cookies.html')
1✔
98

99

100
@blueprint.route('/about')
1✔
101
def about():
1✔
102
    return render_template('hepdata_theme/pages/about.html')
1✔
103

104

105
@blueprint.route('/terms')
1✔
106
def terms():
1✔
107
    return render_template('hepdata_theme/pages/terms.html')
1✔
108

109

110
@blueprint.route('/formats')
1✔
111
def formats():
1✔
112
    ctx = {}
1✔
113
    sample_resource = None
1✔
114
    hepsubmission = get_latest_hepsubmission(inspire_id='1748602')
1✔
115

116
    if hepsubmission:
1✔
117
        workspace_resources = [r for r in hepsubmission.resources if r.file_location.endswith('HEPData_workspaces.tar.gz')]
×
118
        if workspace_resources:
×
119
            sample_resource = workspace_resources[0]
×
120
            if sample_resource:
×
121
                sample_resource_url = url_for(
×
122
                    'hepdata_records.get_resource',
123
                    resource_id=sample_resource.id, landing_page=True,
124
                    _external=True)
125
                sample_resource_doi = sample_resource.doi or '10.17182/hepdata.89408.v1/r2'
×
126

127
    if not sample_resource:
1✔
128
        sample_resource_url = 'https://www.hepdata.net/record/resource/997020?landing_page=true'
1✔
129
        sample_resource_doi = '10.17182/hepdata.89408.v1/r2'
1✔
130

131
    ctx = {
1✔
132
        'sample_resource_url': sample_resource_url,
133
        'sample_resource_doi': sample_resource_doi
134
    }
135
    return render_template('hepdata_theme/pages/formats.html', ctx=ctx)
1✔
136

137

138
@blueprint.route('/record/invalid_doi')
1✔
139
def invalid_doi():
1✔
140
    return render_template(current_app.config['INVALID_DOI_TEMPLATE']), 410
×
141

142

143
def page_forbidden(e):
1✔
144
    """Error handler to show a 403.html page in case of a 403 error."""
145
    return render_template(current_app.config['THEME_403_TEMPLATE'],
×
146
                           ctx={"name": type(e).__name__, "error": str(e)}), 403
147

148

149
def page_not_found(e):
1✔
150
    """Error handler to show a 404.html page in case of a 404 error."""
151
    return render_template(current_app.config['THEME_404_TEMPLATE'],
1✔
152
                           ctx={"name": type(e).__name__, "error": str(e)}), 404
153

154

155
def internal_error(e):
1✔
156
    """Error handler to show a 500.html page in case of a 500 error."""
157
    return render_template(current_app.config['THEME_500_TEMPLATE'],
×
158
                           ctx={"name": type(e).__name__, "error": str(e)}), 500
159

160

161
def redirect_nonwww():
1✔
162
    if current_app.config.get('PRODUCTION_MODE', False) and 'www' not in request.url:
1✔
163
        return redirect(request.url.replace('://', '://www.'), code=301)
×
164

165

166
@blueprint.route('/ping')
1✔
167
def ping():
1✔
168
    return 'OK'
×
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

© 2026 Coveralls, Inc