コード例 #1
0
ファイル: report.py プロジェクト: wovari/scoremodel
 def read(self, object_id):
     existing_report = BenchmarkReport.query.filter(
         BenchmarkReport.id == object_id).first()
     if not existing_report:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             BenchmarkReport, object_id))
     return existing_report
コード例 #2
0
 def read(self, type_id):
     existing_type = OrganisationType.query.filter(
         OrganisationType.id == type_id).first()
     if not existing_type:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             OrganisationType, type_id))
     return existing_type
コード例 #3
0
ファイル: document.py プロジェクト: wovari/scoremodel
 def read(self, item_id):
     existing_document = Document.query.filter(
         Document.id == item_id).first()
     if not existing_document:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             Document, item_id))
     return existing_document
コード例 #4
0
 def get_risk_factor(self, risk_factor_name):
     risk_factor = RiskFactor.query.filter(
         RiskFactor.risk_factor == risk_factor_name).first()
     if risk_factor is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             RiskFactor, risk_factor_name))
     return risk_factor
コード例 #5
0
    def query_user_report_question(self, input_data):
        """
        Return a question answer (which should be unique for this combination) for a specific question in
        a specific user_report.
        :param input_data:
        :return:
        """
        cleaned_data = {}
        for key in self.possible_params:
            if key in self.required_params and key != 'answer_id':
                if key not in input_data:
                    raise RequiredAttributeMissing(
                        _e['attr_missing'].format(key))
                cleaned_data[key] = input_data[key]
            else:
                if key not in input_data:
                    cleaned_data[key] = None
                else:
                    cleaned_data[key] = input_data[key]

        existing_question_answer = QuestionAnswer.query.filter(
            and_(
                QuestionAnswer.user_report_id ==
                cleaned_data['user_report_id'],
                QuestionAnswer.user_id == cleaned_data['user_id'],
                QuestionAnswer.question_id ==
                cleaned_data['question_id'])).first()
        if existing_question_answer is None:
            raise DatabaseItemDoesNotExist(
                _('No QuestionAnswer with user_report_id %(user_report_id)s user_id %(user_id)s and question_id %(question_id)s',
                  user_report_id=cleaned_data['user_report_id'],
                  user_id=cleaned_data['user_id'],
                  question_id=cleaned_data['question_id']))
        return existing_question_answer
コード例 #6
0
 def read(self, question_answer_id):
     existing_question_answer = QuestionAnswer.query.filter(
         QuestionAnswer.id == question_answer_id).first()
     if existing_question_answer is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             'QuestionAnswer', question_answer_id))
     return existing_question_answer
コード例 #7
0
ファイル: user.py プロジェクト: wovari/scoremodel
 def by_session_token(self, session_token):
     existing_user = User.query.filter(
         User.session_token == session_token).first()
     if not existing_user:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             User, session_token))
     return existing_user
コード例 #8
0
 def by_menu_link(self, menu_link):
     existing_menu_link = MenuLink.query.filter(
         MenuLink.menu_link == menu_link).first()
     if not existing_menu_link:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             MenuLink, menu_link))
     return existing_menu_link
コード例 #9
0
 def get_section(self, section_title, report_id):
     existing_section = Section.query.filter(
         and_(Section.title == section_title,
              Section.report_id == report_id)).first()
     if existing_section is None:
         raise DatabaseItemDoesNotExist(_e['item_not_in'].format(
             Section, section_title, Report, report_id))
     return existing_section
コード例 #10
0
 def get_question(self, question_name, section_id):
     existing_question = Question.query.filter(
         and_(Question.question == question_name,
              Question.section_id == section_id)).first()
     if existing_question is None:
         raise DatabaseItemDoesNotExist(_e['item_not_in'].format(
             Question, question_name, Section, section_id))
     return existing_question
コード例 #11
0
 def read(self, report_id):
     """
     Get a report by its id. See QuestionApi.read()
     :param report_id:
     :return:
     """
     existing_report = Report.query.filter(Report.id == report_id).first()
     if existing_report is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             Report, report_id))
     return existing_report
コード例 #12
0
ファイル: role.py プロジェクト: wovari/scoremodel
 def read(self, role_id):
     """
     Get a role by its id
     :param role_id:
     :return:
     """
     existing_role = Role.query.filter(Role.id == role_id).first()
     if existing_role is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             Role, role_id))
     return existing_role
コード例 #13
0
ファイル: user.py プロジェクト: wovari/scoremodel
 def read(self, user_id):
     """
     Return a user by its id.
     :param user_id:
     :return:
     """
     existing_user = User.query.filter(User.id == user_id).first()
     if existing_user is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             User, user_id))
     return existing_user
コード例 #14
0
 def read(self, answer_id):
     """
     Return an answer by its id. See QuestionApi.read()
     :param answer_id:
     :return:
     """
     existing_answer = Answer.query.filter(Answer.id == answer_id).first()
     if existing_answer is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             Answer, answer_id))
     return existing_answer
コード例 #15
0
ファイル: user.py プロジェクト: wovari/scoremodel
 def get_by_user(self, user_name):
     """
     Get a user by its user_name
     :param user_name:
     :return:
     """
     existing_user = User.query.filter(User.username == user_name).first()
     if existing_user is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             User, user_name))
     return existing_user
コード例 #16
0
 def by_menu_link_and_lang(self, menu_link, lang):
     # Language
     existing_lang = self.lang_api.by_lang(lang)
     # Menu link
     existing_menu_link = self.menu_link_api.by_menu_link(menu_link)
     existing_page = Page.query.filter(and_(Page.menu_link_id == existing_menu_link.id,
                                            Page.lang_id == existing_lang.id)).first()
     if not existing_page:
         raise DatabaseItemDoesNotExist(_('A page for menu_link {0} in language {1} does not exist.')
                                        .format(menu_link, lang))
     return existing_page
