Skip to content

Commit 047e683

Browse files
committed
more code review and feature annotation
1 parent 0b69b02 commit 047e683

File tree

14 files changed

+437
-195
lines changed

14 files changed

+437
-195
lines changed

docs/featuremap/types.csv

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Asset
22
BackgroundTask
33
Blueprint
4+
Build
45
Config
56
Crosswalk
67
Data
@@ -11,13 +12,14 @@ Environment
1112
ExternalService
1213
Feature
1314
Fragment
15+
Framework
1416
Library
1517
Model
1618
Process
1719
Query
20+
Regex
1821
Schema
1922
Script
20-
SourceData
2123
Technology
2224
Template
2325
Test

docs/generated

Submodule generated updated 182 files

lccSubjects.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- ~~LCC:SourceData~~ -->
1+
<!-- ~~LCCXML:Data~~ -->
22
<subjects>
33
<subject>
44
<name>Agriculture</name>

portality/authorise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class Authorise(object):
44
"""
5-
~~Authorise:Feature->AuthNZ:Feature~~
5+
~~AuthNZ:Feature~~
66
"""
77
@classmethod
88
def has_role(cls, role, reference):

portality/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ~~Constants:Config~~
12
APPLICATION_STATUS_ACCEPTED = "accepted"
23
APPLICATION_STATUS_REJECTED = "rejected"
34
APPLICATION_STATUS_UPDATE_REQUEST = "update_request"

portality/core.py

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,49 @@
2121

2222
@login_manager.user_loader
2323
def load_account_for_login_manager(userid):
24+
"""
25+
~~LoginManager:Feature->Account:Model~~
26+
:param userid:
27+
:return:
28+
"""
2429
from portality import models
2530
out = models.Account.pull(userid)
2631
return out
2732

2833

2934
def create_app():
35+
"""
36+
~~CreateApp:Framework->Flask:Technology~~
37+
:return:
38+
"""
3039
app = Flask(__name__)
40+
# ~~->AppSettings:Config~~
3141
configure_app(app)
42+
#~~->ErrorHandler:Feature~~
3243
setup_error_logging(app)
44+
#~~->Jinja2:Environment~~
3345
setup_jinja(app)
46+
#~~->CrossrefXML:Feature~~
3447
app.config["LOAD_CROSSREF_THREAD"] = threading.Thread(target=load_crossref_schema, args=(app, ), daemon=True)
3548
app.config["LOAD_CROSSREF_THREAD"].start()
49+
#~~->LoginManager:Feature~~
3650
login_manager.init_app(app)
51+
#~~->CORS:Framework~~
3752
CORS(app)
53+
#~~->APM:Feature~~
3854
initialise_apm(app)
55+
#~~->DebugToolbar:Framework~~
3956
DebugToolbarExtension(app)
57+
#~~->ProxyFix:Framework~~
4058
proxyfix(app)
59+
#~~->CMS:Build~~
4160
build_statics(app)
4261
return app
4362

4463

