app/soc/logic/models/survey.py
changeset 2442 dd1f94c3594c
parent 2439 7fac0da44bbf
child 2443 2e86dbd47907
equal deleted inserted replaced
2441:a24b2b4af87d 2442:dd1f94c3594c
    33 from soc.logic.models.user import logic as user_logic
    33 from soc.logic.models.user import logic as user_logic
    34 from soc.logic.models import work
    34 from soc.logic.models import work
    35 from soc.models.program import Program
    35 from soc.models.program import Program
    36 from soc.models import student_project
    36 from soc.models import student_project
    37 from soc.models.survey import Survey
    37 from soc.models.survey import Survey
       
    38 from soc.models.survey import ProjectSurvey
       
    39 from soc.models.survey import GradingProjectSurvey
    38 from soc.models.survey import SurveyContent
    40 from soc.models.survey import SurveyContent
    39 from soc.models.survey_record import SurveyRecord
    41 from soc.models.survey_record import SurveyRecord
    40 from soc.models.survey_record_group import SurveyRecordGroup
    42 from soc.models.survey_record_group import SurveyRecordGroup
    41 from soc.models.work import Work
    43 from soc.models.work import Work
    42 
    44 
   197         logging.warning('Unable to determine student for \
   199         logging.warning('Unable to determine student for \
   198         user %s. Results returned: %s ' % (
   200         user %s. Results returned: %s ' % (
   199         user.key().name(), str(students)) )
   201         user.key().name(), str(students)) )
   200         return False
   202         return False
   201 
   203 
   202       this_student = students[0]
       
   203 
       
   204   def getStudentforProject(self, user, project):
   204   def getStudentforProject(self, user, project):
   205     """Get student projects for a given User.
   205     """Get student projects for a given User.
   206 
   206 
   207     params:
   207     params:
   208       user = survey taking user
   208       user = survey taking user
   254     if survey.taking_access != "mentor evaluation":
   254     if survey.taking_access != "mentor evaluation":
   255       logging.error("Cannot grade survey %s with taking access %s"
   255       logging.error("Cannot grade survey %s with taking access %s"
   256       % (survey.key().name(), survey.taking_access))
   256       % (survey.key().name(), survey.taking_access))
   257       return False
   257       return False
   258 
   258 
   259     program = survey.scope
   259     program = survey.scope or Program.get_by_key_name(survey.scope_path)
   260 
   260 
   261     for project in program.student_projects.fetch(1000):
   261     for project in program.student_projects.fetch(1000):
   262       this_record_group = SurveyRecordGroup.all().filter(
   262       this_record_group = SurveyRecordGroup.all().filter(
   263       "project = ", project).filter(
   263       "project = ", project).filter(
   264       "initial_status = ", project.status).get()
   264       "initial_status = ", project.status).get()
   287          logging.warning('project %s record group should not \
   287          logging.warning('project %s record group should not \
   288          yet have a final status %s' % (
   288          yet have a final status %s' % (
   289          project.key().name(), this_record_group.final_status ) )
   289          project.key().name(), this_record_group.final_status ) )
   290          continue
   290          continue
   291 
   291 
   292       # assign the new status to the project and s
   292       # assign the new status to the project and surveyrecordgroup
   293       project.status = new_project_status
   293       project.status = new_project_status
   294       this_record_group.final_status = new_project_status
   294       this_record_group.final_status = new_project_status
   295 
   295 
   296   def getKeyNameFromPath(self, path):
   296   def getKeyNameFromPath(self, path):
   297     """Gets survey key name from a request path.
   297     """Gets survey key name from a request path.
   311 
   311 
   312     params:
   312     params:
   313       survey = survey entity
   313       survey = survey entity
   314       user = survey taking user
   314       user = survey taking user
   315     """
   315     """
   316     this_program = survey.scope
   316 
       
   317     this_program = survey.scope or Program.get_by_key_name(survey.scope_path)
       
   318 
   317 
   319 
   318     if 'mentor' in survey.taking_access:
   320     if 'mentor' in survey.taking_access:
   319       these_projects = self.getMentorProjects(user, this_program)
   321       these_projects = self.getMentorProjects(user, this_program)
   320 
   322 
   321     if 'student' in survey.taking_access:
   323     elif 'student' in survey.taking_access:
   322       these_projects = self.getStudentProjects(user, this_program)
   324       these_projects = self.getStudentProjects(user, this_program)
   323 
   325 
   324     logging.info(these_projects)
   326     logging.info(these_projects)
   325 
   327 
   326     if len(these_projects) == 0:
   328     if len(these_projects) == 0:
   401     entity.put()
   403     entity.put()
   402 
   404 
   403     # return the scope
   405     # return the scope
   404     return entity.scope
   406     return entity.scope
   405 
   407 
       
   408 
   406 logic = Logic()
   409 logic = Logic()
       
   410 # TODO separate project and grading logic into own class to overwrite methods
       
   411 project_logic = Logic(model=ProjectSurvey)
       
   412 grading_logic = Logic(model=GradingProjectSurvey)