[973924]: / qiita_pet / portal.py

Download this file

87 lines (71 with data), 2.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -----------------------------------------------------------------------------
# Copyright (c) 2014--, The Qiita Development Team.
#
# Distributed under the terms of the BSD 3-clause License.
#
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
from os.path import join, dirname, abspath
from qiita_core.exceptions import MissingConfigSection
from qiita_core.qiita_settings import qiita_config
from configparser import ConfigParser
class PortalStyleManager(object):
"""Holds the portal style information
Parameters
----------
conf_fp: str, optional
Filepath to the configuration file. Default: portal.txt
Attributes
----------
logo : str
Path from base URL to the site logo
title : str
Site title
index header : str
Welcome text header for the website
index_text : str
Welcome text for the website
example_search : str
Example search to be shown on the study listing page
custom_css : str
custom CSS for the portal
conf_fp : str
The filepath to the portal styling config file
css_fp : str
The filepath to the portal styling custom CSS
"""
def __init__(self):
if qiita_config.portal_fp:
self.conf_fp = qiita_config.portal_fp
else:
self.conf_fp = join(dirname(abspath(__file__)),
'support_files/config_portal.cfg')
# Parse the configuration file
config = ConfigParser()
with open(self.conf_fp, newline=None) as conf_file:
config.read_file(conf_file)
_required_sections = {'sitebase', 'index', 'study_list'}
if not _required_sections.issubset(set(config.sections())):
missing = _required_sections - set(config.sections())
raise MissingConfigSection(', '.join(missing))
self.css_fp = config.get('sitebase', 'CSS_FP')
# Load the custom CSS if needed
self.custom_css = ''
if self.css_fp:
with open(self.css_fp, newline=None) as f:
self.custom_css = f.read()
self._get_sitebase(config)
self._get_index(config)
self._get_study_list(config)
def _get_sitebase(self, config):
"""Get the configuration of the sitebase section"""
self.logo = config.get('sitebase', 'LOGO')
self.title = config.get('sitebase', 'TITLE')
def _get_index(self, config):
"""Get the configuration of the index section"""
self.index_header = config.get('index', 'HEADER')
self.index_text = config.get('index', 'TEXT')
def _get_study_list(self, config):
"""Get the configuration of the study_list section"""
self.example_search = config.get('study_list', 'EXAMPLE_SEARCH')
portal_styling = PortalStyleManager()