Improve/harmonise error handling for missing template (even though missing template should never occur).

svn: r23195
This commit is contained in:
Tim G L Lyons 2013-09-25 13:59:54 +00:00
parent 89909f87cd
commit 7fb1ad876a

View File

@ -87,11 +87,13 @@ def reference_L(db, source=None):
Return the list reference (bibliography entry) based on the passed source Return the list reference (bibliography entry) based on the passed source
If source is None, the same input_dict as before is used. If source is None, the same input_dict as before is used.
""" """
global refL global refL, template_cache
if source: if source:
set_input_dict_and_template(db, source) set_input_dict_and_template(db, source)
if refL is not None: if refL is not None:
return refL return refL
if template_cache is None:
return ""
refL = _reference(db, REF_TYPE_L) refL = _reference(db, REF_TYPE_L)
return refL return refL
@ -100,11 +102,13 @@ def reference_S(db, source=None, citation=None):
Return the short reference based on the passed source and/or citation Return the short reference based on the passed source and/or citation
If both source and citation are None, the same list as before is used. If both source and citation are None, the same list as before is used.
""" """
global refS global refS, template_cache
if source or citation: if source or citation:
set_input_dict_and_template(db, source, citation) set_input_dict_and_template(db, source, citation)
if refS is not None: if refS is not None:
return refS return refS
if template_cache is None:
return ""
refS = _reference(db, REF_TYPE_S) refS = _reference(db, REF_TYPE_S)
return refS return refS
@ -113,11 +117,13 @@ def reference_F(db, source=None, citation=None):
Return the full reference based on the passed source and/or citation Return the full reference based on the passed source and/or citation
If both source and citation are None, the same list as before is used. If both source and citation are None, the same list as before is used.
""" """
global refF global refF, template_cache
if source or citation: if source or citation:
set_input_dict_and_template(db, source, citation) set_input_dict_and_template(db, source, citation)
if refF is not None: if refF is not None:
return refF return refF
if template_cache is None:
return ""
refF = _reference(db, REF_TYPE_F) refF = _reference(db, REF_TYPE_F)
return refF return refF
@ -205,6 +211,7 @@ def set_input_dict_and_template(db, source=None, citation=None):
source_cache = db.get_source_from_handle(source_handle) source_cache = db.get_source_from_handle(source_handle)
template_handle = source_cache.get_template() template_handle = source_cache.get_template()
if template_handle is None: if template_handle is None:
template_cache = None
return return
template_cache = db.get_template_from_handle(template_handle) template_cache = db.get_template_from_handle(template_handle)
attr_list = source_cache.get_attribute_list() + citation.get_attribute_list() attr_list = source_cache.get_attribute_list() + citation.get_attribute_list()
@ -221,6 +228,7 @@ def set_input_dict_and_template(db, source=None, citation=None):
# raise Exception('Citation must be a Citation of the Source being cited') # raise Exception('Citation must be a Citation of the Source being cited')
template_handle = source_cache.get_template() template_handle = source_cache.get_template()
if template_handle is None: if template_handle is None:
template_cache = None
return return
template_cache = db.get_template_from_handle(template_handle) template_cache = db.get_template_from_handle(template_handle)
attr_list = source_cache.get_attribute_list() + citation.get_attribute_list() attr_list = source_cache.get_attribute_list() + citation.get_attribute_list()
@ -230,6 +238,7 @@ def set_input_dict_and_template(db, source=None, citation=None):
source_cache = source source_cache = source
template_handle = source_cache.get_template() template_handle = source_cache.get_template()
if template_handle is None: if template_handle is None:
template_cache = None
return return
template_cache = db.get_template_from_handle(template_handle) template_cache = db.get_template_from_handle(template_handle)
attr_list = source_cache.get_attribute_list() attr_list = source_cache.get_attribute_list()