def handleDiff(self): qid = self.getQuestionnaireId() dbHelper = dbUtils() answers = dbHelper.diffWithLatest(qid) return '{\"csrf\":\"' + self.csrf_token + \ '\",\"qid\":\"' + session['qid'] + \ '\",\"answers\":' + answers + '}'
def fetchMetadataFromDB(self, searchType, qid): """Fetches the questionnaire answer metadata from the database""" contents = '' app = current_app dbHelper = dbUtils() if qid is None or qid == "": status = self._getStatusDict(searchType).get( "status", ('Submitted', '', '', '', '')) rows = dbHelper.fetchForSubmissionsStatus(status) else: rows = dbHelper.loadPreviousRevisions(qid) if len(rows) != 0: contents = json.dumps(rows) return contents return '{}'
def handleStatus(self): if session.get('_auth') == True: newStatus = request.form['s'] qid = request.form['id'] dbHelper = dbUtils() errCode = dbHelper.updateStatus(qid, newStatus, session.get('_user')) if errCode != 0: abort(500) else: self.updateSharedSession( qid, " ", "" if session.get('_app_name') is None else session.get('_app_name')) if newStatus == "a": logging.critical(self.app.config['MAIL_BODY_APPROVED']) else: logging.critical(self.app.config['MAIL_BODY_IN_REVIEW']) return '{\"csrf\":\"' + self.csrf_token + '\"}' else: abort(401)
def fetchAnswersFromDB(self): """Fetches the questionnaire answers from the database""" contents = '' app = current_app searchQid = request.form[ 'id'] if request.method == 'POST' else request.args.get('id') searchTerms = searchQid.split("-") if len(searchTerms) > 2: abort(400) else: dbHelper = dbUtils() if len(searchTerms) == 2: if (searchTerms[0]).isalnum(): auditId = -1 try: auditId = int(searchTerms[1]) except Exception as e: abort(400) finally: rows = dbHelper.searchInRevisionHistory( searchTerms[0], auditId) if len(rows) != 0: rows[0]['app_status'] = "Revision" else: abort(400) else: rows = dbHelper.wildCardSearch(searchQid) if len(rows) != 0: logging.debug( "PostHandler.fetchAnswersFromDB:Found %d rows matching the QID:%s", len(rows), searchQid) savedResponse = json.loads(rows[0]['app_answer']) updatedValues = self.updateValues(savedResponse) updatedValues['app_status'] = rows[0]['app_status'] session['_app_name'] = updatedValues['app_name'] contents = json.dumps(updatedValues) return contents logging.debug( "PostHandler.fetchAnswersFromDB:Found no row matching the QID:%s", searchQid) return '{}'
def saveAnswersInDB(self, answersDict): """Saves the questionnaire answers from the request in a database""" dbHelper = dbUtils() errCode = dbHelper.insertOrUpdateAnswers(answersDict) if errCode != 0: abort(500)