blob: 4fe582ad92d4bb813fc7ceff9208c64517ee3dc3 [file] [log] [blame]
# Copyright 2010 the Melange authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utils for manipulating the survey."""
from soc.models import org_app_record
from soc.modules.gsoc.models import grading_project_survey
from soc.modules.gsoc.models import grading_project_survey_record
from soc.modules.gsoc.models import grading_record
from soc.modules.gsoc.models import grading_survey_group
from soc.modules.gsoc.models import project_survey
from soc.modules.gsoc.models import project_survey_record
from soc.modules.seeder.logic.providers import string as string_provider
from soc.modules.seeder.logic.seeder import logic as seeder_logic
from tests import profile_utils
from tests import timeline_utils
class SurveyHelper(object):
"""Helper class to aid in setting the survey.
def __init__(self, program, dev_test, org_app=None):
self.program = program
self.dev_test = dev_test
self.org_app = org_app
def seed(self, model, properties):
return seeder_logic.seed(model, properties, recurse=False)
def evalSchemaString(self):
return (
def createEvaluation(self, survey, host=None, override=None):
if not host:
host = profile_utils.seedNDBUser(host_for=[self.program])
# TODO (Madhu): Remove scope and author once the survey data conversion
# is complete
properties = {
'program': self.program,
'created_by': host.key.to_old_key(),
'prefix': 'gsoc_program',
'schema': self.evalSchemaString(),
'survey_content': None,
'author': host.key.to_old_key(),
'modified_by': host.key.to_old_key(),
'scope': self.program,
'key_name': string_provider.SurveyKeyNameProvider(),
'survey_start': timeline_utils.past(),
'survey_end': timeline_utils.future(),
properties.update(override or {})
return self.seed(survey, properties)
def createStudentEvaluation(self, host=None, override=None):
return self.createEvaluation(project_survey.ProjectSurvey, host=host,
override=override or {})
def createMentorEvaluation(self, host=None, override=None):
return self.createEvaluation(grading_project_survey.GradingProjectSurvey,
host=host, override=override or {})
def createGradingSurveyGroup(self, mentor_eval=None, student_eval=None):
"""Creates a new evaluation group for a specific evaluation.
Evaluation group is a pair pointing to a student evaluation and a mentor
mentor_eval: Mentor evaluation survey entity that defines the
mentor evaluation component.
student_eal: Student evaluation survey entity that defines the
student evaluation component.
properties = {
'program': self.program,
'grading_survey': mentor_eval or self.createMentorEvaluation(),
'student_survey': student_eval or self.createStudentEvaluation(),
return self.seed(grading_survey_group.GSoCGradingSurveyGroup, properties)
def createOrgAppRecord(
self, link_id, main_admin_key, backup_admin_key, override=None):
"""Creates a new OrgAppRecord for the specified link_id.
link_id: Link ID of the organization to which the application record
should be created.
main_admin: User entity of the main admin of the organization.
backup_admin: User entity of the backup admin of the organization.
override: A dictionary of override parameters for the seeder.
properties = {
'org_id': link_id,
'survey': self.org_app,
'backup_admin': backup_admin_key.to_old_key(),
'user': main_admin_key.to_old_key(),
'main_admin': main_admin_key.to_old_key(),
'status': 'accepted',
'program': self.program,
properties.update(override or {})
entity = self.seed(org_app_record.OrgAppRecord, properties)
return entity
def createStudentEvaluationRecord(self, student_eval, org, student, project):
"""Creates a new Student Evaluation record.
student_eval: Student evaluation survey entity that defines the
org: NDB Organization entity to which this student's project belongs to.
student: NDB Profile entity of the student to whom this evaluation
record belongs to.
project: NDB Project entity to which this evaluation record belongs to.
A student evaluation record.
properties = {
'survey': student_eval,
'user': student.key.parent().to_old_key(),
'org': org.key.to_old_key(),
'project': project.key.to_old_key()
return self.seed(project_survey_record.GSoCProjectSurveyRecord, properties)
def createMentorEvaluationRecord(self, mentor_eval, org, mentor,
project, grade):
"""Creates a new Mentor Evaluation record.
mentor_eval: Mentor evaluation survey entity that defines the
org: NDB Organization entity to which this project belongs to.
mentor: NDB Profile entity of the mentor who submitted this evaluation.
project: NDB Project entity to which this evaluation record belongs to.
grade: True for pass, False otherwise.
A mentor evaluation record.
properties = {
'survey': mentor_eval,
'user': mentor.key.parent().to_old_key(),
'org': org.key.to_old_key(),
'project': project.key.to_old_key(),
'grade': grade
return self.seed(
def createGradingRecord(self, grading_survey_group_ent, mentor_record,
student_record, project, grade_decision):
"""Creates an evaluation record containing the final result/grade.
grading_survey_group_ent: GSoCGradingSurveyGroup entity that points to
the student and mentor evaluation pair.
mentor_record: Mentor evaluation record component for a project.
student_record: Student evaluation record component for a project.
project: Project entity for which this grading record belongs to.
grade_decision: Evaluation grade - pass/fail/undecided.
properties = {
'parent': project.key.to_old_key(),
'grading_survey_group': grading_survey_group_ent,
'mentor_record': mentor_record,
'student_record': student_record,
'grade_decision': grade_decision
return self.seed(grading_record.GSoCGradingRecord, properties)