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

HEPData / hepdata / 7019203348

28 Nov 2023 12:57PM UTC coverage: 83.15% (+0.1%) from 83.039%
7019203348

Pull #732

github

ItIsJordan
Fix e2e related record test

Fixes the e2e related record test to dynamically generate the ids to ensure functionality when ran standalone and alongside the test suite
Pull Request #732: Related data mouseover

56 of 58 new or added lines in 4 files covered. (96.55%)

1 existing line in 1 file now uncovered.

4451 of 5353 relevant lines covered (83.15%)

0.83 hits per line

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

68.83
/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."""
1✔
26

27
import re
1✔
28

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

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

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

45

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

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

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

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

68

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

73

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

78

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

84
    return redirect(RAW_SCHEMAS_URL + '/' + jsonschema)
×
85

86

87
@blueprint.route('/cookies')
1✔
88
def cookie_policy():
1✔
89
    return render_template('hepdata_theme/pages/cookies.html')
1✔
90

91

92
@blueprint.route('/about')
1✔
93
def about():
1✔
94
    return render_template('hepdata_theme/pages/about.html')
1✔
95

96

97
@blueprint.route('/terms')
1✔
98
def terms():
1✔
99
    return render_template('hepdata_theme/pages/terms.html')
1✔
100

101

102
@blueprint.route('/formats')
1✔
103
def formats():
1✔
104
    ctx = {}
×
105
    sample_resource = None
×
106
    hepsubmission = get_latest_hepsubmission(inspire_id='1748602')
×
107

108
    if hepsubmission:
×
109
        workspace_resources = [r for r in hepsubmission.resources if r.file_location.endswith('HEPData_workspaces.tar.gz')]
×
110
        if workspace_resources:
×
111
            sample_resource = workspace_resources[0]
×
112
            if sample_resource:
×
113
                sample_resource_url = url_for(
×
114
                    'hepdata_records.get_resource',
115
                    resource_id=sample_resource.id, landing_page=True,
116
                    _external=True)
117
                sample_resource_doi = sample_resource.doi or '10.17182/hepdata.89408.v1/r2'
×
118

119
    if not sample_resource:
×
120
        sample_resource_url = 'https://www.hepdata.net/record/resource/997020?landing_page=true'
×
121
        sample_resource_doi = '10.17182/hepdata.89408.v1/r2'
×
122

123
    ctx = {
×
124
        'sample_resource_url': sample_resource_url,
125
        'sample_resource_doi': sample_resource_doi
126
    }
127
    return render_template('hepdata_theme/pages/formats.html', ctx=ctx)
×
128

129

130
@blueprint.route('/record/invalid_doi')
1✔
131
def invalid_doi():
1✔
132
    return render_template(current_app.config['INVALID_DOI_TEMPLATE']), 410
×
133

134

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

140

141
def page_not_found(e):
1✔
142
    """Error handler to show a 404.html page in case of a 404 error."""
UNCOV
143
    return render_template(current_app.config['THEME_404_TEMPLATE'],
×
144
                           ctx={"name": type(e).__name__, "error": str(e)}), 404
145

146

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

152

153
def redirect_nonwww():
1✔
154
    if current_app.config.get('PRODUCTION_MODE', False) and 'www' not in request.url:
1✔
155
        return redirect(request.url.replace('://', '://www.'), code=301)
×
156

157

158
@blueprint.route('/ping')
1✔
159
def ping():
1✔
160
    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