コード例 #17
0
ファイル: benchmark.py プロジェクト: wovari/scoremodel
 def query(self, input_data):
     cleaned_data = self.parse_input_data(input_data)
     existing_benchmark = Benchmark.query.filter(and_(
         Benchmark.benchmark_report_id == cleaned_data['benchmark_report_id'],
         Benchmark.question_id == cleaned_data['question_id']
     )).first()
     if not existing_benchmark:
         raise DatabaseItemDoesNotExist(_('No benchmark with benchmark_report_id {0} and question_id {1}.').format(
             cleaned_data['benchmark_report_id'],
             cleaned_data['question_id']
         ))
     return existing_benchmark
コード例 #18
0
ファイル: risk_factor.py プロジェクト: wovari/scoremodel
 def read(self, risk_factor_id):
     """
     Return a RiskFactor by its id. See QuestionApi.read()
     :param risk_factor_id:
     :return:
     """
     existing_risk_factor = RiskFactor.query.filter(
         RiskFactor.id == risk_factor_id).first()
     if existing_risk_factor is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             RiskFactor, risk_factor_id))
     return existing_risk_factor
コード例 #19
0
ファイル: question.py プロジェクト: wovari/scoremodel
 def read(self, question_id):
     """
     Get a question from the database by its ID
     :param question_id:
     :return:
     """
     existing_question = Question.query.filter(
         Question.id == question_id).first()
     if existing_question is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             Question, question_id))
     return existing_question
コード例 #20
0
ファイル: question.py プロジェクト: wovari/scoremodel
 def query(self, question_question):
     """
     Select a question by its name ("question"): this attribute is unique
     :param question_question:
     :return:
     """
     existing_question = Question.query.filter(
         Question.question == question_question).first()
     if not existing_question:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             Question, question_question))
     return existing_question
コード例 #21
0
 def read(self, section_id):
     """
     Return a section based on its id. See QuestionApi.read()
     :param section_id:
     :param section_data:
     :return:
     """
     existing_section = Section.query.filter(
         Section.id == section_id).first()
     if existing_section is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             Section, section_id))
     return existing_section
コード例 #22
0
 def get_answer_by_question_id(self, question_id, user_id, user_report_id):
     """
     Get the answer to a question by its question_id in a specific report.
     :param question_id:
     :param user_id:
     :param user_report_id:
     :return:
     """
     question_answer = QuestionAnswer.query.filter(
         and_(QuestionAnswer.question_id == question_id,
              QuestionAnswer.user_id == user_id,
              QuestionAnswer.user_report_id == user_report_id)).first()
     if question_answer is None:
         raise DatabaseItemDoesNotExist(
             _('No answer found for question %(question_id)s in report %(report_id)s',
               question_id=question_id,
               report_id=user_report_id))
     return question_answer
コード例 #23
0
 def query(self, input_data):
     """
     Query for a QuestionAnswer where question_id, answer_id, user_id and user_report_id equal the input.
     Return QuestionAnswer or throw DatabaseItemDoesNotExist
     :param input_data:
     :return:
     """
     cleaned_data = self.parse_input_data(input_data)
     existing_question_answer = QuestionAnswer.query.filter(
         and_(
             QuestionAnswer.user_report_id ==
             cleaned_data['user_report_id'],
             QuestionAnswer.user_id == cleaned_data['user_id'],
             QuestionAnswer.question_id == cleaned_data['question_id'],
             QuestionAnswer.answer_id ==
             cleaned_data['answer_id'])).first()
     if existing_question_answer is None:
         raise DatabaseItemDoesNotExist(
             _('No QuestionAnswer with user_report_id %(user_report_id)s user_id %(user_id)s question_id %(question_id)s and answer_id %(answer_id)s',
               user_report_id=cleaned_data['user_report_id'],
               user_id=cleaned_data['user_id'],
               question_id=cleaned_data['question_id'],
               answer_id=cleaned_data['answer_id']))
     return existing_question_answer
コード例 #24
0
ファイル: role.py プロジェクト: wovari/scoremodel
 def get_by_role(self, input_role):
     existing_role = Role.query.filter(Role.role == input_role).first()
     if existing_role is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             Role, input_role))
     return existing_role
コード例 #25
0
 def get_answer(self, answer_name):
     answer = Answer.query.filter(Answer.answer == answer_name).first()
     if answer is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             Answer, answer_name))
     return answer
コード例 #26
0
ファイル: user.py プロジェクト: wovari/scoremodel
 def by_api_key(self, api_key):
     existing_user = User.query.filter(User.api_key == api_key).first()
     if not existing_user:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             User, api_key))
     return existing_user
コード例 #27
0
ファイル: user_report.py プロジェクト: wovari/scoremodel
 def read(self, report_id):
     existing_user_report = UserReport.query.filter(UserReport.id == report_id).first()
     if existing_user_report is None:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(UserReport, report_id))
     return existing_user_report
コード例 #28
0
ファイル: lang.py プロジェクト: wovari/scoremodel
 def by_lang(self, lang):
     existing_lang = Lang.query.filter(Lang.lang == lang).first()
     if not existing_lang:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(
             Lang, lang))
     return existing_lang
コード例 #29
0
ファイル: organisation.py プロジェクト: wovari/scoremodel
 def read(self, organisation_id):
     existing_organisation = Organisation.query.filter(Organisation.id == organisation_id).first()
     if not existing_organisation:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(Organisation, organisation_id))
     return existing_organisation
コード例 #30
0
 def read(self, page_id):
     existing_page = Page.query.filter(Page.id == page_id).first()
     if not existing_page:
         raise DatabaseItemDoesNotExist(_e['item_not_exists'].format(Page, page_id))
     return existing_page