Beispiel #1
0
 def operation_report_result_set(self, req, args):
     """
     Run a report, generating a result set.
     """
     dbconn = self._connect_db()
     table_name = args['report']
     del args['report']
     server_modified = DBQueries.get_table_lastupdate(dbconn, table_name)
     headers = [(
         'Last-Modified',
         format_date_time(mktime(server_modified.timetuple()))
     )]
     # Handle conditional requests
     if not args:
         if (
             req.if_modified_since and
             req.if_modified_since >= server_modified
         ):
             return (webob.exc.HTTPNotModified(), headers)
     try:
         result_set = DBQueries.filter_table(dbconn, table_name, args)
         # Pylint warns about catch-all exception handlers like that below.
         # The rationale is that this "prohibits the use of tailored
         # responses" - but that is exactly what we are attempting to do.
         # So just disable the warning.
         # pylint: disable=W0702
     except:
         # Don't leak information about the database
         return (webob.exc.HTTPBadRequest(), [])
     return (result_set, headers)
Beispiel #2
0
 def _get_report_details(self, dbconn, report_name):
     """
     Return details about the given-named report.
     """
     return dict(
         name=report_name,
         description=DBQueries.get_table_comment(
             dbconn, self.dbname, report_name
         ),
         lastUpdated=DBQueries.get_table_lastupdate(
             dbconn, report_name
         ),
         links=self._get_report_links(report_name)
     )
Beispiel #3
0
 def operation_reports_list(self, req, args):
     """
     List available reports.
     """
     dbconn = self._connect_db()
     report_name_iter = DBQueries.get_table_list(dbconn)
     # The current resultset must be entirely read before another query
     # can be performed on the same connection.
     # This means we must either finish reading all report names before
     # reading all report details, or must use multiple connections.
     report_names = [report_name for report_name in report_name_iter]
     return ([
         self._get_report_details(dbconn, report_name)
         for report_name in report_names
     ], None)