def setSurveyRecordGroup(self, survey, survey_record, project): """First looks for an existing SurveyRecordGroup, using the project and its current status as a filter. IOW SurveyRecordGroup cannot consist of surveys taken with two different statuses. This means that a student cannot take a survey after the mentor has taken the accompanying survey and the project has since changed. (Assuming we want this strict behavior) params: survey = survey entity survey_record = saved response to survey project = student project for survey taker """ group_query = SurveyRecordGroup.all( ).filter("project = ", project ).filter("initial_status = ", project.status ) if survey.taking_access == 'mentor evaluation': survey_record_group = group_query.filter( "mentor = ", None ).get() elif survey.taking_access == 'student evaluation': survey_record_group = group_query.filter( "student = ", None ).get() if not survey_record_group: #create Survey Record Group if it doesn't already exist survey_record_group = SurveyRecordGroup( project=project, initial_status = project.status ) if survey.taking_access == 'mentor evaluation': survey_record_group.mentor_record = survey_record elif survey.taking_access == 'student evaluation': survey_record_group.student_record = survey_record return survey_record_group