Add gettext feature (/gettext/<aoid>)

This commit is contained in:
jar3b
2016-03-21 13:08:49 +03:00
parent aa604cc7b7
commit 2b71f7680e
3 changed files with 35 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ class FiasFactory:
self.searcher = SphinxSearch(self.db)
self.expand_templ = template('aore/templates/postgre/expand_query.sql', aoid="//aoid")
self.normalize_templ = template('aore/templates/postgre/normalize_query.sql', aoid="//aoid")
self.gettext_templ = template('aore/templates/postgre/gettext_query.sql', aoid="//aoid")
# Проверка, что строка является действительым UUID v4
@staticmethod
@@ -97,3 +98,20 @@ class FiasFactory:
return dict(error=err.args[0])
return rows
# Возвращает простую текстовую строку по указанному AOID (при AOGUID будет
# ошибка, так что нужно предварительно нормализовать), ищет и в
def gettext(self, aoid):
try:
self.__check_param(aoid, "uuid")
sql_query = self.gettext_templ.replace("//aoid", aoid)
rows = self.db.get_rows(sql_query, True)
assert len(rows), "Record with this AOID not found in DB"
except Exception, err:
if BasicConfig.logging:
logging.error(traceback.format_exc(err))
return dict(error=err.args[0])
return rows