64+
##################################################
65+
# Configure the App
66+
4567
def configure_app(app):
4668
"""
4769
Configure the DOAJ from:
@@ -104,7 +126,15 @@ def get_app_env(app):
104126
return env
105127

106128

129+
################################################
130+
# Crossref setup
131+
107132
def load_crossref_schema(app):
133+
"""
134+
~~CrossrefXML:Feature->CrossrefXML:Schema~~
135+
:param app:
136+
:return:
137+
"""
108138
schema_path = app.config["SCHEMAS"].get("crossref")
109139

110140
if not app.config.get("CROSSREF_SCHEMA"):
@@ -117,17 +147,17 @@ def load_crossref_schema(app):
117147
message="There was an error attempting to load schema from " + schema_path, inner=e)
118148

119149

120-
def create_es_connection(app):
121-
# temporary logging config for debugging index-per-type
122-
#import logging
123-
#esprit.raw.configure_logging(logging.DEBUG)
124150

151+
############################################
152+
# Elasticsearch initialisation
153+
154+
def create_es_connection(app):
155+
# ~~ElasticConnection:Framework->Elasticsearch:Technology~~
125156
# make a connection to the index
126157
if app.config['ELASTIC_SEARCH_INDEX_PER_TYPE']:
127158
conn = esprit.raw.Connection(host=app.config['ELASTIC_SEARCH_HOST'], index='')
128159
else:
129160
conn = esprit.raw.Connection(app.config['ELASTIC_SEARCH_HOST'], app.config['ELASTIC_SEARCH_DB'])
130-
131161
return conn
132162

133163

@@ -161,6 +191,12 @@ def put_mappings(conn, mappings):
161191

162192

163193
def initialise_index(app, conn):
194+
"""
195+
~~InitialiseIndex:Framework->Elasticsearch:Technology~~
196+
:param app:
197+
:param conn:
198+
:return:
199+
"""
164200
if not app.config['INITIALISE_INDEX']:
165201
app.logger.warn('INITIALISE_INDEX config var is not True, initialise_index command cannot run')
166202
return
@@ -176,29 +212,56 @@ def initialise_index(app, conn):
176212
put_mappings(conn, mappings)
177213

178214

215+
##################################################
216+
# APM
217+
179218
def initialise_apm(app):
219+
"""
220+
~~APM:Feature->ElasticAPM:Technology~~
221+
:param app:
222+
:return:
223+
"""
180224
if app.config.get('ENABLE_APM', False):
181225
from elasticapm.contrib.flask import ElasticAPM
182226
app.logger.info("Configuring Elastic APM")
183227
apm = ElasticAPM(app, logging=True)
184228

185229

230+
##################################################
231+
# proxyfix
232+
186233
def proxyfix(app):
234+
"""
235+
~~ProxyFix:Framework~~
236+
:param app:
237+
:return:
238+
"""
187239
if app.config.get('PROXIED', False):
188240
from werkzeug.middleware.proxy_fix import ProxyFix
189241
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
190242

191243

244+
##################################################
245+
# Jinja2
246+
192247
def setup_jinja(app):
248+
"""
249+
Jinja2:Environment->Jinja2:Technology
250+
:param app:
251+
:return:
252+
"""
193253
'''Add jinja extensions and other init-time config as needed.'''
194254

195255
app.jinja_env.add_extension('jinja2.ext.do')
196256
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
197257
app.jinja_env.globals['getattr'] = getattr
198258
app.jinja_env.globals['type'] = type
259+
#~~->Constants:Config~~
199260
app.jinja_env.globals['constants'] = constants
261+
#~~->Datasets:Data~~
200262
app.jinja_env.globals['datasets'] = datasets
201263
_load_data(app)
264+
#~~->CMS:DataStore~~
202265
app.jinja_env.loader = FileSystemLoader([app.config['BASE_FILE_PATH'] + '/templates',
203266
os.path.dirname(app.config['BASE_FILE_PATH']) + '/cms/fragments'])
204267

@@ -221,7 +284,16 @@ def _load_data(app):
221284
app.jinja_env.globals["data"][dataname] = data
222285

223286

287+
##################################################
288+
# Static Content
289+
224290
def build_statics(app):
291+
"""
292+
~~CMS:Build->Fragments:Build~~
293+
~~->SASS:Build~~
294+
:param app:
295+
:return:
296+
"""
225297
if not app.config.get("DEBUG", False):
226298
return
227299
from portality.cms import build_fragments, build_sass

portality/dao.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class ElasticSearchWriteException(Exception):
2424

2525

2626
class DomainObject(UserDict, object):
27+
"""
28+
~~DomainObject:Model->Elasticsearch:Technology~~
29+
"""
2730
__type__ = None # set the type on the model that inherits this
2831

2932
def __init__(self, **kwargs):
@@ -107,7 +110,14 @@ def last_updated_timestamp(self):
107110
return datetime.strptime(self.last_updated, "%Y-%m-%dT%H:%M:%SZ")
108111

109112
def save(self, retries=0, back_off_factor=1, differentiate=False, blocking=False):
110-
113+
"""
114+
~~->ReadOnlyMode:Feature~~
115+
:param retries:
116+
:param back_off_factor:
117+
:param differentiate:
118+
:param blocking:
119+
:return:
120+
"""
111121
if app.config.get("READ_ONLY_MODE", False) and app.config.get("SCRIPTS_READ_ONLY_MODE", False):
112122
app.logger.warn("System is in READ-ONLY mode, save command cannot run")
113123
return
@@ -201,6 +211,13 @@ def save(self, retries=0, back_off_factor=1, differentiate=False, blocking=False
201211

202212
@classmethod
203213
def bulk(cls, bibjson_list, idkey='id', refresh=False):
214+
"""
215+
~~->ReadOnlyMode:Feature~~
216+
:param bibjson_list:
217+
:param idkey:
218+
:param refresh:
219+
:return:
220+
"""
204221
if app.config.get("READ_ONLY_MODE", False) and app.config.get("SCRIPTS_READ_ONLY_MODE", False):
205222
app.logger.warn("System is in READ-ONLY mode, bulk command cannot run")
206223
return
@@ -216,6 +233,10 @@ def bulk(cls, bibjson_list, idkey='id', refresh=False):
216233

217234
@classmethod
218235
def refresh(cls):
236+
"""
237+
~~->ReadOnlyMode:Feature~~
238+
:return:
239+
"""
219240
if app.config.get("READ_ONLY_MODE", False) and app.config.get("SCRIPTS_READ_ONLY_MODE", False):
220241
app.logger.warn("System is in READ-ONLY mode, refresh command cannot run")
221242
return
@@ -826,12 +847,14 @@ class ESError(Exception):
826847

827848

828849
class Facetview2(object):
829-
830850
"""
831-
{"query":{"filtered":{"filter":{"bool":{"must":[{"term":{"_type":"article"}}]}},"query":{"query_string":{"query":"richard","default_operator":"OR"}}}},"from":0,"size":10}
832-
{"query":{"query_string":{"query":"richard","default_operator":"OR"}},"from":0,"size":10}
851+
~~SearchURLGenerator:Feature->Elasticsearch:Technology~~
833852
"""
834853

854+
# Examples of queries
855+
# {"query":{"filtered":{"filter":{"bool":{"must":[{"term":{"_type":"article"}}]}},"query":{"query_string":{"query":"richard","default_operator":"OR"}}}},"from":0,"size":10}
856+
# {"query":{"query_string":{"query":"richard","default_operator":"OR"}},"from":0,"size":10}
857+
835858
@staticmethod
836859
def make_term_filter(term, value):
837860
return {"term": {term: value}}

portality/datasets.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
"""
2+
~~DataSets:Data~~
3+
"""
4+
15
import pycountry
26
from collections import OrderedDict
37

48

59
def _generate_country_options():
6-
"""Gather the countries with 2-character codes"""
10+
"""
11+
~~->Countries:Data~~
12+
~~!Countries:Data->PyCountry:Technology~~
13+
Gather the countries with 2-character codes
14+
"""
715
country_options_ = [('', '')]
816

917
for co in sorted(pycountry.countries, key=lambda x: x.name):
@@ -15,6 +23,11 @@ def _generate_country_options():
1523

1624

1725
def _generate_currency_options():
26+
"""
27+
~~->Currencies:Data~~
28+
~~!Currencies:Data->PyCountry:Technology~~
29+
:return:
30+
"""
1831
currency_options_ = [(CURRENCY_DEFAULT, CURRENCY_DEFAULT)]
1932

2033
for cu in sorted(pycountry.currencies, key=lambda x: x.name):
@@ -27,7 +40,11 @@ def _generate_currency_options():
2740

2841

2942
def _generate_language_options():
30-
""" Gather the languages with 2-character codes (ISO 639-2b) """
43+
"""
44+
~~->Languages:Data~~
45+
~~!Languages:Data->PyCountry:Technology~~
46+
Gather the languages with 2-character codes (ISO 639-2b)
47+
"""
3148
language_options_ = [('', '')]
3249
for l in sorted(pycountry.languages, key=lambda x: x.name):
3350
try:
@@ -39,7 +56,10 @@ def _generate_language_options():
3956

4057

4158
def _generate_license_options():
42-
""" Licenses and their rights """
59+
"""
60+
~~->Licences:Data~~
61+
Licenses and their rights
62+
"""
4363
licenses_ = {
4464
# The titles and types are made to match the current values of journals in the DOAJ.
4565
# DOAJ currently assumes type and title are the same.

0 commit comments

Comments
 (0)