Add function to retrieve survey configurations from DB.

As the survey definitions will no longer be stored in files
under etc/surveys/ but directly on the database, this
function replaces configuration.surveys()
This commit is contained in:
D. Berge
2023-08-30 14:19:56 +02:00
parent 25ab623328
commit c99a625b60
8 changed files with 45 additions and 35 deletions

View File

@@ -589,6 +589,36 @@ class Datastore:
# we assume that we are in the middle of a transaction
def surveys (self, include_archived = False):
"""
Return list of survey definitions.
"""
if self.conn is None:
self.connect()
if include_archived:
qry = """
SELECT meta
FROM public.projects;
"""
else:
qry = """
SELECT meta
FROM public.projects
WHERE NOT (meta->'archived')::boolean IS true
"""
with self.conn:
with self.conn.cursor() as cursor:
cursor.execute(qry)
results = cursor.fetchall()
return [r[0] for r in results if r[0]]
# TODO Does this need tweaking on account of #246?
def apply_survey_configuration(self, cursor = None):
if cursor is None:
cur = self.conn.cursor()